From 9840ab69e484d7c59f3ea734513d12d522839e62 Mon Sep 17 00:00:00 2001
From: alecpl <alec@alec.pl>
Date: Tue, 14 Dec 2010 02:37:52 -0500
Subject: [PATCH] - Fix charset conversion for text attachments without charset specification (#1487634)

---
 CHANGELOG                      |    1 +
 program/include/rcube_imap.php |   17 +++++++++--------
 2 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index c99e6eb..ffc9e93 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -21,6 +21,7 @@
 - Fix handling of untagged responses for AUTHENTICATE command (#1487450)
 - Add username and IP address to log message on unsuccessful login (#1487626)
 - Improved Mail-Followup-To and Mail-Reply-To headers handling
+- Fix charset conversion for text attachments without charset specification (#1487634)
 
 RELEASE 0.5-BETA
 ----------------
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 83c34bc..5aa23fa 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -2429,20 +2429,21 @@
 
         // TODO: Add caching for message parts
 
-        if (!$part) $part = 'TEXT';
+        if (!$part) {
+            $part = 'TEXT';
+        }
 
         $body = $this->conn->handlePartBody($this->mailbox, $uid, true, $part,
             $o_part->encoding, $print, $fp);
 
-        if ($fp || $print)
+        if ($fp || $print) {
             return true;
+        }
 
-        // convert charset (if text or message part)
-        if ($body && ($o_part->ctype_primary == 'text' || $o_part->ctype_primary == 'message')) {
-            // assume default if no charset specified
-            if (empty($o_part->charset) || strtolower($o_part->charset) == 'us-ascii')
-                $o_part->charset = $this->default_charset;
-
+        // convert charset (if text or message part) and part's charset is specified
+        if ($body && $o_part->charset
+            && preg_match('/^(text|message)$/', $o_part->ctype_primary)
+        ) {
             $body = rcube_charset_convert($body, $o_part->charset);
         }
 

--
Gitblit v1.9.1