Bug 397021 - Subject line <foo@bar> in the forward inline body not shown in html. r=dbienvenu
authorJonathan Kamens <jik@kamens.us>
Wed, 28 Mar 2012 13:06:45 -0400
changeset 9773 30c2149ba8878c3a41bc6c9992d42c2993198388
parent 9772 5fda17fdf77921b75b77d2c692f7e0912e40496a
child 9774 b42a1b7630ba6b2c7a07463802f918f9379c6bc5
push id7457
push userryanvm@gmail.com
push dateThu, 29 Mar 2012 00:32:42 +0000
treeherdercomm-central@c604f2ff2691 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbienvenu
bugs397021
Bug 397021 - Subject line <foo@bar> in the forward inline body not shown in html. r=dbienvenu
mail/test/mozmill/composition/test-forwarded-content.js
mailnews/mime/src/mimedrft.cpp
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/composition/test-forwarded-content.js
@@ -0,0 +1,60 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Tests that forwarded content is ok.
+ */
+
+const MODULE_NAME = "test-forwarded-content";
+
+const RELATIVE_ROOT = "../shared-modules";
+const MODULE_REQUIRES = ["folder-display-helpers",
+                         "window-helpers", "compose-helpers"];
+
+var elib = {};
+Components.utils.import("resource://mozmill/modules/elementslib.js", elib);
+
+var folderHelper = null;
+var windowindowHelperelper = null;
+var composeHelper = null;
+
+var folder = null;
+
+var setupModule = function(module) {
+  folderHelper = collector.getModule("folder-display-helpers");
+  folderHelper.installInto(module);
+  windowHelper = collector.getModule("window-helpers");
+  windowHelper.installInto(module);
+  composeHelper = collector.getModule("compose-helpers");
+  composeHelper.installInto(module);
+
+  folder = folderHelper.create_folder("Forward Content Testing");
+  add_message_to_folder(folder, create_message({
+    subject: "something like <foo@bar>",
+    body: {body: "Testing bug 397021!"},
+  }));
+}
+
+/**
+ * Test that the subject is set properly in the forwarded message content
+ * when you hit forward.
+ */
+function test_forwarded_subj() {
+  be_in_folder(folder);
+
+  let msg = select_click_row(0);
+  assert_selected_and_displayed(mc, msg);
+
+  let fwdWin = open_compose_with_forward();
+
+  let headerTableText  = fwdWin.e("content-frame").contentDocument
+                          .getElementsByTagName("table")[0].textContent;
+  if (headerTableText.indexOf(msg.mime2DecodedSubject) == -1) {
+    throw new Error("Subject not set correctly in header table: subject=" + 
+                    msg.mime2DecodedSubject + ", header table text=" +
+                    headerTableText);
+  }
+  close_compose_window(fwdWin);
+}
+
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -75,16 +75,17 @@
 #include "nsDirectoryServiceDefs.h"
 #include "nsIMsgMessageService.h"
 #include "nsMsgUtils.h"
 #include "nsCExternalHandlerService.h"
 #include "nsIMIMEService.h"
 #include "nsIMsgHeaderParser.h"
 #include "nsIMsgAccountManager.h"
 #include "nsMsgBaseCID.h"
+#include "nsEscape.h"
 
 //
 // Header strings...
 //
 #define HEADER_NNTP_POSTING_HOST      "NNTP-Posting-Host"
 #define MIME_HEADER_TABLE             "<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=0 class=\"moz-email-headers-table\">"
 #define HEADER_START_JUNK             "<TR><TH VALIGN=BASELINE ALIGN=RIGHT NOWRAP>"
 #define HEADER_MIDDLE_JUNK            ": </TH><TD>"
@@ -585,42 +586,16 @@ mime_draft_process_attachments(mime_draf
   return attachData;
 
 FAIL:
   delete [] attachData;
   return nsnull;
 }
 
 static void
