diff options
| author | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-12-16 13:40:13 +0000 |
|---|---|---|
| committer | alec <alec@208e9e7b-5314-0410-a742-e7e81cd9613c> | 2008-12-16 13:40:13 +0000 |
| commit | a9d2a18eb676d8fb1bc42e7ece476a2de38eb52a (patch) | |
| tree | a2deb4ec9e60b79dcde54a531d3103f9113aae1c /roundcubemail/program | |
| parent | 0efe7c675c39cebe55ffb044bef71980263e45ae (diff) | |
#1485549: fix mb_convert_encoding() issue
git-svn-id: https://svn.roundcube.net/trunk@2156 208e9e7b-5314-0410-a742-e7e81cd9613c
Diffstat (limited to 'roundcubemail/program')
| -rw-r--r-- | roundcubemail/program/include/main.inc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/roundcubemail/program/include/main.inc b/roundcubemail/program/include/main.inc index 95b167969..7cf739282 100644 --- a/roundcubemail/program/include/main.inc +++ b/roundcubemail/program/include/main.inc @@ -178,7 +178,9 @@ function rcmail_cache_gc() */ 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,9 +221,19 @@ function rcube_charset_convert($str, $from, $to=NULL) $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; } |
