Decoding support added when replying or forwarding message.
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 5 Oct 2003 08:16:09 +0000 (08:16 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Sun, 5 Oct 2003 08:16:09 +0000 (08:16 +0000)
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.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@5829 7612ce4b-ef26-0410-bec9-ea0150e637f0

functions/i18n.php
src/compose.php

index 1208da4427f4e8aa150e578d30415ca6d0476525..a0e9456377db1de2c5998947cee7f694e2103f0f 100644 (file)
@@ -852,4 +852,75 @@ endswitch;
 // return space instead of non-braking space. 
  return str_replace($nbsp,' ',$string);
 }
 // 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;
+}
 ?>
 ?>
index f3d500889be7823c5235397fb3b4cff84b4d18ab..8f7393ccd7e66379d3b8182ed99d4c8f834720b7 100644 (file)
@@ -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;
            $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;
 
     $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);
                 }
             }
                     $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) {
             $body .= $bodypart;
         }
         if ($default_use_priority) {