thomascube
2006-08-23 5f56a5bfa9ecdddd8c69884a6ac25b758c2b89f3
Fixed wrong usage of mbstring (Bug #1462439)

2 files modified
55 ■■■■■ changed files
program/include/main.inc 47 ●●●● patch | view | raw | blame | history
program/lib/utf8.class.php 8 ●●●● patch | view | raw | blame | history
program/include/main.inc
@@ -377,38 +377,14 @@
// set localization charset based on the given language
function rcmail_set_locale($lang)
  {
  global $OUTPUT, $MBSTRING, $MBSTRING_ENCODING;
  global $OUTPUT, $MBSTRING;
  static $s_mbstring_loaded = NULL;
  
  // settings for mbstring module (by Tadashi Jokagi)
  if ($s_mbstring_loaded===NULL)
    {
    if ($s_mbstring_loaded = extension_loaded("mbstring"))
      {
      $MBSTRING = TRUE;
      if (function_exists("mb_mbstring_encodings"))
        $MBSTRING_ENCODING = mb_mbstring_encodings();
      else
        $MBSTRING_ENCODING = array("ISO-8859-1", "UTF-7", "UTF7-IMAP", "UTF-8",
                                   "ISO-2022-JP", "EUC-JP", "EUCJP-WIN",
                                   "SJIS", "SJIS-WIN");
       $MBSTRING_ENCODING = array_map("strtoupper", $MBSTRING_ENCODING);
       if (in_array("SJIS", $MBSTRING_ENCODING))
         $MBSTRING_ENCODING[] = "SHIFT_JIS";
       }
     else
      {
      $MBSTRING = FALSE;
      $MBSTRING_ENCODING = array();
      }
    }
  if ($MBSTRING && function_exists("mb_language"))
    {
    if (!@mb_language(strtok($lang, "_")))
      $MBSTRING = FALSE;   //  unsupport language
    }
  if (is_null($s_mbstring_loaded))
    $MBSTRING = $s_mbstring_loaded = extension_loaded("mbstring");
  else
    $MBSTRING = $s_mbstring_loaded = FALSE;
  $OUTPUT->set_charset(rcube_language_prop($lang, 'charset'));
  }
@@ -868,22 +844,23 @@
// this function is not complete and not tested well
function rcube_charset_convert($str, $from, $to=NULL)
  {
  global $MBSTRING, $MBSTRING_ENCODING;
  global $MBSTRING;
  $from = strtoupper($from);
  $to = $to==NULL ? strtoupper($GLOBALS['CHARSET']) : strtoupper($to);
  if ($from==$to)
  if ($from==$to || $str=='')
    return $str;
  // convert charset using mbstring module  
  if ($MBSTRING)
    {
    $to = $to=="UTF-7" ? "UTF7-IMAP" : $to;
    $from = $from=="UTF-7" ? "UTF7-IMAP": $from;
    if (in_array($to, $MBSTRING_ENCODING) && in_array($from, $MBSTRING_ENCODING))
      return mb_convert_encoding($str, $to, $from);
    // return if convert succeeded
    if (($out = mb_convert_encoding($str, $to, $from)) != '')
      return $out;
    }
  // convert charset using iconv module  
program/lib/utf8.class.php
@@ -50,7 +50,13 @@
  "ISO-8859-1" => UTF8_MAP_DIR . "/ISO-8859-1.map",
  "ISO-8859-2" => UTF8_MAP_DIR . "/ISO-8859-2.map",
  "ISO-8859-3" => UTF8_MAP_DIR . "/ISO-8859-3.map",
  "ISO-8859-4" => UTF8_MAP_DIR . "/ISO-8859-4.map");
  "ISO-8859-4" => UTF8_MAP_DIR . "/ISO-8859-4.map",
  "ISO-8859-5" => UTF8_MAP_DIR . "/ISO-8859-5.map",
  "ISO-8859-6" => UTF8_MAP_DIR . "/ISO-8859-6.map",
  "ISO-8859-7" => UTF8_MAP_DIR . "/ISO-8859-7.map",
  "ISO-8859-8" => UTF8_MAP_DIR . "/ISO-8859-8.map",
  "ISO-8859-9" => UTF8_MAP_DIR . "/ISO-8859-9.map"
  );
//Error constants
define("ERR_OPEN_MAP_FILE","ERR_OPEN_MAP_FILE");