From 54029ea959b5f59447e3f0a01a453fd5fe0ba8fa Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Sat, 21 Dec 2013 08:49:00 -0500
Subject: [PATCH] Fix broken text/* attachments when forwarding/editing a message (#1489426)

---
 CHANGELOG                            |    1 +
 program/steps/mail/compose.inc       |    4 ++--
 program/lib/Roundcube/rcube_imap.php |    2 +-
 3 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 967e2a3..b1eca46 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,7 @@
 CHANGELOG Roundcube Webmail
 ===========================
 
+- Fix broken text/* attachments when forwarding/editing a message (#1489426)
 - Improved minified files handling, added css minification (#1486988)
 - Fix handling of X-Forwarded-For header with multiple addresses (#1489481)
 - Fix border issue on folders list in classic skin (#1489473)
diff --git a/program/lib/Roundcube/rcube_imap.php b/program/lib/Roundcube/rcube_imap.php
index dc53058..f1363ca 100644
--- a/program/lib/Roundcube/rcube_imap.php
+++ b/program/lib/Roundcube/rcube_imap.php
@@ -2121,7 +2121,7 @@
         // convert charset (if text or message part)
         if ($body && preg_match('/^(text|message)$/', $o_part->ctype_primary)) {
             // Remove NULL characters if any (#1486189)
-            if (strpos($body, "\x00") !== false) {
+            if ($formatted && strpos($body, "\x00") !== false) {
                 $body = str_replace("\x00", '', $body);
             }
 
diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index f75b219..aee31bb 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -1286,12 +1286,12 @@
     $temp_dir = unslashify($rcmail->config->get('temp_dir'));
     $path = tempnam($temp_dir, 'rcmAttmnt');
     if ($fp = fopen($path, 'w')) {
-      $message->get_part_content($pid, $fp);
+      $message->get_part_content($pid, $fp, true, 0, false);
       fclose($fp);
     } else
       return false;
   } else {
-    $data = $message->get_part_content($pid);
+    $data = $message->get_part_content($pid, null, true, 0, false);
   }
 
   $mimetype = $part->ctype_primary . '/' . $part->ctype_secondary;

--
Gitblit v1.9.1