[root@mail squirrelmail-1.4.8]# diff -uwBN functions/mime.php /var/www/squirrelmail/functions/mime.php --- functions/mime.php 2006-06-20 14:14:53.000000000 +0800 +++ /var/www/squirrelmail/functions/mime.php 2014-01-10 09:35:57.104824062 +0800
@@ -288,7 +288,7 @@
$body_ary[$i] = $line;
}
- $body = '<pre>' . implode("\n", $body_ary) . '</pre>';
+ $body = implode("<br>\n", $body_ary);// . '</pre>'; //dywang
}
/**
@@ -465,7 +465,7 @@
}
}
- $display_filename = $filename;
+ $display_filename = utf8convert($filename,''); //dywang
if (isset($passed_ent_id)) {
$passed_ent_id_link = '&passed_ent_id='.$passed_ent_id;
} else {
@@ -495,7 +499,7 @@
$defaultlink = $hookresults[6];
$attachments .= '<tr><td>' .
- '<a href="'.$defaultlink.'">'.decodeHeader($display_filename).'</a> </td>' .
+ '<a href="'.$defaultlink.'">'.decodeHeader($display_filename,false,false,true).'</a> </td>' .//dywang
'<td><small><b>' . show_readable_size($header->size) .
'</b> </small></td>' .
'<td><small>[ '.htmlspecialchars($type0).'/'.htmlspecialchars($type1).' ] </small></td>' .
$utfencode=true 表示郵件為 utf8 編碼,$htmlsave=true 表示保留 html 格式,$decide=false 表示決定不必解碼。如果 Header 出現 =?,而且沒出現 =?,也就是出現編碼開始,但沒有編碼結束,就刪除換行等符號,直到變數 $pre_chunk 包含整個郵件的 header,以利解碼。
-function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) {
+function decodeHeader ($string, $utfencode=true,$htmlsave=true,$decide=false) { //dywang debug this function
global $languages, $squirrelmail_language,$default_charset;
if (is_array($string)) {
$string = implode("\n", $string);
@@ -604,8 +615,10 @@
$iLastMatch = -2;
$encoded = false;
+ static $pre_chunk; //dywang
$aString = explode(' ',$string);
$ret = '';
foreach ($aString as $chunk) {
if ($encoded && $chunk === '') {
continue;
@@ -616,8 +629,14 @@
$encoded = false;
/* if encoded words are not separated by a linear-space-white we still catch them */
$j = $i-1;
-
+ if (preg_match('/^.*=\?[^?]*/',$chunk) && !preg_match('/[^?]*\?=.*$/',$chunk)) { //dywang begin
+ $pre_chunk = preg_replace("/[\n\t\r]/", '',$chunk);
+ $chunk='';
+ } else{// if (!preg_match(preg_match('/^.*=\?/',$pre_chunk) && preg_match('/\?=.*$/',$chunk)) {
+ $chunk = $pre_chunk . $chunk;
+ $pre_chunk = '';
+ } // dywang end
/* if the last chunk isn't an encoded string then put back the space, otherwise don't */
if ($iLastMatch !== $j) {
if ($htmlsave) {
@@ -634,9 +653,12 @@
$ret .= $res[1];
}
$encoding = ucfirst($res[3]);
/* decide about valid decoding */
- if ($decide && is_conversion_safe($res[2])) {
+ if ($decide) {
$can_be_encoded=true;
} else {
$can_be_encoded=false;
@@ -648,10 +670,12 @@
$replace = base64_decode($res[4]);
if ($can_be_encoded) {
// string is converted from one charset to another. sanitizing depends on $htmlsave
- $replace = charset_convert($res[2],$replace,$default_charset,$htmlsave);
+ $replace = utf8convert($replace,$res[2]); //dywang
} elseif ($utfencode) {
// string is converted to htmlentities and sanitized
$replace = charset_decode($res[2],$replace);
@@ -664,7 +688,8 @@
$replace);
if ($can_be_encoded) {
// string is converted from one charset to another. sanitizing depends on $htmlsave
- $replace = charset_convert($res[2], $replace,$default_charset,$htmlsave);
+ $replace = utf8convert($replace,$res[2]); //dywang
} elseif ($utfencode) {
// string is converted to html entities and sanitized
$replace = charset_decode($res[2], $replace);
@@ -723,7 +749,7 @@
}
// Use B encoding for multibyte charsets
- $mb_charsets = array('utf-8','big5','gb2313','euc-kr');
+ $mb_charsets = array('utf-8','gb2313','big-5','euc-cn','cp936');
if (in_array($default_charset,$mb_charsets) &&
in_array($default_charset,sq_mb_list_encodings()) &&
sq_is8bit($string)) {
@@ -735,9 +761,10 @@
// Encode only if the string contains 8-bit characters or =?
$j = strlen($string);
- $max_l = 75 - strlen($default_charset) - 7;
+ $max_l = 120 - strlen($default_charset) - 7; //dywang 75 亂碼 for full_name
$aRet = array();
$ret = '';
$iEncStart = $enc_init = false;
@@ -897,7 +924,7 @@
* remove =? ? ?= (5 chars)
* remove 2 more chars (\r\n ?)
*/
- $iMaxLength = 75 - strlen($charset) - 7;
+ $iMaxLength = 120 - strlen($charset) - 7; //dywang
// set first character position
$iStartCharNum = 0;
@@ -2152,7 +2326,7 @@
// version
//set all the Cache Control Headers for IE
if ($isIE) {
- $filename=rawurlencode($filename);
+ //$filename=rawurlencode($filename); //dywang
header ("Pragma: public");
header ("Cache-Control: no-store, max-age=0, no-cache, must-revalidate"); // HTTP/1.1
header ("Cache-Control: post-check=0, pre-check=0", false);
+/**
+ * This is a function to convert string coding to UTF-8.
+ *
+ * Author De-Yu Wang 2012/04/28 dywang
+ * @param $str the string
+ * @param $default_charset
+ * @return a string encoded by UTF-8
+ */
+function utf8convert($str, $actural) { //dywang optimal, Don't change
+ global $default_charset;
+ if(stristr($actural,'UTF-8')) return $str;//.'!&'.$actural;
+ if(stristr($actural,'gb2312') || stristr($actural,'gb18030'))
+ return mb_convert_encoding($str,$default_charset,'GBK');//.'!#'.$actural;
+ if($actural!="" && !stristr($actural,'gb18030'))
+ return mb_convert_encoding($str,$default_charset,$actural);//.'!+'.$actural;//.$default_charset.$detect;
+ $encoding_list = 'UTF-8,GB2312,BIG-5,CP936, GBK, EUC-CN';
+ $detect = mb_detect_encoding($str,$encoding_list);
+ if(stristr($detect,'UTF'))
+ return $str;//.'!/'. $detect;
+ if(stristr($detect,'GB') || stristr($detect,'!EUC-CN'))
+ return mb_convert_encoding($str,$default_charset,'GB2312');//.'!-'.$detect;
+ if(stristr($detect,'C' ) || stristr($detect,'BIG'))
+ return mb_convert_encoding($str,$default_charset,$detect);//.'!x'.$detect;
+ if($detect == '')
+ return mb_convert_encoding($str,$default_charset,'EUC-CN');//.'!C'.$detect;
+ return $str;//.'!/'. $detect;
+}
+
?>