--- lib/Horde/MIME/Part.php.orig 2007-09-29 23:22:47.000000000 +0800 +++ lib/Horde/MIME/Part.php 2007-10-27 15:03:11.000000000 +0800 @@ -505,6 +505,10 @@ function getCharset() { $charset = $this->getContentTypeParameter('charset'); + /* rafan.050209 dirty hack to big5 */ + if (in_array(strtolower($charset), array("x-unknown", "us-ascii", "ms950", "cp950", "iso-8859-1"))) { + $charset = "BIG5"; + } return (empty($charset)) ? null : $charset; } --- lib/Horde/MIME.php.orig 2007-09-29 23:22:47.000000000 +0800 +++ lib/Horde/MIME.php 2007-11-02 12:51:50.000000000 +0800 @@ -133,6 +133,11 @@ $charset = String::lower($charset); $line = ''; + /* rafan.080106: some parts of Horde code pass UTF-8 to MIME::encode with $charset != utf-8 */ + if (MIME::is_utf8($text) && $charset != "utf-8") { + $charset = "utf-8"; + } + /* Get the list of elements in the string. */ $size = preg_match_all('/([^\s]+)([\s]*)/', $text, $matches, PREG_SET_ORDER); @@ -296,6 +301,21 @@ return $text; } + function is_utf8($string) { + return (is_string($string) && preg_match('/^.*$/us', $string)); + /*// From http://w3.org/International/questions/qa-forms-utf-8.html + return preg_match('%^(?: + [\x09\x0A\x0D\x20-\x7E] # ASCII + | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte + | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte + | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates + | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 + | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 + | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 + )*$%xs', $string);*/ + } // function is_utf8 + /** * Decodes an RFC 2047-encoded string. * @@ -308,6 +328,11 @@ function decode($string, $to_charset = null) { if (($pos = strpos($string, '=?')) === false) { + /* 050219.rafan: XXX subject is in RAW big5, force conversion */ + /* 071027.rafan: force conversion from big5 only if it's not utf-8 */ + if (!MIME::is_utf8($string)) { + $string = String::convertCharset($string, "big5"); + } return $string; } @@ -346,6 +371,12 @@ $to_charset = NLS::getCharset(); } + /* rafan.040717: dirty hack for raw 8bit subject */ + /* rafan.050209: assume raw 8bit is BIG5 */ + if (in_array(strtolower($charset), array("x-unknown", "us-ascii", "ms950", "cp950", "iso-8859-1"))) { + $charset = "BIG5"; + } + switch ($encoding) { case 'Q': case 'q':