Bug 453196 - Supply proper message arguments. r=rkent a=jorgk
authorJorg K
Wed, 22 Jun 2016 10:14:53 +0200
changeset 27295 41cdfb1f9c8bbdb11bca0e21b915d078cab4c666
parent 27294 aca753894875474faf1ed646067caf0ba2f599d4
child 27296 7dcfc3353d0be19b6dc20973c1548f3516551510
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
bugs453196
Bug 453196 - Supply proper message arguments. r=rkent a=jorgk
mailnews/compose/src/nsMsgSend.cpp
mailnews/compose/test/unit/test_messageHeaders.js
--- a/mailnews/compose/src/nsMsgSend.cpp
+++ b/mailnews/compose/src/nsMsgSend.cpp
@@ -2505,18 +2505,27 @@ nsMsgComposeAndSend::HackAttachments(nsI
 
       //
       // This only returns a failure code if NET_GetURL was not called
       // (and thus no exit routine was or will be called.)
       //
 
       // Display some feedback to user...
       nsString msg;
+      nsAutoString attachmentFileName;
       NS_ConvertUTF8toUTF16 params(m_attachments[i]->m_realName);
-      const char16_t *formatParams[] = { params.get() };
+      const char16_t *formatParams[1];
+      if (!params.IsEmpty()) {
+        formatParams[0] = params.get();
+      } else if (m_attachments[i]->mURL) {
+        nsCString asciiSpec;
+        m_attachments[i]->mURL->GetAsciiSpec(asciiSpec);
+        attachmentFileName.AssignASCII(asciiSpec.get());
+        formatParams[0] = attachmentFileName.get();
+      }
       mComposeBundle->FormatStringFromName(MOZ_UTF16("gatheringAttachment"),
                                            formatParams, 1, getter_Copies(msg));
 
       if (!msg.IsEmpty())
       {
         SetStatusMessage(msg);
       }
 
@@ -2524,18 +2533,23 @@ nsMsgComposeAndSend::HackAttachments(nsI
          we need to avoid to call it ourself.
       */
       needToCallGatherMimeAttachments = false;
 
       nsresult status = m_attachments[i]->SnarfAttachment(mCompFields);
       if (NS_FAILED(status))
       {
         nsString errorMsg;
-        nsAutoString attachmentFileName;
         nsresult rv = ConvertToUnicode(nsMsgI18NFileSystemCharset(), m_attachments[i]->m_realName, attachmentFileName);
+        if (attachmentFileName.IsEmpty() && m_attachments[i]->mURL) {
+          nsCString asciiSpec;
+          m_attachments[i]->mURL->GetAsciiSpec(asciiSpec);
+          attachmentFileName.AssignASCII(asciiSpec.get());
+          rv = NS_OK;
+        }
         if (NS_SUCCEEDED(rv))
         {
           nsCOMPtr<nsIStringBundle> bundle;
           const char16_t *params[] = { attachmentFileName.get() };
           mComposeBundle->FormatStringFromName(MOZ_UTF16("errorAttachingFile"),
                                                params, 1,
                                                getter_Copies(errorMsg));
           mSendReport->SetMessage(nsIMsgSendReport::process_Current, errorMsg.get(), false);
--- a/mailnews/compose/test/unit/test_messageHeaders.js
+++ b/mailnews/compose/test/unit/test_messageHeaders.js
@@ -370,24 +370,24 @@ function* testContentHeaders() {
 
   plainAttachment.name = "\ud83d\udca9.txt";
   plainAttachmentHeaders["Content-Disposition"] =
     "attachment; filename*=UTF-8''%F0%9F%92%A9%2E%74%78%74";
   yield richCreateMessage(fields, [plainAttachment], identity);
   checkDraftHeaders(plainAttachmentHeaders, "2");
 
   let httpAttachment = makeAttachment({
-    url: "data:text/html,<html><body></body></html>",
+    url: "data:text/html,<html></html>",
     name: "attachment.html",
   });
   let httpAttachmentHeaders = {
     "Content-Type": "text/html",
     "Content-Disposition": "attachment; filename=\"attachment.html\"",
-    "Content-Base": '"data:text/html,<html><body></body></html>"',
-    "Content-Location": '"data:text/html,<html><body></body></html>"',
+    "Content-Base": '"data:text/html,<html></html>"',
+    "Content-Location": '"data:text/html,<html></html>"',
   };
   yield richCreateMessage(fields, [httpAttachment], identity);
   checkDraftHeaders({
     "Content-Base": undefined,
     "Content-Location": undefined
   }, "1");
   checkDraftHeaders(httpAttachmentHeaders, "2");