-mime_fix_up_html_address( char **addr)
-{
-  //
-  // We need to replace paired <> they are treated as HTML tag
-  //
-  if (addr && *addr && PL_strchr(*addr, '<') && PL_strchr(*addr, '>'))
-  {
-    char *lt = NULL;
-    PRInt32 newLen = 0;
-    do
-    {
-      newLen = strlen(*addr) + 3 + 1;
-      *addr = (char *) PR_REALLOC(*addr, newLen);
-      NS_ASSERTION (*addr, "out of memory fixing up html address");
-      lt = PL_strchr(*addr, '<');
-      NS_ASSERTION(lt, "couldn't find < char in address");
-      memmove(lt+4, lt+1, newLen - 4 - (lt - *addr));
-      *lt++ = '&';
-      *lt++ = 'l';
-      *lt++ = 't';
-      *lt = ';';
-    } while (PL_strchr(*addr, '<'));
-  }
-}
-
-static void
 mime_intl_insert_message_header_1(char        **body,
                                   char        **hdr_value,
                                   const char  *hdr_str,
                                   const char  *html_hdr_str,
                                   const char  *mailcharset,
                                   bool        htmlEdit)
 {
   if (!body || !hdr_value || !hdr_str)
@@ -643,18 +618,22 @@ mime_intl_insert_message_header_1(char  
   }
   else
     NS_MsgSACat(body, ": ");
 
     // MIME decode header
     char* utf8 = MIME_DecodeMimeHeader(*hdr_value, mailcharset, false,
                                        true);
     if (NULL != utf8) {
-        NS_MsgSACat(body, utf8);
-        PR_Free(utf8);
+      char *escaped = nsnull;
+      if (htmlEdit)
+        escaped = nsEscapeHTML(utf8);
+      NS_MsgSACat(body, escaped ? escaped : utf8);
+      NS_Free(escaped);
+      PR_Free(utf8);
     } else {
         NS_MsgSACat(body, *hdr_value); // raw MIME encoded string
     }
 
   if (htmlEdit)
     NS_MsgSACat(body, HEADER_END_JUNK);
 }
 
@@ -786,19 +765,16 @@ mime_insert_all_headers(char            
     memcpy(c2, contents, end - contents);
     c2[end - contents] = 0;
 
     /* Do not reveal bcc recipients when forwarding a message!
        See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
     */
     if (PL_strcasecmp(name, "bcc") != 0)
     {
-      if (htmlEdit)
-        mime_fix_up_html_address(&c2);
-
       if (!PL_strcasecmp(name, "resent-from") || !PL_strcasecmp(name, "from") ||
           !PL_strcasecmp(name, "resent-to") || !PL_strcasecmp(name, "to") ||
           !PL_strcasecmp(name, "resent-cc") || !PL_strcasecmp(name, "cc") ||
           !PL_strcasecmp(name, "reply-to"))
         UnquoteMimeAddress(parser, &c2);
 
       mime_intl_insert_message_header_1(&newBody, &c2, name, name, mailcharset, htmlEdit);
     }
@@ -893,96 +869,86 @@ mime_insert_normal_headers(char         
                       mailcharset, htmlEdit);
   if (resent_date)
     mime_intl_insert_message_header_1(&newBody, &resent_date,
                       HEADER_RESENT_DATE,
                       MimeGetNamedString(MIME_MHTML_RESENT_DATE),
                       mailcharset, htmlEdit);
   if (resent_from)
   {
-    if (htmlEdit) mime_fix_up_html_address(&resent_from);
     mime_intl_insert_message_header_1(&newBody, &resent_from,
                       HEADER_RESENT_FROM,
                       MimeGetNamedString(MIME_MHTML_RESENT_FROM),
                       mailcharset, htmlEdit);
   }
   if (resent_to)
   {
-    if (htmlEdit) mime_fix_up_html_address(&resent_to);
     mime_intl_insert_message_header_1(&newBody, &resent_to,
                       HEADER_RESENT_TO,
                       MimeGetNamedString(MIME_MHTML_RESENT_TO),
                       mailcharset, htmlEdit);
   }
   if (resent_cc)
   {
-    if (htmlEdit) mime_fix_up_html_address(&resent_cc);
     mime_intl_insert_message_header_1(&newBody, &resent_cc,
                       HEADER_RESENT_CC,
                       MimeGetNamedString(MIME_MHTML_RESENT_CC),
                       mailcharset, htmlEdit);
   }
   if (date)
     mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE,
                       MimeGetNamedString(MIME_MHTML_DATE),
                       mailcharset, htmlEdit);
   if (from)
   {
-    if (htmlEdit) mime_fix_up_html_address(&from);
     mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM,
                       MimeGetNamedString(MIME_MHTML_FROM),
                       mailcharset, htmlEdit);
   }
   if (reply_to)
   {
-    if (htmlEdit) mime_fix_up_html_address(&reply_to);
     mime_intl_insert_message_header_1(&newBody, &reply_to, HEADER_REPLY_TO,
                       MimeGetNamedString(MIME_MHTML_REPLY_TO),
                       mailcharset, htmlEdit);
   }
   if (organization)
     mime_intl_insert_message_header_1(&newBody, &organization,
                       HEADER_ORGANIZATION,
                       MimeGetNamedString(MIME_MHTML_ORGANIZATION),
                       mailcharset, htmlEdit);
   if (to)
   {
-    if (htmlEdit) mime_fix_up_html_address(&to);
     mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO,
                       MimeGetNamedString(MIME_MHTML_TO),
                       mailcharset, htmlEdit);
   }
   if (cc)
   {
-    if (htmlEdit) mime_fix_up_html_address(&cc);
     mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC,
                       MimeGetNamedString(MIME_MHTML_CC),
                       mailcharset, htmlEdit);
   }
     /*
       Do not reveal bcc recipients when forwarding a message!
       See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
     */
   if (newsgroups)
     mime_intl_insert_message_header_1(&newBody, &newsgroups, HEADER_NEWSGROUPS,
                       MimeGetNamedString(MIME_MHTML_NEWSGROUPS),
                       mailcharset, htmlEdit);
   if (followup_to)
   {
-    if (htmlEdit) mime_fix_up_html_address(&followup_to);
     mime_intl_insert_message_header_1(&newBody, &followup_to,
                       HEADER_FOLLOWUP_TO,
                       MimeGetNamedString(MIME_MHTML_FOLLOWUP_TO),
                       mailcharset, htmlEdit);
   }
   // only show references for newsgroups
   if (newsgroups && references)
   {
-    if (htmlEdit) 
-      mime_fix_up_html_address(&references);
     mime_intl_insert_message_header_1(&newBody, &references,
                       HEADER_REFERENCES,
                       MimeGetNamedString(MIME_MHTML_REFERENCES),
                       mailcharset, htmlEdit);
   }
   if (htmlEdit)
   {
     NS_MsgSACat(&newBody, "</TABLE>");
@@ -1064,50 +1030,45 @@ mime_insert_micro_headers(char          
   else
   {
     NS_MsgSACopy(&(newBody), MSG_LINEBREAK MSG_LINEBREAK);
     NS_MsgSACat(&newBody, MimeGetNamedString(MIME_FORWARDED_MESSAGE_HTML_USER_WROTE));
   }
 
   if (from)
   {
-    if (htmlEdit)
-      mime_fix_up_html_address(&from);
     mime_intl_insert_message_header_1(&newBody, &from, HEADER_FROM,
                     MimeGetNamedString(MIME_MHTML_FROM),
                     mailcharset, htmlEdit);
   }
   if (subject)
     mime_intl_insert_message_header_1(&newBody, &subject, HEADER_SUBJECT,
                     MimeGetNamedString(MIME_MHTML_SUBJECT),
                       mailcharset, htmlEdit);
 /*
   if (date)
     mime_intl_insert_message_header_1(&newBody, &date, HEADER_DATE,
                     MimeGetNamedString(MIME_MHTML_DATE),
                     mailcharset, htmlEdit);
 */
   if (resent_from)
   {
-    if (htmlEdit) mime_fix_up_html_address(&resent_from);
     mime_intl_insert_message_header_1(&newBody, &resent_from,
                     HEADER_RESENT_FROM,
                     MimeGetNamedString(MIME_MHTML_RESENT_FROM),
                     mailcharset, htmlEdit);
   }
   if (to)
   {
-    if (htmlEdit) mime_fix_up_html_address(&to);
     mime_intl_insert_message_header_1(&newBody, &to, HEADER_TO,
                     MimeGetNamedString(MIME_MHTML_TO),
                     mailcharset, htmlEdit);
   }
   if (cc)
   {
-    if (htmlEdit) mime_fix_up_html_address(&cc);
     mime_intl_insert_message_header_1(&newBody, &cc, HEADER_CC,
                     MimeGetNamedString(MIME_MHTML_CC),
                     mailcharset, htmlEdit);
   }
   /*
     Do not reveal bcc recipients when forwarding a message!
     See http://bugzilla.mozilla.org/show_bug.cgi?id=41150
   */