/** * Decode a string from UTF8 to current Storage Charset * @static * @param string $filesystemElement * @param bool $test Try to detect if it's really utf8 or not * @return string */ public static function toStorageEncoding($filesystemElement, $test = false) { if ($test && !SystemTextEncoding::isUtf8($filesystemElement)) { return $filesystemElement; } $enc = SystemTextEncoding::getEncoding(); return SystemTextEncoding::changeCharset("UTF-8", $enc, $filesystemElement); }
public function mimeExtractorCallback($masterFile, $targetFile) { $metadata = array(); require_once "Mail/mimeDecode.php"; $params = array('include_bodies' => true, 'decode_bodies' => false, 'decode_headers' => 'UTF-8'); $mess = ConfService::getMessages(); $content = file_get_contents($masterFile); $decoder = new Mail_mimeDecode($content); $structure = $decoder->decode($params); $allowedHeaders = array("to", "from", "subject", "message-id", "mime-version", "date", "return-path"); foreach ($structure->headers as $hKey => $hValue) { if (!in_array($hKey, $allowedHeaders)) { continue; } if (is_array($hValue)) { $hValue = implode(", ", $hValue); } if ($hKey == "date") { $date = strtotime($hValue); $metadata["eml_time"] = $date; } $metadata["eml_" . $hKey] = AJXP_Utils::xmlEntities(@htmlentities($hValue, ENT_COMPAT, "UTF-8")); //$this->logDebug($hKey." - ".$hValue. " - ".$metadata["eml_".$hKey]); if ($metadata["eml_" . $hKey] == "") { $metadata["eml_" . $hKey] = AJXP_Utils::xmlEntities(@htmlentities($hValue)); if (!SystemTextEncoding::isUtf8($metadata["eml_" . $hKey])) { $metadata["eml_" . $hKey] = SystemTextEncoding::toUTF8($metadata["eml_" . $hKey]); } } $metadata["eml_" . $hKey] = str_replace("&", "&", $metadata["eml_" . $hKey]); } $metadata["eml_attachments"] = 0; $parts = $structure->parts; if (!empty($parts)) { foreach ($parts as $mimePart) { if (!empty($mimePart->disposition) && $mimePart->disposition == "attachment") { $metadata["eml_attachments"]++; } } } $metadata["icon"] = "eml_images/ICON_SIZE/mail_mime.png"; file_put_contents($targetFile, serialize($metadata)); }
/** * Transform a string from current charset to utf8 * @static * @param string $filesystemElement * @param bool $test Test if it's already UTF8 or not, to avoid double-encoding * @return string */ static function toUTF8($filesystemElement, $test = true) { if ($test && SystemTextEncoding::isUtf8($filesystemElement)) { return $filesystemElement; } $enc = SystemTextEncoding::getEncoding(); return SystemTextEncoding::changeCharset($enc, "UTF-8", $filesystemElement); }