Commit 29acd465 authored by YANO Takashi's avatar YANO Takashi

ZP-1202 Part of subject or from may be in junk string. Released under the...

ZP-1202 Part of subject or from may be in junk string. Released under the Affero GNU General Public License (AGPL) version 3.
parent 9e4f0a3e
...@@ -1030,8 +1030,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider { ...@@ -1030,8 +1030,7 @@ class BackendIMAP extends BackendDiff implements ISearchProvider {
$mobj = new Mail_mimeDecode($mail); $mobj = new Mail_mimeDecode($mail);
$message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8')); $message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8'));
Utils::CheckAndFixEncoding($message->headers["subject"]); Utils::CheckAndFixEncodingInHeaders($mail, $message);
Utils::CheckAndFixEncoding($message->headers["from"]);
$is_multipart = is_multipart($message); $is_multipart = is_multipart($message);
$is_smime = is_smime($message); $is_smime = is_smime($message);
......
...@@ -335,8 +335,7 @@ class BackendMaildir extends BackendDiff { ...@@ -335,8 +335,7 @@ class BackendMaildir extends BackendDiff {
$message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8')); $message = Mail_mimeDecode::decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'input' => $rfc822, 'crlf' => "\n", 'charset' => 'utf-8'));
Utils::CheckAndFixEncoding($message->headers["subject"]); Utils::CheckAndFixEncodingInHeaders($mail, $message);
Utils::CheckAndFixEncoding($message->headers["from"]);
$output = new SyncMail(); $output = new SyncMail();
......
...@@ -1176,6 +1176,55 @@ class Utils { ...@@ -1176,6 +1176,55 @@ class Utils {
return isset($folder->displayname) && substr($folder->displayname, -3) == hex2bin("e2808b"); return isset($folder->displayname) && substr($folder->displayname, -3) == hex2bin("e2808b");
} }
/**
* if string is ISO-2022-JP, convert this into utf-8
*
* @access public
* @param $nonencstr, $utf8str
* @return string
*/
public static function ConvertRawHeader2Utf8($nonencstr, $utf8str) {
if ( !isset($nonencstr) ) {
return $utf8str;
}
$isiso2022jp = false;
$str = "";
foreach ( imap_mime_header_decode($nonencstr) as $val ) {
if ( strtolower($val->charset) == "iso-2022-jp" ) {
$isiso2022jp = true;
$str .= mb_convert_encoding($val->text, "utf-8", "ISO-2022-JP-MS");
} else if ( strtolower($val->charset) == "default" ) {
$str .= $val->text;
} else {
$str .= mb_convert_encoding($val->text, "utf-8", $val->charset);
}
}
if ( !$isiso2022jp ) {
return $utf8str;
}
return $str;
}
/**
* get raw mail headers as key-value pair array
*
* @access public
* @param $mail
* @return string array
*/
public static function GetRawMailHeaders($mail) {
$mobj = new Mail_mimeDecode($mail);
$headersonly = $mobj->_parseHeaders($mail);
$headers = array();
foreach ( $headersonly as $value ) {
if ( $value["name"] === false ) {
continue;
}
$headers[strtolower($value["name"])] = $value["value"];
}
return $headers;
}
/** /**
* Check if the UTF-8 string has ISO-2022-JP esc seq * Check if the UTF-8 string has ISO-2022-JP esc seq
* if so, it is ISO-2022-JP, not UTF-8 and convert it into UTF-8 * if so, it is ISO-2022-JP, not UTF-8 and convert it into UTF-8
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment