Bug 998191, part 7: Remove nsIMsgCompFields::otherRandomHeaders, r=irving
authorJoshua Cranmer <Pidgeot18@gmail.com>
Wed, 07 Jan 2015 15:58:18 -0600
changeset 21602 e82cc8049281382d045df1366c465688225bd7da
parent 21601 a2546abffc36d708363a2f8a5ca2823b28267631
child 21603 81ecc4e6871facb270e6b40431b1d3c15ba636ef
push id1305
push usermbanner@mozilla.com
push dateMon, 23 Feb 2015 19:48:12 +0000
treeherdercomm-beta@3ae4f13858fd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersirving
bugs998191
Bug 998191, part 7: Remove nsIMsgCompFields::otherRandomHeaders, r=irving The replacement for this is to use the generic header accessors provided by msgIStructuredHeaders and its writable cousin. CLOSED TREE due to the need to fix up SeaMonkey code.
mail/components/compose/content/addressingWidgetOverlay.js
mailnews/compose/public/nsIMsgCompFields.idl
mailnews/compose/src/nsMsgCompFields.cpp
mailnews/compose/src/nsMsgCompFields.h
mailnews/compose/src/nsMsgCompUtils.cpp
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/test/unit/test_messageHeaders.js
mailnews/mime/src/mimedrft.cpp
suite/mailnews/compose/addressingWidgetOverlay.js
--- a/mail/components/compose/content/addressingWidgetOverlay.js
+++ b/mail/components/compose/content/addressingWidgetOverlay.js
@@ -114,17 +114,16 @@ function Recipients2CompFields(msgCompFi
   {
     var i = 1;
     var addrTo = "";
     var addrCc = "";
     var addrBcc = "";
     var addrReply = "";
     var addrNg = "";
     var addrFollow = "";
-    var addrOther = "";
     var to_Sep = "";
     var cc_Sep = "";
     var bcc_Sep = "";
     var reply_Sep = "";
     var ng_Sep = "";
     var follow_Sep = "";
 
     var recipientType;
@@ -163,31 +162,33 @@ function Recipients2CompFields(msgCompFi
         switch (recipientType)
         {
           case "addr_to"          : addrTo += to_Sep + recipient; to_Sep = ",";               break;
           case "addr_cc"          : addrCc += cc_Sep + recipient; cc_Sep = ",";               break;
           case "addr_bcc"         : addrBcc += bcc_Sep + recipient; bcc_Sep = ",";            break;
           case "addr_reply"       : addrReply += reply_Sep + recipient; reply_Sep = ",";      break;
           case "addr_newsgroups"  : addrNg += ng_Sep + fieldValue; ng_Sep = ",";              break;
           case "addr_followup"    : addrFollow += follow_Sep + fieldValue; follow_Sep = ",";  break;
-          // do CRLF, same as PUSH_NEWLINE() in nsMsgSend.h / nsMsgCompUtils.cpp
-          // see bug #195965
-          case "addr_other"       : addrOther += awGetPopupElement(i).selectedItem.getAttribute("label") + " " + fieldValue + "\r\n";break;
+          case "addr_other":
+            let headerName =
+              awGetPopupElement(i).selectedItem.getAttribute("label");
+            headerName = headerName.substring(0, headerName.indexOf(':'));
+            msgCompFields.setHeader(headerName, fieldValue);
+            break;
         }
       }
       i ++;
     }
 
     msgCompFields.to = addrTo;
     msgCompFields.cc = addrCc;
     msgCompFields.bcc = addrBcc;
     msgCompFields.replyTo = addrReply;
     msgCompFields.newsgroups = addrNg;
     msgCompFields.followupTo = addrFollow;
-    msgCompFields.otherRandomHeaders = addrOther;
   }
   else
     dump("Message Compose Error: msgCompFields is null (ExtractRecipients)");
 }
 
 function CompFields2Recipients(msgCompFields)
 {
   if (msgCompFields) {
@@ -199,17 +200,16 @@ function CompFields2Recipients(msgCompFi
     // dump("replacing child in comp fields 2 recips \n");
     listbox.parentNode.replaceChild(newListBoxNode, listbox);
 
     top.MAX_RECIPIENTS = 0;
     let msgReplyTo = msgCompFields.replyTo;
     let msgTo = msgCompFields.to;
     let msgCC = msgCompFields.cc;
     let msgBCC = msgCompFields.bcc;
-    let msgRandomHeaders = msgCompFields.otherRandomHeaders;
     let msgNewsgroups = msgCompFields.newsgroups;
     let msgFollowupTo = msgCompFields.followupTo;
     let havePrimaryRecipient = false;
     if (msgReplyTo)
       awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgReplyTo, false, {}),
                                   "addr_reply", newListBoxNode, templateNode);
     if (msgTo)
     {
@@ -221,18 +221,16 @@ function CompFields2Recipients(msgCompFi
       }
     }
     if (msgCC)
       awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgCC, false, {}),
                                   "addr_cc", newListBoxNode, templateNode);
     if (msgBCC)
       awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgBCC, false, {}),
                                   "addr_bcc", newListBoxNode, templateNode);
