Minor cleanups
[squirrelmail.git] / functions / imap_utf7_local.php
index eb5db9c43b84e68266db0d48a8c906de5fc69be6..86acabb73c328c4e998486832afec439cf5bfd66 100644 (file)
@@ -3,25 +3,33 @@
 /**
  * imap_utf7_local.php
  *
- * Copyright (c) 1999-2003 The SquirrelMail Project Team
+ * Copyright (c) 1999-2004 The SquirrelMail Project Team
  * Licensed under the GNU GPL. For full terms see the file COPYING.
  *
  * This implements all functions that do imap UTF7 conversions.
  *
- * $Id $
+ * @version $Id$
+ * @package squirrelmail
+ * @subpackage imap
  */
 
+/**
+ * @param string $str
+ * @param string $to_encoding
+ * @param string $from_encoding
+ * @param string $default_charset
+ * @return string
+ */
 function sqimap_mb_convert_encoding($str, $to_encoding, $from_encoding, $default_charset)
 {
-  // Allows mbstring functions only with iso-8859-*, utf-8 and 
+  // Allows mbstring functions only with iso-8859-*, utf-8 and
   // iso-2022-jp (Japanese)
   // koi8-r and gb2312 can be added only in php 4.3+
-  if ( stristr('iso-8859-',$default_charset) ||
-       stristr('utf-8',$default_charset) || 
-       stristr('iso-2022-jp',$default_charset) ) {
+  if ( stristr($default_charset, 'iso-8859-') ||
+       stristr($default_charset, 'utf-8') ||
+       stristr($default_charset, 'iso-2022-jp') ) {
     if (function_exists('mb_convert_encoding')) {
-      set_my_charset();
-      return mb_convert_encoding($s, $to_encoding, $from_encoding);
+      return mb_convert_encoding($str, $to_encoding, $from_encoding);
     }
   }
   return '';
@@ -29,24 +37,25 @@ function sqimap_mb_convert_encoding($str, $to_encoding, $from_encoding, $default
 
 function imap_utf7_encode_local($s) {
     global $languages, $squirrelmail_language;
-    
+
     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
-        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
-        return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_encode', $s);
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'].'_utf7_imap_encode')) {
+        return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_utf7_imap_encode', $s);
     }
 
     if ($s == '')  //If empty, don't bother
       return '';
 
     global $default_charset;
-    if (strtolower($default_charset) != 'iso-8859-1') {
+    set_my_charset();  //must be called before using $default_charset
+    if ((strtolower($default_charset) != 'iso-8859-1') && ($default_charset != '')) {
       $utf7_s = sqimap_mb_convert_encoding($s, 'UTF7-IMAP', $default_charset, $default_charset);
       if ($utf7_s != '')
         return $utf7_s;
     }
 
-    // Later code works only for ISO-8859-1 
-    
+    // Later code works only for ISO-8859-1
+
        $b64_s = '';    // buffer for substring to be base64-encoded
        $utf7_s = '';   // imap-utf7-encoded string
        for ($i = 0; $i < strlen($s); $i++) {
@@ -81,24 +90,25 @@ function imap_utf7_encode_local($s) {
 
 function imap_utf7_decode_local($s) {
     global $languages, $squirrelmail_language;
-    
+
     if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
-        function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
-        return $languages[$squirrelmail_language]['XTRA_CODE']('utf7-imap_decode', $s);
+        function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_utf7_imap_decode')) {
+        return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_utf7_imap_decode', $s);
     }
 
     if ($s == '')  //If empty, don't bother
       return '';
 
     global $default_charset;
-    if (strtolower($default_charset) != 'iso-8859-1') {
+    set_my_charset();  //must be called before using $default_charset
+    if ((strtolower($default_charset) != 'iso-8859-1') && ($default_charset != '')) {
       $utf7_s = sqimap_mb_convert_encoding($s, $default_charset, 'UTF7-IMAP', $default_charset);
       if ($utf7_s != '')
         return $utf7_s;
     }
 
     // Later code works only for ISO-8859-1
-    
+
        $b64_s = '';
        $iso_8859_1_s = '';
        for ($i = 0, $len = strlen($s); $i < $len; $i++) {