[Svn] r2156 - trunk/roundcubemail/program/include

trac at roundcube.net trac at roundcube.net
Tue Dec 16 14:40:13 CET 2008


Author: alec
Date: 2008-12-16 07:40:13 -0600 (Tue, 16 Dec 2008)
New Revision: 2156

Modified:
   trunk/roundcubemail/program/include/main.inc
Log:
#1485549: fix mb_convert_encoding() issue


Modified: trunk/roundcubemail/program/include/main.inc
===================================================================
--- trunk/roundcubemail/program/include/main.inc	2008-12-16 13:00:55 UTC (rev 2155)
+++ trunk/roundcubemail/program/include/main.inc	2008-12-16 13:40:13 UTC (rev 2156)
@@ -178,7 +178,9 @@
  */
 function rcube_charset_convert($str, $from, $to=NULL)
   {
-  static $mbstring_loaded = null, $convert_warning = false;
+  static $mbstring_loaded = null;
+  static $mbstring_list = null;
+  static $convert_warning = false;
 
   $from = strtoupper($from);
   $to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to);
@@ -219,11 +221,21 @@
     $aliases['UTF-7'] = 'UTF7-IMAP';
     $aliases['WINDOWS-1257'] = 'ISO-8859-13';
     
-    // return if convert succeeded
-    if (($out = mb_convert_encoding($str, ($aliases[$to] ? $aliases[$to] : $to), ($aliases[$from] ? $aliases[$from] : $from))) != '')
-      return $out;
+    if (is_null($mbstring_list)) {
+      $mbstring_list = mb_list_encodings();
+      $mbstring_list = array_map('strtoupper', $mbstring_list);
     }
     
+    $mb_from = $aliases[$from] ? $aliases[$from] : $from;
+    $mb_to = $aliases[$to] ? $aliases[$to] : $to;
+    
+    // return if encoding found, string matches encoding and convert succeeded
+    if (in_array($mb_from, $mbstring_list) && in_array($mb_to, $mbstring_list))
+      if (mb_check_encoding($str, $mb_from))
+	if ($out = mb_convert_encoding($str, $mb_to, $mb_from))
+          return $out;
+    }
+    
   
   if (class_exists('utf8'))
     $conv = new utf8();

_______________________________________________
http://lists.roundcube.net/mailman/listinfo/svn



More information about the Svn mailing list