-    if (msgRandomHeaders)
-      awSetInputAndPopup(msgRandomHeaders, "addr_other", newListBoxNode, templateNode);
     if (msgNewsgroups)
     {
       awSetInputAndPopup(msgNewsgroups, "addr_newsgroups", newListBoxNode, templateNode);
       havePrimaryRecipient = true;
     }
     if (msgFollowupTo)
       awSetInputAndPopup(msgFollowupTo, "addr_followup", newListBoxNode, templateNode);
 
--- a/mailnews/compose/public/nsIMsgCompFields.idl
+++ b/mailnews/compose/public/nsIMsgCompFields.idl
@@ -6,17 +6,17 @@
 #include "msgIStructuredHeaders.idl"
 
 interface nsIMsgAttachment;
 interface nsISimpleEnumerator;
 
 /**
  * A collection of headers and other attributes for building a mail message.
  */
-[scriptable, uuid(095fd3b3-41e1-448e-8f9a-534a5f8e5407)]
+[scriptable, uuid(4d251187-8213-467a-90f7-f8f330f59085)]
 interface nsIMsgCompFields : msgIWritableStructuredHeaders {
 
   attribute AString from;
   attribute AString replyTo;
   attribute AString to;
   attribute AString cc;
   attribute AString bcc;
   readonly attribute bool hasRecipients;
@@ -46,18 +46,16 @@ interface nsIMsgCompFields : msgIWritabl
   attribute boolean attachVCard;
   attribute boolean forcePlainText;
   attribute boolean useMultipartAlternative;
   attribute boolean bodyIsAsciiOnly;
   attribute boolean forceMsgEncoding;
   /// Status of manually-activated attachment reminder.
   attribute boolean attachmentReminder;
 
-  attribute AString otherRandomHeaders;
-
   /**
    * Beware that when setting this property, your body must be properly wrapped,
    * and the line endings must match MSG_LINEBREAK, namely "\r\n" on Windows
    * and "\n" on Linux and OSX.
    */
   attribute AString body;
 
   readonly attribute nsISimpleEnumerator attachments;
--- a/mailnews/compose/src/nsMsgCompFields.cpp
+++ b/mailnews/compose/src/nsMsgCompFields.cpp
@@ -38,17 +38,16 @@ static HeaderInfo kHeaders[] = {
   { "Bcc", true },
   { nullptr, false },
   { nullptr, false },
   { "Newsgroups", true },
   { "Followup-To", true },
   { "Subject", false },
   { "Organization", false },
   { "References", true },
-  { nullptr, false },
   { "X-Mozilla-News-Host", false },
   { "X-Priority", false },
   { nullptr, false },
   { "Message-Id", true },
   { "X-Template", true },
   { nullptr, false }
 };
 
@@ -275,26 +274,16 @@ NS_IMETHODIMP nsMsgCompFields::SetRefere
 }
 
 NS_IMETHODIMP nsMsgCompFields::GetReferences(char **_retval)
 {
   *_retval = strdup(GetAsciiHeader(MSG_REFERENCES_HEADER_ID));
   return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
-NS_IMETHODIMP nsMsgCompFields::SetOtherRandomHeaders(const nsAString &value)
-{
-  return SetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value);
-}
-
-NS_IMETHODIMP nsMsgCompFields::GetOtherRandomHeaders(nsAString &_retval)
-{
-  return GetUnicodeHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, _retval);
-}
-
 NS_IMETHODIMP nsMsgCompFields::SetNewspostUrl(const char *value)
 {
   return SetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID, value);
 }
 
 NS_IMETHODIMP nsMsgCompFields::GetNewspostUrl(char **_retval)
 {
   *_retval = strdup(GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID));
