From 764641d4a38e0a9856cced092ac7c294a2956dcf Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 29 Aug 2012 03:22:07 -0400
Subject: [PATCH] Fix decoding of HTML messages with UTF-16 charset specified (#1488654)

---
 CHANGELOG                         |    1 +
 program/include/rcube_charset.php |    6 ++++++
 2 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index cddfc96..7654cde 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix decoding of HTML messages with UTF-16 charset specified (#1488654)
 - Fix quota capability detection so it can be overwritten by a plugin (#1488655)
 - Added template object 'frame'
 - Fix identity selection on reply (#1488101)
diff --git a/program/include/rcube_charset.php b/program/include/rcube_charset.php
index 380d149..1740a60 100644
--- a/program/include/rcube_charset.php
+++ b/program/include/rcube_charset.php
@@ -181,6 +181,12 @@
         $to   = empty($to) ? strtoupper(RCMAIL_CHARSET) : self::parse_charset($to);
         $from = self::parse_charset($from);
 
+        // It is a common case when UTF-16 charset is used with US-ASCII content (#1488654)
+        // In that case we can just skip the conversion (use UTF-8)
+        if ($from == 'UTF-16' && !preg_match('/[^\x00-\x7F]/', $str)) {
+            $from = 'UTF-8';
+        }
+
         if ($from == $to || empty($str) || empty($from)) {
             return $str;
         }

--
Gitblit v1.9.1