歡迎您光臨本站 註冊首頁

請教關於squirrelmail簡體繁體亂碼問題

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

請教關於squirrelmail簡體繁體亂碼問題

兩個用戶假如都是簡體中文環境或者都是繁體中文環境,相互發郵件正常,但一方簡體環境,另一方繁體環境時,收發的郵件都是亂碼,需要改成相應的環境才能正常顯示,有什麼辦法讓系統自動轉換嗎?
《解決方案》

自己將自己的語言設置正確.

不要在英文設置下發其他語言的郵件. 也不要這樣轉發
《解決方案》

台灣和大陸的公司共用一個郵件系統,沒辦法啊
《解決方案》

你們用的什麼郵件系統哦
沒採用UTF-8的編碼呀
《解決方案》

postfix
《解決方案》

我自己寫了一個patch,加入了charset detection功能,會依照郵件內的Content-Type或subject選擇合適的編碼,回覆和看附件時都會用同樣的encoding.....前提php要打開output_buffering.....如小弟的劣作有任何何bugs煩請告知,謝謝

diff -ruNb ../functions/i18n.php mail/functions/i18n.php
--- ../functions/i18n.php        2007-06-30 01:39:16.000000000 +0800
+++ ../functions/i18n.php        2007-10-29 07:52:07.000000000 +0800
@@ -468,6 +468,11 @@
     if ($my_language!='en_US') {
         $default_charset = $my_charset;
     }
+    //added by shing start
+    sqgetGlobalVar('charset', $charset, SQ_GET);
+        if ($charset!="")
+                $default_charset = $charset;
+    //added by shing end
}

/**
diff -ruNb ../functions/page_header.php mail/functions/page_header.php
--- ../functions/page_header.php        2007-07-14 21:04:00.000000000 +0800
+++ ../functions/page_header.php        2007-11-22 18:08:12.000000000 +0800
@@ -39,12 +39,42 @@
              $base_uri . 'themes/css/'.$custom_css.'">';
     }

+//added by shing start
+    global $charset, $mail_charset, $imapServerAddress, $imapPort ;
+    sqgetGlobalVar('charset', $charset, SQ_GET);
+    if (PAGE_NAME=="read_body") {
+
+        if ( sqgetGlobalVar('passed_id', $temp, SQ_GET) ) {
+          $passed_id = (int) $temp;
+        }
+        if ( sqgetGlobalVar('mailbox', $temp, SQ_GET) ) {
+          $mailbox = $temp;
+        }
+        if ( !sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
+          $passed_ent_id = '';
+        }
+        sqgetGlobalVar('key',        $key,          SQ_COOKIE);
+        sqgetGlobalVar('username',   $username,     SQ_SESSION);
+        sqgetGlobalVar('onetimepad', $onetimepad,   SQ_SESSION);
+        sqgetGlobalVar('delimiter',  $delimiter,    SQ_SESSION);
+
+        $imapConnection = sqimap_login($username, $key, $imapServerAddress,$imapPort, 0);
+        $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
+        $mail_charset = get_mail_charset($imapConnection,$passed_id, $passed_ent_id);
+    }
+//added by shing end
     if ($squirrelmail_language == 'ja_JP') {
         // Why is it added here? Header ('Content-Type:..) is used in i18n.php
         echo "<!-- \xfd\xfe -->\n";
         echo '<meta http-equiv="Content-type" content="text/html; charset=euc-jp">' . "\n";
     }

+// added by shing start
+    else if ($charset!="")
+               header('Content-type:text/html; charset='.$charset);
+    else if ($mail_charset!=false && !isset($_GET['charset']) )
+                header('Content-type:text/html; charset='.$mail_charset);
+//added by shing end
     if ($do_hook) {
         do_hook('generic_header');
     }
@@ -70,6 +100,34 @@
     $pageheader_sent = TRUE;
}

+//added by shing start
+function get_mail_charset($imapConnection,$id, $passed_ent_id) {
+    global $uid_support;
+
+    $header_full = array();
+    $header_output = array();
+    $second = array();
+    $first = array();
+
+    if (!$passed_ent_id) {
+        $read=sqimap_run_command ($imapConnection, "FETCH $id BODY", true, $a, $b, $uid_support);
+    } else {
+        $query = "FETCH $id BODY[".$passed_ent_id.'.HEADER]';
+        $read=sqimap_run_command ($imapConnection, $query, true, $a, $b, $uid_support);
+    }
+    $cnum = 0;
+
+    for ($i=1; $i < count($read); $i++) {
+        $line = $read[$i];
+        if (preg_match('/charset[ ]*=[ ]*["]?[\']?(+)[\']?["]?/i', $line, $regs))
+            return $regs;
+        if (preg_match('/subject[ ]*:[ ]*=[ ]*\?(+)\?/i', $line, $regs))
+                return $regs;
+     }
+      return false;
+}
+//added by shing end
+
function makeInternalLink($path, $text, $target='') {
     sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
     if ($target != '') {
diff -ruNb ../src/compose.php mail/src/compose.php
--- ../src/compose.php        2007-09-01 01:20:22.000000000 +0800
+++ ../src/compose.php        2007-10-28 23:19:05.000000000 +0800
@@ -1050,7 +1050,8 @@
             "// -->\n</script>\n\n";
     }

-    echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
+/*added by shing*/ global $charset; if ($charset!="") $charseturl = "?charset=$charset";
+/*changed by shing */    echo "\n" . '<form name="compose" action="compose.php'.$charseturl.'" method="post" ' .
         'enctype="multipart/form-data"';
     do_hook('compose_form');

