浏览代码

Decoding support added when replying or forwarding message.
Original patch was provided by Viktor S. Grishchenko <gritzko@plotinka.ru>
Currently patch works only with utf-8 translations and with Ukrainian/Bulgarian
translations if message has similar charset. Patch should not have any
effect on other translations and From: and Subject: headers still need to be
fixed with some messages.

tokul 22 年之前
父节点
当前提交
f9fdf4266b
共有 2 个文件被更改,包括 78 次插入1 次删除
  1. 71 0
      functions/i18n.php
  2. 7 1
      src/compose.php

+ 71 - 0
functions/i18n.php

@@ -852,4 +852,75 @@ endswitch;
 // return space instead of non-braking space. 
  return str_replace($nbsp,' ',$string);
 }
+
+function is_conversion_safe($input_charset) {
+  global $languages, $sm_notAlias, $default_charset;
+
+ // convert to lower case
+ $input_charset = strtolower($input_charset);
+
+ // Is user's locale Unicode based ?
+ if ( $default_charset == "utf-8" ) {
+   return true;
+ }
+
+ // Charsets that are similar
+switch ($default_charset):
+case "windows-1251":
+      if ( $input_charset == "iso-8859-5" || 
+	   $input_charset == "koi8-r" ||
+	   $input_charset == "koi8-u" ) {
+        return true;
+     } else {
+        return false;
+     }
+case "windows-1257":
+  if ( $input_charset == "iso-8859-13" || 
+	 $input_charset == "iso-8859-4" ) {
+    return true;
+  } else {
+    return false;
+  }
+case "iso-8859-4":
+  if ( $input_charset == "iso-8859-13" || 
+	 $input_charset == "windows-1257" ) {
+     return true;
+  } else {
+     return false;
+  }
+case "iso-8859-5":
+  if ( $input_charset == "windows-1251" || 
+	 $input_charset == "koi8-r" || 
+	 $input_charset == "koi8-u" ) {
+     return true;
+  } else {
+     return false;
+  }
+case "iso-8859-13":
+  if ( $input_charset == "iso-8859-4" ||
+       $input_charset == "windows-1257" ) {
+     return true;
+  } else {
+     return false;
+  }
+case "koi8-r":
+  if ( $input_charset == "windows-1251" ||
+	 $input_charset == "iso-8859-5" || 
+	 $input_charset == "koi8-u" ) {
+     return true;
+  } else {
+     return false;
+  }
+case "koi8-u":
+  if ( $input_charset == "windows-1251" ||
+	$input_charset == "iso-8859-5" ||
+	$input_charset == "koi8-r" ) {
+     return true;
+  } else {
+     return false;
+  }
+default:
+   return false;
+endswitch;
+}
 ?>

+ 7 - 1
src/compose.php

@@ -562,7 +562,7 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
            $use_signature, $composesession, $data_dir, $username,
            $username, $key, $imapServerAddress, $imapPort, $compose_messages,
            $composeMessage;
-    global $languages, $squirrelmail_language;
+    global $languages, $squirrelmail_language, $default_charset;
 
     $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
     $mailprio = 3;
@@ -619,6 +619,12 @@ function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $se
                     $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
                 }
             }
+	    
+	    $actual = $body_part_entity->header->parameters['charset'];
+	    if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
+		$bodypart = charset_decode($actual,$bodypart);
+	    }
+	    
             $body .= $bodypart;
         }
         if ($default_use_priority) {