Bug 701261 - Emails with body as "attachment" appear blank with no option to save attachment, and is shown as attachment by Forward; r=bienvenu, a=standard8
authorJim Porter <squibblyflabbetydoo@gmail.com>
Tue, 06 Dec 2011 21:55:03 -0600
changeset 9393 dd915d6cd71da36f5365b5a2ee892d9f782255a5
parent 9392 afdd55bc88bdb0f4b2da3ac2e35920cd4ff66b6a
child 9394 7b09fc4f9f86dac8adf815360b1cf035fa08e4b8
push id265
push usersquibblyflabbetydoo@gmail.com
push dateWed, 07 Dec 2011 03:55:36 +0000
treeherdercomm-beta@dd915d6cd71d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu, standard8
bugs701261
Bug 701261 - Emails with body as "attachment" appear blank with no option to save attachment, and is shown as attachment by Forward; r=bienvenu, a=standard8
mailnews/mime/src/mimemoz2.cpp
mailnews/mime/test/unit/test_attachment_size.js
--- a/mailnews/mime/src/mimemoz2.cpp
+++ b/mailnews/mime/src/mimemoz2.cpp
@@ -119,21 +119,21 @@ MimeObject    *mime_get_main_object(Mime
 nsresult
 ProcessBodyAsAttachment(MimeObject *obj, nsMsgAttachmentData **data)
 {
   nsMsgAttachmentData   *tmp;
   PRInt32               n;
   char                  *disp = nsnull;
   char                  *charset = nsnull;
 
-  // Ok, this is the special case when somebody sends an "attachment" as the body
-  // of an RFC822 message...I really don't think this is the way this should be done.
-  // I belive this should really be a multipart/mixed message with an empty body part,
-  // but what can ya do...our friends to the North seem to do this.
-  //
+  // Ok, this is the special case when somebody sends an "attachment" as the
+  // body of an RFC822 message...I really don't think this is the way this
+  // should be done.  I belive this should really be a multipart/mixed message
+  // with an empty body part, but what can ya do...our friends to the North seem
+  // to do this.
   MimeObject    *child = obj;
 
   n = 1;
   *data = new nsMsgAttachmentData[2];
   if (!*data)
     return NS_ERROR_OUT_OF_MEMORY;
 
   tmp = *data;
@@ -149,29 +149,33 @@ ProcessBodyAsAttachment(MimeObject *obj,
     if (fname)
       tmp->m_realName.Adopt(fname);
   }
   else
   {
     tmp->m_realName.Adopt(MimeHeaders_get_name(child->headers, obj->options));
   }
 
+  tmp->m_hasFilename = !tmp->m_realName.IsEmpty();
+
   if (tmp->m_realName.IsEmpty() &&
       StringBeginsWith(tmp->m_realType, NS_LITERAL_CSTRING("text"),
                        nsCaseInsensitiveCStringComparator()))
     ValidateRealName(tmp, child->headers);
 
   char  *tmpURL = nsnull;
   char  *id = nsnull;
   char  *id_imap = nsnull;
 
   id = mime_part_address (obj);
   if (obj->options->missing_parts)
     id_imap = mime_imap_part_address (obj);
 
+  tmp->m_isDownloaded = !id_imap;
+
   if (! id)
   {
     PR_FREEIF(*data);
     PR_FREEIF(id_imap);
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
   if (obj->options && obj->options->url)
@@ -198,16 +202,20 @@ ProcessBodyAsAttachment(MimeObject *obj,
       PR_FREEIF(id_imap);
       return NS_ERROR_OUT_OF_MEMORY;
     }
   }
   PR_FREEIF(id);
   PR_FREEIF(id_imap);
   PR_FREEIF(tmpURL);
   tmp->m_description.Adopt(MimeHeaders_get(child->headers, HEADER_CONTENT_DESCRIPTION, PR_FALSE, PR_FALSE));
+
+  tmp->m_size = 0;
+  MimeGetSize(child, &tmp->m_size);
+
   return NS_OK;
 }
 
 PRInt32
 CountTotalMimeAttachments(MimeContainer *aObj)
 {
   PRInt32     i;
   PRInt32     rc = 0;
@@ -342,17 +350,17 @@ GenerateAttachmentData(MimeObject *objec
   nsMsgAttachmentData *tmp = &(aAttachData[attIndex++]);
 
   tmp->m_realType = object->content_type;
   tmp->m_realEncoding = object->encoding;
   tmp->m_isExternalAttachment = isExternalAttachment;
   tmp->m_size = attSize;
 
   char *part_addr = mime_imap_part_address(object);
-  tmp->m_isDownloaded = (part_addr == nsnull);
+  tmp->m_isDownloaded = !part_addr;
   PR_FREEIF(part_addr);
 
   PRInt32 i;
   char *charset = nsnull;
   char *disp = MimeHeaders_get(object->headers, HEADER_CONTENT_DISPOSITION, PR_FALSE, PR_FALSE);
   if (disp)
   {
     tmp->m_realName.Adopt(MimeHeaders_get_parameter(disp, "filename", &charset, nsnull));
@@ -428,29 +436,29 @@ GenerateAttachmentData(MimeObject *objec
   tmp->m_description.Adopt(MimeHeaders_get(object->headers, HEADER_CONTENT_DESCRIPTION,
                                            PR_FALSE, PR_FALSE));
 
   // Now, do the right thing with the name!
   if (tmp->m_realName.IsEmpty() && !(tmp->m_realType.LowerCaseEqualsLiteral(MESSAGE_RFC822)))
   {
     // Keep in mind that the name was provided by us and this is probably not a
     // real attachment.
-    tmp->m_hasFilename = PR_FALSE;
+    tmp->m_hasFilename = false;
     /* If this attachment doesn't have a name, just give it one... */
     tmp->m_realName.Adopt(MimeGetStringByID(MIME_MSG_DEFAULT_ATTACHMENT_NAME));
     if (!tmp->m_realName.IsEmpty())
     {
       char *newName = PR_smprintf(tmp->m_realName.get(), part.get());
       if (newName)
         tmp->m_realName.Adopt(newName);
     }
     else
       tmp->m_realName.Adopt(mime_part_address(object));
   } else {
-    tmp->m_hasFilename = PR_TRUE;
+    tmp->m_hasFilename = true;
   }
   nsCString urlString(urlSpec);
 
   if (!tmp->m_realName.IsEmpty() && !tmp->m_isExternalAttachment)
   {
     urlString.Append("&filename=");
     nsCAutoString aResult;
     if (NS_SUCCEEDED(MsgEscapeString(tmp->m_realName,
--- a/mailnews/mime/test/unit/test_attachment_size.js
+++ b/mailnews/mime/test/unit/test_attachment_size.js
@@ -172,17 +172,22 @@ let messages = [
                            attachments: [{ body: imageAttachment,
                             contentType: 'application/x-ubik',
                             filename: 'ubik',
                             encoding: 'base64',
                             format: '' }] }),
     ]),
     size: textAttachment.length + imageSize,
   },
-  ];
+  // an "attachment" that's really the body of the message
+  { body: { body: textAttachment,
+            contentType: 'application/x-ubik; name=attachment.ubik' },
+    size: textAttachment.length,
+  },
+];
 
 
 let gStreamListener = {
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIStreamListener]),
 
   // nsIRequestObserver part
   onStartRequest: function (aRequest, aContext) {
     // We reset the size here because we know that we only expect one attachment