Bug 717429 - Decode subject for attachment file in message/rfc822 mail. r=dbienvenu
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Wed, 29 Feb 2012 20:15:02 -0500
changeset 10969 5171fff86520088e139bf9f44b3f56df30ae475b
parent 10968 7bb995ee9fa3d28c6009d344f69f8a8d43d0e50d
child 10970 3de041a65fc1da3db05a9523f6e6c5a7d2da5149
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbienvenu
bugs717429
Bug 717429 - Decode subject for attachment file in message/rfc822 mail. r=dbienvenu
mailnews/mime/src/mimemoz2.cpp
mailnews/mime/test/unit/test_message_attachment.js
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -266,31 +266,16 @@ ValidateRealName(nsMsgAttachmentData *aA
     return;
 
   // Internal MIME structures need not be named!
   if (aAttach->m_realType.IsEmpty() ||
       StringBeginsWith(aAttach->m_realType, NS_LITERAL_CSTRING("multipart"),
                        nsCaseInsensitiveCStringComparator()))
     return;
 
-  // Special case...if this is a enclosed RFC822 message, give it a nice
-  // name.
-  if (aAttach->m_realType.LowerCaseEqualsLiteral(MESSAGE_RFC822))
-  {
-    NS_ASSERTION(aHdrs, "How comes the object's headers is null!");
-    if (aHdrs && aHdrs->munged_subject)
-    {
-      aAttach->m_realName.Assign(aHdrs->munged_subject);
-      aAttach->m_realName.Append(".eml");
-    }
-    else
-      aAttach->m_realName = "ForwardedMessage.eml";
-    return;
-  }
-
   //
   // Now validate any other name we have for the attachment!
   //
   if (aAttach->m_realName.IsEmpty())
   {
     aAttach->m_realName = "attachment";
     nsresult rv = NS_OK;
     nsCAutoString contentType (aAttach->m_realType);
@@ -491,17 +476,31 @@ GenerateAttachmentData(MimeObject *objec
       urlString.Append(tmp->m_realName);
     if (tmp->m_realType.EqualsLiteral("message/rfc822") &&
            !StringEndsWith(urlString, NS_LITERAL_CSTRING(".eml"), nsCaseInsensitiveCStringComparator()))
       urlString.Append(".eml");
   } else if (tmp->m_isExternalAttachment) {
     // Allows the JS mime emitter to figure out the part information.
     urlString.Append("?part=");
     urlString.Append(part);
+  } else if (tmp->m_realType.LowerCaseEqualsLiteral(MESSAGE_RFC822)) {
+    // Special case...if this is a enclosed RFC822 message, give it a nice
+    // name.
+    if (object->headers->munged_subject)
+    {
+      nsCString subject;
+      subject.Assign(object->headers->munged_subject);
+      MimeHeaders_convert_header_value(options, subject, false);
+      tmp->m_realName.Assign(subject);
+      tmp->m_realName.Append(".eml");
+    }
+    else
+      tmp->m_realName = "ForwardedMessage.eml";
   }
+
   nsresult rv = nsMimeNewURI(getter_AddRefs(tmp->m_url), urlString.get(), nsnull);
 
   PR_FREEIF(urlSpec);
 
   if (NS_FAILED(rv) || !tmp->m_url)
     return NS_ERROR_OUT_OF_MEMORY;
 
   ValidateRealName(tmp, object->headers);
--- a/mailnews/mime/test/unit/test_message_attachment.js
+++ b/mailnews/mime/test/unit/test_message_attachment.js
@@ -70,16 +70,25 @@ let messages = [
   // named email attachment
   { attachments: [{ body: textAttachment,
                     filename: 'test.txt',
                     format: '' },
                   { body: '',
                     filename: 'Attached Message',
                     contentType: 'message/rfc822', },
                  ]},
+  // no named email attachment with subject header
+  { attachments: [{ expectedFilename: 'testSubject.eml' }],
+    bodyPart: new SyntheticPartMultiMixed([
+      new SyntheticPartLeaf('plain body text'),
+      msgGen.makeMessage({
+        subject: '=?UTF-8?B?dGVzdFN1YmplY3Q?=', // This string is 'testSubject'.
+        charset: 'UTF-8',
+      }),
+    ])},
 ];
 
 
 let gStreamListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener]),
 
   index: 0, // The index of the message we're currently looking at.