Bug 405063 - When "Reply with Template" is executed for mail with "From: <>", yields error: "Sending of Message Failed". r=rkent a=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 19 Jan 2016 22:01:18 +0200
changeset 26662 88fa01d8bda40c815ea5748215e7baa7d488e168
parent 26661 e943c9d1dffaa83cca9a649f4069f3a49fd70a9f
child 26663 ddc209117ac2f807b253a41921352182bcef3afe
push id1850
push userclokep@gmail.com
push dateWed, 08 Mar 2017 19:29:12 +0000
treeherdercomm-esr52@028df196b2d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrkent, jorgk
bugs405063
Bug 405063 - When "Reply with Template" is executed for mail with "From: <>", yields error: "Sending of Message Failed". r=rkent a=jorgk
mailnews/compose/src/nsMsgComposeService.cpp
mailnews/compose/test/unit/test_autoReply.js
mailnews/test/data/mail-without-from
--- a/mailnews/compose/src/nsMsgComposeService.cpp
+++ b/mailnews/compose/src/nsMsgComposeService.cpp
@@ -1127,16 +1127,23 @@ NS_IMETHODIMP nsMsgComposeService::Reply
     return NS_ERROR_OUT_OF_MEMORY;
 
   NS_ADDREF(helper);
 
   helper->mHdrToReplyTo = aMsgHdr;
   helper->mMsgWindow = aMsgWindow;
   helper->mIdentity = identity;
 
+  nsAutoCString replyTo;
+  aMsgHdr->GetStringProperty("replyTo", getter_Copies(replyTo));
+  if (replyTo.IsEmpty())
+    aMsgHdr->GetAuthor(getter_Copies(replyTo));
+  if (replyTo.IsEmpty())
+    return NS_ERROR_FAILURE; // nowhere to send the reply
+
   nsCOMPtr <nsIMsgFolder> templateFolder;
   nsCOMPtr <nsIMsgDatabase> templateDB;
   nsCString templateMsgHdrUri;
   const char * query = PL_strstr(templateUri, "?messageId=");
   if (!query)
     return NS_ERROR_FAILURE;
 
   nsAutoCString folderUri(Substring(templateUri, query)); 
--- a/mailnews/compose/test/unit/test_autoReply.js
+++ b/mailnews/compose/test/unit/test_autoReply.js
@@ -14,16 +14,18 @@ Components.utils.import("resource:///mod
 
 load("../../../resources/logHelper.js"); // watch for errors in the error console
 
 const kSender = "from@foo.invalid";
 
 var gIncomingMailFile = do_get_file("../../../data/bugmail10"); // mail to reply to
 // reply-filter-testmail: mail to reply to (but not really)
 var gIncomingMailFile2 = do_get_file("../../../data/reply-filter-testmail");
+// mail to reply to (but not really, no from)
+var gIncomingMailFile3 = do_get_file("../../../data/mail-without-from");
 var gTemplateMailFile = do_get_file("../../../data/draft1"); // template
 var gTemplateFolder;
 
 var gServer;
 
 function run_test() {
   localAccountUtils.loadLocalMailAccount();
   gTemplateFolder = localAccountUtils.rootFolder
@@ -48,16 +50,25 @@ add_task(function* copy_gIncomingMailFil
   let promiseCopyListener = new PromiseTestUtils.PromiseCopyListener();
   // Copy gIncomingMailFile2 into the Inbox.
   MailServices.copy.CopyFileMessage(gIncomingMailFile2,
     localAccountUtils.inboxFolder, null, false, 0, "",
     promiseCopyListener, null);
   yield promiseCopyListener.promise;
 });
 
+add_task(function* copy_gIncomingMailFile3() {
+  let promiseCopyListener = new PromiseTestUtils.PromiseCopyListener();
+  // Copy gIncomingMailFile3 into the Inbox.
+  MailServices.copy.CopyFileMessage(gIncomingMailFile3,
+    localAccountUtils.inboxFolder, null, false, 0, "",
+    promiseCopyListener, null);
+  yield promiseCopyListener.promise;
+});
+
 add_task(function* copy_gTemplateMailFile() {
   let promiseCopyListener = new PromiseTestUtils.PromiseCopyListener();
   // Copy gTemplateMailFile into the Templates folder.
   MailServices.copy.CopyFileMessage(gTemplateMailFile,
     gTemplateFolder, null, true, 0, "",
     promiseCopyListener, null);
   yield promiseCopyListener.promise;
 });
@@ -81,26 +92,39 @@ add_task(function testReplyingToAdressed
   try {
     testReply(1); // mail 1 is adressed to us
   }
   catch (e) {
     do_throw("Didn't reply to a message addressed to us! "  + e);
   }
 });
 
+/// Test that a reply is NOT even tried when the message has no From.
+add_task(function testReplyingToMailWithNoFrom() {
+  try {
+    testReply(2); // mail 2 has no From
+    do_throw("Shouldn't even have tried to reply reply to the message " +
+             "with no From and no Reply-To");
+  }
+  catch (e) {
+    if (e.result != Components.results.NS_ERROR_FAILURE)
+      throw e;
+  }
+});
+
 /// Test reply with template.
 function testReply(aHrdIdx) {
   let smtpServer = getBasicSmtpServer();
   smtpServer.port = gServer.port;
 
   let identity = getSmtpIdentity(kSender, smtpServer);
   localAccountUtils.msgAccount.addIdentity(identity);
 
   let msgHdr = mailTestUtils.getMsgHdrN(localAccountUtils.inboxFolder, aHrdIdx);
-  do_print("Sender: " + kSender + ", msg #" + aHrdIdx + " recipients: " +
+  do_print("Msg#" + aHrdIdx +  " author=" + msgHdr.author + ", recipients=" +
            msgHdr.recipients);
   let templateHdr = mailTestUtils.getMsgHdrN(gTemplateFolder, 0);
 
   // See <method name="getTemplates"> in searchWidgets.xml
   let msgTemplateUri = gTemplateFolder.URI +
                        "?messageId=" + templateHdr.messageId +
                        "&subject=" + templateHdr.mime2DecodedSubject;
   MailServices.compose.replyWithTemplate(msgHdr, msgTemplateUri, null,
new file mode 100644
--- /dev/null
+++ b/mailnews/test/data/mail-without-from
@@ -0,0 +1,8 @@
+From - Sun Apr 26 21:30:59 2015
+Subject: mail with no from
+To: from@foo.invalid
+Content-Type: text/plain; charset="UTF-8"
+MIME-Version: 1.0
+
+This mail has no from address.
+