From b8e65ce39b5330fb99371c9dc039f8d19f39477d Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Fri, 10 Aug 2007 12:38:29 -0400
Subject: [PATCH] Fix charset converting issues with iconv and mbstring
---
CHANGELOG | 3 +++
program/include/main.inc | 32 +++++++++++++++++++-------------
2 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index e41c32e..6dfbff4 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -9,6 +9,9 @@
- Protect AJAX request from being fetched by a foreign site (XSS)
- Make autocomplete for loginform configurable by the skin template
- Fix compose function from address book (closes #1484426)
+- Added //IGNORE to iconv call (patch #1484420, closes #1484023)
+- Check if mbstring supports charset (#1484290 and #1484292)
+- Prefer iconv over mbstring (as suggested in #1484292)
- Updated Simplified Chinese localization
- Added Ukrainian translation
diff --git a/program/include/main.inc b/program/include/main.inc
index 19d4214..9aa274f 100644
--- a/program/include/main.inc
+++ b/program/include/main.inc
@@ -472,9 +472,17 @@
static $s_mbstring_loaded = NULL;
// settings for mbstring module (by Tadashi Jokagi)
- if (is_null($s_mbstring_loaded))
- $MBSTRING = $s_mbstring_loaded = extension_loaded("mbstring");
- else
+ if (is_null($s_mbstring_loaded) && ($s_mbstring_loaded = extension_loaded("mbstring")))
+ {
+ $MBSTRING = array();
+ foreach (mb_list_encodings() as $charset)
+ $MBSTRING[strtoupper($charset)] = strtoupper($charset);
+
+ // add some alias charsets
+ $MBSTRING['UTF-7'] = "UTF7-IMAP";
+ $MBSTRING['WINDOWS-1257'] = "ISO-8859-13";
+ }
+ else if (is_null($s_mbstring_loaded))
$MBSTRING = $s_mbstring_loaded = FALSE;
if ($MBSTRING)
@@ -1049,6 +1057,7 @@
function rcube_charset_convert($str, $from, $to=NULL)
{
global $MBSTRING;
+ static $mb_encodings;
$from = strtoupper($from);
$to = $to==NULL ? strtoupper(RCMAIL_CHARSET) : strtoupper($to);
@@ -1056,20 +1065,17 @@
if ($from==$to || $str=='' || empty($from))
return $str;
- // convert charset using mbstring module
- if ($MBSTRING)
- {
- $to = $to=="UTF-7" ? "UTF7-IMAP" : $to;
- $from = $from=="UTF-7" ? "UTF7-IMAP": $from;
+ // convert charset using iconv module
+ if (function_exists('iconv') && $from != 'UTF-7' && $to != 'UTF-7')
+ return iconv($from, $to . "//IGNORE", $str);
+ // convert charset using mbstring module
+ if ($MBSTRING && ($mbfrom = $MBSTRING[$from]) && ($mbto = $MBSTRING[$to]))
+ {
// return if convert succeeded
- if (($out = mb_convert_encoding($str, $to, $from)) != '')
+ if (($out = mb_convert_encoding($str, $mbto, $mbfrom)) != '')
return $out;
}
-
- // convert charset using iconv module
- if (function_exists('iconv') && $from!='UTF-7' && $to!='UTF-7')
- return iconv($from, $to, $str);
$conv = new utf8();
--
Gitblit v1.9.1