--- a/mailnews/compose/src/nsMsgCompFields.h
+++ b/mailnews/compose/src/nsMsgCompFields.h
@@ -46,17 +46,16 @@ public:
     MSG_BCC_HEADER_ID,
     MSG_FCC_HEADER_ID,
     MSG_FCC2_HEADER_ID,
     MSG_NEWSGROUPS_HEADER_ID,
     MSG_FOLLOWUP_TO_HEADER_ID,
     MSG_SUBJECT_HEADER_ID,
     MSG_ORGANIZATION_HEADER_ID,
     MSG_REFERENCES_HEADER_ID,
-    MSG_OTHERRANDOMHEADERS_HEADER_ID,
     MSG_NEWSPOSTURL_HEADER_ID,
     MSG_PRIORITY_HEADER_ID,
     MSG_CHARACTER_SET_HEADER_ID,
     MSG_MESSAGE_ID_HEADER_ID,
     MSG_X_TEMPLATE_HEADER_ID,
     MSG_DRAFT_ID_HEADER_ID,
 
     MSG_MAX_HEADERS   //Must be the last one.
@@ -104,19 +103,16 @@ public:
   nsresult SetSubject(const char *value) {return SetAsciiHeader(MSG_SUBJECT_HEADER_ID, value);}
   const char* GetSubject() {return GetAsciiHeader(MSG_SUBJECT_HEADER_ID);}
 
   nsresult SetOrganization(const char *value) {return SetAsciiHeader(MSG_ORGANIZATION_HEADER_ID, value);}
   const char* GetOrganization() {return GetAsciiHeader(MSG_ORGANIZATION_HEADER_ID);}
 
   const char* GetReferences() {return GetAsciiHeader(MSG_REFERENCES_HEADER_ID);}
 
-  nsresult SetOtherRandomHeaders(const char *value) {return SetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID, value);}
-  const char* GetOtherRandomHeaders() {return GetAsciiHeader(MSG_OTHERRANDOMHEADERS_HEADER_ID);}
-
   const char* GetNewspostUrl() {return GetAsciiHeader(MSG_NEWSPOSTURL_HEADER_ID);}
 
   const char* GetPriority() {return GetAsciiHeader(MSG_PRIORITY_HEADER_ID);}
 
   const char* GetCharacterSet() {return GetAsciiHeader(MSG_CHARACTER_SET_HEADER_ID);}
 
   const char* GetMessageId() {return GetAsciiHeader(MSG_MESSAGE_ID_HEADER_ID);}
 
--- a/mailnews/compose/src/nsMsgCompUtils.cpp
+++ b/mailnews/compose/src/nsMsgCompUtils.cpp
@@ -293,17 +293,16 @@ mime_generate_headers (nsMsgCompFields *
   const char* pMessageID;
   const char* pReplyTo;
   const char* pOrg;
   const char* pNewsGrp;
   const char* pFollow;
   const char* pSubject;
   const char* pPriority;
   const char* pReference;
-  const char* pOtherHdr;
   char *convbuf;
 
   bool hasDisclosedRecipient = false;
 
   nsAutoCString headerBuf;    // accumulate header strings to get length
   headerBuf.Truncate();
 
   NS_ASSERTION (fields, "null fields");
@@ -327,17 +326,16 @@ mime_generate_headers (nsMsgCompFields *
   pFollow= fields->GetFollowupTo(); if (pFollow)        size += 3 * PL_strlen (pFollow);
   pSubject = fields->GetSubject();
   if (pSubject)
     headerBuf.Append(pSubject);
   pReference = fields->GetReferences(); if (pReference)   size += 3 * PL_strlen (pReference);
   pOrg= fields->GetOrganization();
   if (pOrg)
     headerBuf.Append(pOrg);
-  pOtherHdr= fields->GetOtherRandomHeaders(); if (pOtherHdr)  size += 3 * PL_strlen (pOtherHdr);
   pPriority = fields->GetPriority();  if (pPriority)      size += 3 * PL_strlen (pPriority);
   pMessageID = fields->GetMessageId(); if (pMessageID)    size += PL_strlen (pMessageID);
 
   /* Multiply by 3 here to make enough room for MimePartII conversion */
   size += 3 * headerBuf.Length();
 
   /* Add a bunch of slop for the static parts of the headers. */
   /* size += 2048; */
@@ -729,22 +727,16 @@ mime_generate_headers (nsMsgCompFields *
       if (lastRef) {
         PUSH_STRING ("In-Reply-To: ");
         PUSH_STRING (lastRef);
         PUSH_NEWLINE ();
       }
     }
   }
 
-  if (pOtherHdr && *pOtherHdr) {
-    /* Assume they already have the right newlines and continuations
-     and so on.  for these headers, the PUSH_NEWLINE() happens in addressingWidgetOverlay.js */
-    PUSH_STRING (pOtherHdr);
-  }
-
   // Convert the blocks of headers into a single string for emission.
   nsCString headerText;
   headerText.Adopt(buffer);
   nsCString moreHeaders;
   finalHeaders->BuildMimeText(moreHeaders);
   headerText += moreHeaders;
 
   return ToNewCString(headerText);
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -2797,20 +2797,16 @@ nsMsgComposeAndSend::InitCompositionFiel
       NS_ENSURE_SUCCESS(rv, rv);
 
       nsCOMPtr<nsIMsgAttachment> attachment = do_QueryInterface(element, &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       mCompFields->AddAttachment(attachment);
     }
   }
 