diff -ruNb ../src/read_body.php mail/src/read_body.php
--- ../src/read_body.php        2007-07-20 19:13:46.000000000 +0800
+++ ../src/read_body.php        2007-10-28 23:19:05.000000000 +0800
@@ -604,23 +604,35 @@
         }
         $s .= $topbar_delimiter . $next_link;
     }
+//added by shing start
+global $mail_charset;
+sqgetGlobalVar('charset', $charset, SQ_GET);
+if (trim($charset)!="")
+       $charseturl = "&amp;charset=".$charset;
+else if ($mail_charset!=false && !isset($_GET['charset']) )
+        $charseturl = "&amp;charset=".$mail_charset;
+//added by shing end

     $s .= '</small></td>' . "\n" .
           html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>';
     $comp_action_uri = $comp_uri . '&amp;smaction=forward';
+    /*added by shing */ $comp_action_uri .= $charseturl;
     $s .= makeComposeLink($comp_action_uri, _("Forward"));

     if ($enable_forward_as_attachment) {
         $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
+    /*added by shing */ $comp_action_uri .= $charseturl;
         $s .= $topbar_delimiter;
         $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
     }

     $comp_action_uri = $comp_uri . '&amp;smaction=reply';
+    /*added by shing */ $comp_action_uri .= $charseturl;
     $s .= $topbar_delimiter;
     $s .= makeComposeLink($comp_action_uri, _("Reply"));

     $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
+    /*added by shing */ $comp_action_uri .= $charseturl;
     $s .= $topbar_delimiter;
     $s .= makeComposeLink($comp_action_uri, _("Reply All"));
     $s .= '</small></td></tr></table>';
@@ -671,6 +683,35 @@
          "</tr>\n";
     echo $s;

+    //added by shing start
+    global $mail_charset;
+    sqgetGlobalVar('charset', $charset, SQ_GET);
+    sqgetGlobalVar('auto', $auto, SQ_GET);
+    $sel = 'selected="selected"';
+    $pos = strpos($_SERVER['REQUEST_URI'], "&charset=");
+    if ($pos === false)
+            $href=$_SERVER['REQUEST_URI'];
+    else
+            $href = substr($_SERVER['REQUEST_URI'], 0, $pos);
+    $pos = strpos($href, "&auto=");
+    if ($pos != false)
+            $href = substr($href, 0, $pos);
+    if ($mail_charset!=false) $mail_charset_link = "&charset=$mail_charset";
+        echo "<tr>\n" .
+          html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Charset") . ":&nbsp;&nbsp;</b></td>\n" .
+          html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) .'
+          <select name="charset" onchange="JavaScript:location.href=\''.$href.'\'+this.value">
+                  <option value="&charset=">Default</option>
+                  <option value="&auto=true'.$mail_charset_link.'" '; if ($auto || !isset($_GET['charset'])) echo $sel;echo'>Auto (';if ($mail_charset==false) echo "none"; else echo $mail_charset; echo ")</option>\n";
+    $char_arr=array('big5', 'big5-hkscs', 'utf-8', 'gb2312', 'euc-kr', 'shift-jis');
+    foreach ($char_arr as $value) {
+        echo "<option value=\"&charset=$value\"";
+        if ($charset==$value && !$auto)
+                echo $sel;
+        echo ">$value</option>\n";
+    }
+     echo '</select></td></tr>';
+    //added by shing end
}

/***************************/
《解決方案》

將.po文件都轉換為utf-8編碼,並將配置文件全改為utf-8格式就不會出現亂碼了。
具體涉及到如下文件:
conf/config.ini.php的default_charset
function/i18n.php的lang[]和lang[]

[火星人 ] 請教關於squirrelmail簡體繁體亂碼問題已經有988次圍觀

http://coctec.com/docs/service/show-post-24856.html