From f2a9a9007a490d24aa333974ac6205fb286a218a Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Fri, 02 Aug 2013 02:35:31 -0400
Subject: [PATCH] Fix broken (in 93b0a30c1c8aa29d862b587b31e52bcc344b8d16) text/plain body of a message when using "edit as new"

---
 program/steps/mail/compose.inc |   15 ++++++++++-----
 1 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc
index 9bf36d2..af84619 100644
--- a/program/steps/mail/compose.inc
+++ b/program/steps/mail/compose.inc
@@ -1005,12 +1005,17 @@
     $cid_map = rcmail_write_compose_attachments($MESSAGE, $bodyIsHtml);
   }
 
-  // clean up html tags - XSS prevention (#1489251)
-  $body = rcmail_wash_html($body, array('safe' => 1), $cid_map);
+  // clean up HTML tags - XSS prevention (#1489251)
+  if ($bodyIsHtml) {
+    $body = rcmail_wash_html($body, array('safe' => 1), $cid_map);
 
-  // replace cid with href in inline images links
-  if ($cid_map) {
-    $body = str_replace(array_keys($cid_map), array_values($cid_map), $body);
+    // remove comments (produced by washtml)
+    $body = preg_replace('/<!--[^>]+-->/', '', $body);
+
+    // replace cid with href in inline images links
+    if (!empty($cid_map)) {
+      $body = str_replace(array_keys($cid_map), array_values($cid_map), $body);
+    }
   }
 
   return $body;

--
Gitblit v1.9.1