-  pStr = fields->GetOtherRandomHeaders();
-  if (pStr)
-    mCompFields->SetOtherRandomHeaders((char *) pStr);
-
   AddDefaultCustomHeaders();
 
   AddMailFollowupToHeader();
   AddMailReplyToHeader();
 
   if (aType == nsIMsgCompType::ForwardInline ||
       aType == nsIMsgCompType::ForwardAsAttachment)
     AddXForwardedMessageIdHeader();
--- a/mailnews/compose/test/unit/test_messageHeaders.js
+++ b/mailnews/compose/test/unit/test_messageHeaders.js
@@ -195,17 +195,17 @@ function* testDraftInfo() {
 }
 
 function* testOtherHeaders() {
   let fields = new CompFields();
   let identity = getSmtpIdentity("from@tinderbox.invalid",
     getBasicSmtpServer());
   fields.priority = "high";
   fields.references = "<fake@tinderbox.invalid> <more@test.invalid>";
-  fields.otherRandomHeaders = "X-Fake-Header: 124\r\n";
+  fields.setHeader("X-Fake-Header", "124");
   let before = Date.now();
   let msgHdr = yield richCreateMessage(fields, [], identity);
   let after = Date.now();
   let msgData = mailTestUtils.loadMessageToString(msgHdr.folder, msgHdr);
   checkMessageHeaders(msgData, {
     "Mime-Version": "1.0",
     "User-Agent":  Cc["@mozilla.org/network/protocol;1?name=http"]
                      .getService(Ci.nsIHttpProtocolHandler).userAgent,
--- a/mailnews/mime/src/mimedrft.cpp
+++ b/mailnews/mime/src/mimedrft.cpp
@@ -322,17 +322,16 @@ CreateCompositionFields(const char      
                         const char        *cc,
                         const char        *bcc,
                         const char        *fcc,
                         const char        *newsgroups,
                         const char        *followup_to,
                         const char        *organization,
                         const char        *subject,
                         const char        *references,
-                        const char        *other_random_headers,
                         const char        *priority,
                         const char        *newspost_url,
                         char              *charset,
                         nsIMsgCompFields  **_retval)
 {
   NS_ENSURE_ARG_POINTER(_retval);
 
   nsresult rv;
@@ -400,21 +399,16 @@ CreateCompositionFields(const char      
     cFields->SetOrganization(NS_ConvertUTF8toUTF16(!val.IsEmpty() ? val.get() : organization));
   }
 
   if (references) {
     MIME_DecodeMimeHeader(references, charset, false, true, val);
     cFields->SetReferences(!val.IsEmpty() ? val.get() : references);
   }
 
-  if (other_random_headers) {
-    MIME_DecodeMimeHeader(other_random_headers, charset, false, true, val);
-    cFields->SetOtherRandomHeaders(NS_ConvertUTF8toUTF16(!val.IsEmpty() ? val.get() : other_random_headers));
-  }
-
   if (priority) {
     MIME_DecodeMimeHeader(priority, charset, false, true, val);
     nsMsgPriorityValue priorityValue;
     NS_MsgGetPriorityFromString(!val.IsEmpty() ? val.get() : priority, priorityValue);
     nsAutoCString priorityName;
     NS_MsgGetUntranslatedPriorityName(priorityValue, priorityName);
     cFields->SetPriority(priorityName.get());
   }
@@ -1238,17 +1232,17 @@ mime_parse_stream_complete (nsMIMESessio
         {
           news_host = PR_smprintf ("news://%s", host);
         }
       }
     }
 
 
     CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll,
-      org, subj, refs, 0, priority, news_host,
+      org, subj, refs, priority, news_host,
       mdd->mailcharset,
       getter_AddRefs(fields));
 
     draftInfo = MimeHeaders_get(mdd->headers, HEADER_X_MOZILLA_DRAFT_INFO, false, false);
     if (draftInfo && fields && !forward_inline)
     {
       char *parm = 0;
       parm = MimeHeaders_get_parameter(draftInfo, "vcard", NULL, NULL);
@@ -1524,17 +1518,17 @@ mime_parse_stream_complete (nsMIMESessio
           CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::Draft, nsIMsgCompFormat::Default, mdd->identity, nullptr, mdd->origMsgHdr);
         }
       }
     }
   }
   else
   {
     CreateCompositionFields( from, repl, to, cc, bcc, fcc, grps, foll,
-      org, subj, refs, 0, priority, news_host,
+      org, subj, refs, priority, news_host,
       mdd->mailcharset,
       getter_AddRefs(fields));
     if (fields)
       CreateTheComposeWindow(fields, newAttachData, nsIMsgCompType::New, nsIMsgCompFormat::Default, mdd->identity, nullptr, mdd->origMsgHdr);
   }
 
   if ( mdd->headers )
     MimeHeaders_free ( mdd->headers );
