Bug 998191, part 3: Copy all MIME headers in nsMsgSend, r=irving
authorJoshua Cranmer <Pidgeot18@gmail.com>
Wed, 07 Jan 2015 15:57:39 -0600
changeset 21598 3b8fcc27ab8ac3b1c8711b08b98ccf38a6c7b089
parent 21597 67519bbca9702cfaa7f699b56c1f350673eebb14
child 21599 45ccfc058277e081883f440f1b0aa22be05652b6
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 3: Copy all MIME headers in nsMsgSend, r=irving
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/src/nsMsgSend.h
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -2624,55 +2624,16 @@ nsMsgComposeAndSend::HackAttachments(nsI
 
   // If no attachments - finish now (this will call the done_callback).
   if (needToCallGatherMimeAttachments)
     return GatherMimeAttachments();
 
   return NS_OK;
 }
 
-nsresult nsMsgComposeAndSend::SetMimeHeader(nsMsgCompFields::MsgHeaderID header, const char *value)
-{
-  char * dupHeader = nullptr;
-  nsresult ret = NS_ERROR_OUT_OF_MEMORY;
-
-  switch (header)
-  {
-    case nsMsgCompFields::MSG_FROM_HEADER_ID :
-    case nsMsgCompFields::MSG_TO_HEADER_ID :
-    case nsMsgCompFields::MSG_REPLY_TO_HEADER_ID :
-    case nsMsgCompFields::MSG_CC_HEADER_ID :
-    case nsMsgCompFields::MSG_BCC_HEADER_ID :
-      dupHeader = mime_fix_addr_header(value);
-      break;
-
-    case nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID :
-    case nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID :
-      dupHeader = mime_fix_news_header(value);
-      break;
-
-    case nsMsgCompFields::MSG_FCC_HEADER_ID :
-    case nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID :
-    case nsMsgCompFields::MSG_SUBJECT_HEADER_ID :
-    case nsMsgCompFields::MSG_REFERENCES_HEADER_ID :
-    case nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID :
-      dupHeader = mime_fix_header(value);
-      break;
-
-    default : NS_ASSERTION(false, "invalid header"); // unhandled header - bad boy.
-  }
-
-  if (dupHeader)
-  {
-    ret = mCompFields->SetAsciiHeader(header, dupHeader);
-    PR_Free(dupHeader);
-  }
-  return ret;
-}
-
 nsresult
 nsMsgComposeAndSend::InitCompositionFields(nsMsgCompFields *fields,
                                            const nsACString &aOriginalMsgURI,
                                            MSG_ComposeType aType)
 {
   nsresult        rv = NS_OK;
   const char      *pStr = nullptr;
 
@@ -2686,31 +2647,16 @@ nsMsgComposeAndSend::InitCompositionFiel
   {
     mCompFields->SetCharacterSet("UTF-8");
   }
   else
   {
     mCompFields->SetCharacterSet(fields->GetCharacterSet());
   }
 
-  pStr = fields->GetMessageId();
-  if (pStr)
-  {
-    mCompFields->SetMessageId((char *) pStr);
-    /* Don't bother checking for out of memory; if it fails, then we'll just
-       let the server generate the message-id, and suffer with the
-       possibility of duplicate messages.*/
-  }
-
-  pStr = fields->GetNewspostUrl();
-  if (pStr && *pStr)
-  {
-    mCompFields->SetNewspostUrl((char *)pStr);
-  }
-
   // Now, we will look for a URI defined as the default FCC pref. If this is set,
   // then SetFcc will use this value. The FCC field is a URI for the server that
   // will hold the "Sent" folder...the
   //
   // First, look at what was passed in via the "fields" structure...if that was
   // set then use it, otherwise, fall back to what is set in the prefs...
   //
   // But even before that, pay attention to the new OVERRIDE pref that will cancel
@@ -2737,17 +2683,17 @@ nsMsgComposeAndSend::InitCompositionFiel
       }
       else
       {
         nsCOMPtr<nsIMsgFolder> folder;
         GetExistingFolder(nsDependentCString(fieldsFCC), getter_AddRefs(folder));
         if (folder)
         {
           useDefaultFCC = false;
-          SetMimeHeader(nsMsgCompFields::MSG_FCC_HEADER_ID, fieldsFCC);
+          mCompFields->SetFcc(mime_fix_header(fieldsFCC));
         }
       }
     }
 
     // We use default FCC setting if it's not set or was set to an invalid folder.
     if (useDefaultFCC)
     {
       // Only check whether the user wants the message in the original message
@@ -2831,30 +2777,19 @@ nsMsgComposeAndSend::InitCompositionFiel
     }
     else
     {
       mCompFields->SetFcc2(fieldsFCC2);
       mNeedToPerformSecondFCC = true;
     }
   }
 
-  mCompFields->SetNewspostUrl((char *) fields->GetNewspostUrl());
-
-  /* strip whitespace from and duplicate header fields. */
-  SetMimeHeader(nsMsgCompFields::MSG_FROM_HEADER_ID, fields->GetFrom());
-  SetMimeHeader(nsMsgCompFields::MSG_REPLY_TO_HEADER_ID, fields->GetReplyTo());
-  SetMimeHeader(nsMsgCompFields::MSG_TO_HEADER_ID, fields->GetTo());
-  SetMimeHeader(nsMsgCompFields::MSG_CC_HEADER_ID, fields->GetCc());
-  SetMimeHeader(nsMsgCompFields::MSG_BCC_HEADER_ID, fields->GetBcc());
-  SetMimeHeader(nsMsgCompFields::MSG_NEWSGROUPS_HEADER_ID, fields->GetNewsgroups());
-  SetMimeHeader(nsMsgCompFields::MSG_FOLLOWUP_TO_HEADER_ID, fields->GetFollowupTo());
-  SetMimeHeader(nsMsgCompFields::MSG_ORGANIZATION_HEADER_ID, fields->GetOrganization());
-  SetMimeHeader(nsMsgCompFields::MSG_SUBJECT_HEADER_ID, fields->GetSubject());
-  SetMimeHeader(nsMsgCompFields::MSG_REFERENCES_HEADER_ID, fields->GetReferences());
-  SetMimeHeader(nsMsgCompFields::MSG_X_TEMPLATE_HEADER_ID, fields->GetTemplateName());
+  // Copy the main bodies of headers over.
+  rv = mCompFields->AddAllHeaders(fields);
+  NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsISimpleEnumerator> srcAttachments;
   fields->GetAttachments(getter_AddRefs(srcAttachments));
   if (srcAttachments)
   {
     bool moreAttachments;
     nsCOMPtr<nsISupports> element;
     while (NS_SUCCEEDED(srcAttachments->HasMoreElements(&moreAttachments)) && moreAttachments) {
--- a/mailnews/compose/src/nsMsgSend.h
+++ b/mailnews/compose/src/nsMsgSend.h
@@ -228,17 +228,16 @@ public:
 
   //
   // Setup the composition fields
   //
   nsresult    InitCompositionFields(nsMsgCompFields *fields,
                                     const nsACString &aOriginalMsgURI,
                                     MSG_ComposeType aType);
 
-  nsresult    SetMimeHeader(nsMsgCompFields::MsgHeaderID header, const char *value);
   NS_IMETHOD  GetBodyFromEditor();
 
 
   //
   // Attachment processing...
   //
   nsresult    HackAttachments(nsIArray *attachments,
                               nsIArray *preloaded_attachments);