summaryrefslogtreecommitdiff
path: root/program
diff options
context:
space:
mode:
authorthomascube <thomas@roundcube.net>2006-08-23 21:52:13 +0000
committerthomascube <thomas@roundcube.net>2006-08-23 21:52:13 +0000
commit5f56a5bfa9ecdddd8c69884a6ac25b758c2b89f3 (patch)
treec18d3a23f2b93fb32449adab679311e893ce2092 /program
parent6c76c91951d259f59b2b7a42b8fe895dcc0ef21b (diff)
Fixed wrong usage of mbstring (Bug #1462439)
Diffstat (limited to 'program')
-rw-r--r--program/include/main.inc47
-rw-r--r--program/lib/utf8.class.php8
2 files changed, 19 insertions, 36 deletions
diff --git a/program/include/main.inc b/program/include/main.inc
index 1a2b8c793..051d6e250 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -377,38 +377,14 @@ function load_gui()
// 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 @@ function rcmail_message_cache_gc()
// 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
diff --git a/program/lib/utf8.class.php b/program/lib/utf8.class.php
index c0bd0a73b..3371c25a8 100644
--- a/program/lib/utf8.class.php
+++ b/program/lib/utf8.class.php
@@ -50,7 +50,13 @@ $utf8_maps = array(
"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");