--- a/suite/mailnews/compose/addressingWidgetOverlay.js
+++ b/suite/mailnews/compose/addressingWidgetOverlay.js
@@ -77,17 +77,16 @@ function Recipients2CompFields(msgCompFi
   {
     var i = 1;
     var addrTo = "";
     var addrCc = "";
     var addrBcc = "";
     var addrReply = "";
     var addrNg = "";
     var addrFollow = "";
-    var addrOther = "";
     var to_Sep = "";
     var cc_Sep = "";
     var bcc_Sep = "";
     var reply_Sep = "";
     var ng_Sep = "";
     var follow_Sep = "";
 
     gMimeHeaderParser = Components.classes["@mozilla.org/messenger/headerparser;1"].getService(Components.interfaces.nsIMsgHeaderParser);
@@ -124,31 +123,32 @@ function Recipients2CompFields(msgCompFi
         switch (recipientType)
         {
           case "addr_to"          : addrTo += to_Sep + recipient; to_Sep = ",";               break;
           case "addr_cc"          : addrCc += cc_Sep + recipient; cc_Sep = ",";               break;
           case "addr_bcc"         : addrBcc += bcc_Sep + recipient; bcc_Sep = ",";            break;
           case "addr_reply"       : addrReply += reply_Sep + recipient; reply_Sep = ",";      break; 
           case "addr_newsgroups"  : addrNg += ng_Sep + fieldValue; ng_Sep = ",";              break;
           case "addr_followup"    : addrFollow += follow_Sep + fieldValue; follow_Sep = ",";  break;
-          // do CRLF, same as PUSH_NEWLINE() in nsMsgSend.h / nsMsgCompUtils.cpp
-          // see bug #195965
-          case "addr_other"       : addrOther += awGetPopupElement(i).selectedItem.getAttribute("label") + " " + fieldValue + "\r\n";break;
+          case "addr_other":
+            let headerName = awGetPopupElement(i).selectedItem.getAttribute("label");
+            headerName = headerName.substring(0, headerName.indexOf(':'));
+            msgCompFields.setHeader(headerName, fieldValue);
+            break;
         }
       }
       i ++;
     }
 
     msgCompFields.to = addrTo;
     msgCompFields.cc = addrCc;
     msgCompFields.bcc = addrBcc;
     msgCompFields.replyTo = addrReply;
     msgCompFields.newsgroups = addrNg;
     msgCompFields.followupTo = addrFollow;
-    msgCompFields.otherRandomHeaders = addrOther;
 
     gMimeHeaderParser = null;
   }
   else
     dump("Message Compose Error: msgCompFields is null (ExtractRecipients)");
 }
 
 function CompFields2Recipients(msgCompFields)
@@ -162,17 +162,16 @@ function CompFields2Recipients(msgCompFi
     // dump("replacing child in comp fields 2 recips \n");
     listbox.parentNode.replaceChild(newListBoxNode, listbox);
     
     top.MAX_RECIPIENTS = 0;
     var msgReplyTo = msgCompFields.replyTo;
     var msgTo = msgCompFields.to;
     var msgCC = msgCompFields.cc;
     var msgBCC = msgCompFields.bcc;
-    var msgRandomHeaders = msgCompFields.otherRandomHeaders;
     var msgNewsgroups = msgCompFields.newsgroups;
     var msgFollowupTo = msgCompFields.followupTo;
     var havePrimaryRecipient = false;
     if(msgReplyTo)
       awSetInputAndPopupFromArray(msgCompFields.splitRecipients(msgReplyTo, false, {}),
                                   "addr_reply", newListBoxNode, templateNode);
     if(msgTo)
     {