Bug 544984 - Improve print format of attachment file names, esp. remove content-type and content-encoding. r=bienvenu
authorJim <squibblyflabbetydoo@gmail.com>
Fri, 10 Dec 2010 13:11:00 +0100
changeset 6859 9704a3548bdb
parent 6858 5ddf0094e105
child 6860 1dcc58a75dbb
push id5255
push userjh@junetz.de
push dateSat, 18 Dec 2010 23:28:24 +0000
treeherdercomm-central@9704a3548bdb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs544984
Bug 544984 - Improve print format of attachment file names, esp. remove content-type and content-encoding. r=bienvenu
mail/locales/en-US/chrome/messenger/messenger.properties
mail/themes/gnomestripe/mail/messageBody.css
mail/themes/pinstripe/mail/messageBody.css
mail/themes/qute/mail/messageBody.css
mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
mailnews/mime/src/mimei.cpp
suite/locales/en-US/chrome/mailnews/messenger.properties
suite/themes/classic/messenger/messageBody.css
suite/themes/modern/messenger/messageBody.css
--- a/mail/locales/en-US/chrome/messenger/messenger.properties
+++ b/mail/locales/en-US/chrome/messenger/messenger.properties
@@ -345,16 +345,19 @@ deleteAttachmentFailure=Failed to delete
 emptyAttachment=This attachment appears to be empty.\nPlease check with the person who sent this.\nOften company firewalls or antivirus programs will destroy attachments.
 
 # This is the format for prepending accesskeys to the
 # each of the attachments in the file|attachments menu:
 #   ie: 1 file.txt
 #       2 another file.txt
 attachmentDisplayNameFormat=%S %S
 
+# This is the heading for the attachment summary when printing an email
+attachmentsPrintHeader=Attachments:
+
 # Connection Error Messages
 101=Unknown Error 
 102=Failed to connect to server %S.
 103=Could not connect to server %S; the connection was refused.
 104=Connection to server %S timed out.
 
 recipientSearchCriteria=Subject or Recipient contains:
 fromSearchCriteria=Subject or From contains:
--- a/mail/themes/gnomestripe/mail/messageBody.css
+++ b/mail/themes/gnomestripe/mail/messageBody.css
@@ -164,18 +164,39 @@ body[selected="false"] {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   border: none;
 }
 
+/* Attachment display styling (for inline attachments and printing) */
 .mimeAttachmentHeader {
   border-style: none;
   border-top: 1px solid GrayText;
 }
 
-.mimeAttachmentName {
+.mimeAttachmentHeaderName {
   color: GrayText;
   font-size: 80%;
   font-family: Arial, sans-serif;
 }
+
+div.mimeAttachmentWrap {
+  padding: 0 1em;
+}
+
+table.mimeAttachmentTable {
+  width: 100%;
+  border-collapse: collapse;
+}
+
+table.mimeAttachmentTable tr + tr > td {
+  border-top: 1px solid GrayText;
+}
+
+.mimeAttachmentFile {
+}
+
+.mimeAttachmentSize {
+  text-align: right;
+}
--- a/mail/themes/pinstripe/mail/messageBody.css
+++ b/mail/themes/pinstripe/mail/messageBody.css
@@ -191,18 +191,39 @@ body[selected="false"] {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   border: none;
 }
 
+/* Attachment display styling (for inline attachments and printing) */
 .mimeAttachmentHeader {
   border-style: none;
-  border-top: 1px solid gray;
+  border-top: 1px solid GrayText;
 }
 
-.mimeAttachmentName {
+.mimeAttachmentHeaderName {
   color: GrayText;
   font-size: 80%;
   font-family: Arial, sans-serif;
 }
+
+div.mimeAttachmentWrap {
+  padding: 0 1em;
+}
+
+table.mimeAttachmentTable {
+  width: 100%;
+  border-collapse: collapse;
+}
+
+table.mimeAttachmentTable tr + tr > td {
+  border-top: 1px solid GrayText;
+}
+
+.mimeAttachmentFile {
+}
+
+.mimeAttachmentSize {
+  text-align: right;
+}
--- a/mail/themes/qute/mail/messageBody.css
+++ b/mail/themes/qute/mail/messageBody.css
@@ -160,18 +160,39 @@ body[selected="false"] {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   border: none;
 }
 
+/* Attachment display styling (for inline attachments and printing) */
 .mimeAttachmentHeader {
   border-style: none;
   border-top: 1px solid GrayText;
 }
 
-.mimeAttachmentName {
+.mimeAttachmentHeaderName {
   color: GrayText;
   font-size: 80%;
   font-family: Arial, sans-serif;
 }
+
+div.mimeAttachmentWrap {
+  padding: 0 1em;
+}
+
+table.mimeAttachmentTable {
+  width: 100%;
+  border-collapse: collapse;
+}
+
+table.mimeAttachmentTable tr + tr > td {
+  border-top: 1px solid GrayText;
+}
+
+.mimeAttachmentFile {
+}
+
+.mimeAttachmentSize {
+  text-align: right;
+}
--- a/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
+++ b/mailnews/mime/emitters/src/nsMimeHtmlEmitter.cpp
@@ -171,24 +171,24 @@ nsMimeHtmlDisplayEmitter::GetHeaderSink(
     if (uri)
     {
       nsCOMPtr<nsIMsgMailNewsUrl> msgurl (do_QueryInterface(uri));
       if (msgurl)
       {
         msgurl->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
         if (!mHeaderSink)  // if the url is not overriding the header sink, then just get the one from the msg window
         {
-        nsCOMPtr<nsIMsgWindow> msgWindow;
-        msgurl->GetMsgWindow(getter_AddRefs(msgWindow));
-        if (msgWindow)
-          msgWindow->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
+          nsCOMPtr<nsIMsgWindow> msgWindow;
+          msgurl->GetMsgWindow(getter_AddRefs(msgWindow));
+          if (msgWindow)
+            msgWindow->GetMsgHeaderSink(getter_AddRefs(mHeaderSink));
+        }
       }
     }
   }
-  }
 
   *aHeaderSink = mHeaderSink;
   NS_IF_ADDREF(*aHeaderSink);
   return rv;
 }
 
 nsresult nsMimeHtmlDisplayEmitter::BroadcastHeaders(nsIMsgHeaderSink * aHeaderSink, PRInt32 aHeaderMode, PRBool aFromNewsgroup)
 {
@@ -208,17 +208,16 @@ nsresult nsMimeHtmlDisplayEmitter::Broad
   {
     pPrefBranch->GetCharPref("mailnews.headers.extraExpandedHeaders", getter_Copies(extraExpandedHeaders));
     // todo - should make this upper case
     if (!extraExpandedHeaders.IsEmpty())
     {
       ToLowerCase(extraExpandedHeaders);
       ParseString(extraExpandedHeaders, ' ', extraExpandedHeadersArray);
     }
-
   }
 
   for (PRInt32 i=0; i<mHeaderArray->Count(); i++)
   {
     headerInfoType * headerInfo = (headerInfoType *) mHeaderArray->ElementAt(i);
     if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) || (!headerInfo->value) || (!(*headerInfo->value)))
       continue;
 
@@ -287,30 +286,30 @@ NS_IMETHODIMP nsMimeHtmlDisplayEmitter::
   {
     headerInfoType *headerInfo = (headerInfoType *)mHeaderArray->ElementAt(j);
     if (!(headerInfo && headerInfo->name && *headerInfo->name))
       continue;
 
     if (!PL_strcasecmp("Newsgroups", headerInfo->name))
     {
       bFromNewsgroups = PR_TRUE;
-    break;
+      break;
     }
   }
 
   // try to get a header sink if there is one....
   nsCOMPtr<nsIMsgHeaderSink> headerSink;
   nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
 
   if (headerSink)
   {
-  PRInt32 viewMode = 0;
-  nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
-  if (pPrefBranch)
-    rv = pPrefBranch->GetIntPref("mail.show_headers", &viewMode);
+    PRInt32 viewMode = 0;
+    nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
+    if (pPrefBranch)
+      rv = pPrefBranch->GetIntPref("mail.show_headers", &viewMode);
 
     rv = BroadcastHeaders(headerSink, viewMode, bFromNewsgroups);
   } // if header Sink
 
   return NS_OK;
 }
 
 nsresult
@@ -418,47 +417,58 @@ nsMimeHtmlDisplayEmitter::StartAttachmen
   mSkipAttachment = PR_FALSE;
 
   if ( (contentType) &&
        ((!strcmp(contentType, APPLICATION_XPKCS7_MIME)) ||
         (!strcmp(contentType, APPLICATION_PKCS7_MIME)) ||
         (!strcmp(contentType, APPLICATION_XPKCS7_SIGNATURE)) ||
         (!strcmp(contentType, APPLICATION_PKCS7_SIGNATURE)) ||
         (!strcmp(contentType, TEXT_VCARD)))
-     ) {
+     )
+  {
      mSkipAttachment = PR_TRUE;
      return NS_OK;
   }
 
-  if (!mFirst) {
+  if (mFirst)
+  {
     UtilityWrite("<br><fieldset class=\"mimeAttachmentHeader\">");
-    if (!name.IsEmpty()) {
-      UtilityWrite("<legend class=\"mimeAttachmentName\">");
-      UtilityWrite(name);
+    if (!name.IsEmpty())
+    {
+      nsresult rv;
+
+      nsCOMPtr<nsIStringBundleService> bundleSvc =
+        do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv);
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsCOMPtr<nsIStringBundle> bundle;
+      rv = bundleSvc->CreateBundle("chrome://messenger/locale/messenger.properties",
+                                   getter_AddRefs(bundle));
+      NS_ENSURE_SUCCESS(rv, rv);
+
+      nsString attachmentsHeader;
+      bundle->GetStringFromName(NS_LITERAL_STRING("attachmentsPrintHeader").get(),
+                                getter_Copies(attachmentsHeader)); 
+
+      UtilityWrite("<legend class=\"mimeAttachmentHeaderName\">");
+      UtilityWrite(NS_ConvertUTF16toUTF8(attachmentsHeader).get());
       UtilityWrite("</legend>");
     }
     UtilityWrite("</fieldset>");
+    UtilityWrite("<div class=\"mimeAttachmentWrap\">");
+    UtilityWrite("<table class=\"mimeAttachmentTable\">");
   }
 
+  UtilityWrite("<tr>");
+
+  UtilityWrite("<td class=\"mimeAttachmentFile\">");
+  UtilityWrite(name);
+  UtilityWrite("</td>");
+
   mFirst = PR_FALSE;
-
-  UtilityWrite("<center>");
-  UtilityWrite("<table border>");
-  UtilityWrite("<tr>");
-  UtilityWrite("<td>");
-
-  UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");
-
-  UtilityWrite(name);
-
-  UtilityWrite("</div>");
-
-  UtilityWrite("</td>");
-  UtilityWrite("<td>");
-  UtilityWrite("<table border=0>");
   return NS_OK;
 }
 
 nsresult
 nsMimeHtmlDisplayEmitter::AddAttachmentField(const char *field, const char *value)
 {
   if (mSkipAttachment)
     return NS_OK;
@@ -468,93 +478,87 @@ nsMimeHtmlDisplayEmitter::AddAttachmentF
     return NS_OK;
 
   // Don't output this ugly header...
   if (!strcmp(field, HEADER_X_MOZILLA_PART_URL))
     return NS_OK;
 
   nsCOMPtr<nsIMsgHeaderSink> headerSink;
   nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
-  if (NS_SUCCEEDED(rv) && headerSink) {
+  if (NS_SUCCEEDED(rv) && headerSink)
+  {
     headerSink->AddAttachmentField(field, value);
   }
-  else {
-    char  *newValue = MsgEscapeHTML(value);
-
-    UtilityWrite("<tr>");
-
-    UtilityWrite("<td>");
-    UtilityWrite("<div align=right class=\"headerdisplayname\" style=\"display:inline;\">");
+  else
+  {
+    // Currently, we only care about the part size.
+    if (strcmp(field, HEADER_X_MOZILLA_PART_SIZE))
+      return NS_OK;
 
-    UtilityWrite(field);
-    UtilityWrite(":");
-    UtilityWrite("</div>");
+    PRUint64 size = atoi(value);
+    nsAutoString sizeString;
+    rv = FormatFileSize(size, PR_FALSE, sizeString);
+    UtilityWrite("<td class=\"mimeAttachmentSize\">");
+    UtilityWrite(NS_ConvertUTF16toUTF8(sizeString).get());
     UtilityWrite("</td>");
-    UtilityWrite("<td>");
-
-    UtilityWrite(newValue);
-
-    UtilityWrite("</td>");
-    UtilityWrite("</tr>");
-
-    PR_Free(newValue);
   }
 
   return NS_OK;
 }
 
 nsresult
 nsMimeHtmlDisplayEmitter::EndAttachment()
 {
   if (mSkipAttachment)
     return NS_OK;
 
   mSkipAttachment = PR_FALSE; // reset it for next attachment round
 
   if (BroadCastHeadersAndAttachments())
     return NS_OK;
 
-  if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput) {
-    UtilityWrite("</table>");
-    UtilityWrite("</td>");
+  if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
     UtilityWrite("</tr>");
 
-    UtilityWrite("</table>");
-    UtilityWrite("</center>");
-    UtilityWrite("<br>");
-  }
   return NS_OK;
 }
 
 nsresult
 nsMimeHtmlDisplayEmitter::EndAllAttachments()
 {
   nsresult rv = NS_OK;
   nsCOMPtr<nsIMsgHeaderSink> headerSink;
   rv = GetHeaderSink(getter_AddRefs(headerSink));
   if (headerSink)
     headerSink->OnEndAllAttachments();
+
+  if (mFormat == nsMimeOutput::nsMimeMessagePrintOutput)
+  {
+    UtilityWrite("</table>");
+    UtilityWrite("</div>");
+  }
+
   return rv;
 }
 
 nsresult
 nsMimeHtmlDisplayEmitter::WriteBody(const nsACString &buf,
                                     PRUint32 *amountWritten)
 {
   Write(buf, amountWritten);
   return NS_OK;
 }
 
 nsresult
 nsMimeHtmlDisplayEmitter::EndBody()
 {
   if (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer)
   {
-  UtilityWriteCRLF("</body>");
-  UtilityWriteCRLF("</html>");
+    UtilityWriteCRLF("</body>");
+    UtilityWriteCRLF("</html>");
   }
   nsCOMPtr<nsIMsgHeaderSink> headerSink;
   nsresult rv = GetHeaderSink(getter_AddRefs(headerSink));
   nsCOMPtr<nsIMsgMailNewsUrl> mailnewsUrl (do_QueryInterface(mURL, &rv));
   if (headerSink)
     headerSink->OnEndMsgHeaders(mailnewsUrl);
 
   return NS_OK;
--- a/mailnews/mime/src/mimei.cpp
+++ b/mailnews/mime/src/mimei.cpp
@@ -1688,17 +1688,17 @@ MimeOptions_write(MimeDisplayOptions *op
       opt->state->separator_suppressed_p = PR_FALSE;
     else {
       const char *sep = "<BR><FIELDSET CLASS=\"mimeAttachmentHeader\">";
       int lstatus = opt->output_fn(sep, strlen(sep), closure);
       opt->state->separator_suppressed_p = PR_FALSE;
       if (lstatus < 0) return lstatus;
 
       if (!name.IsEmpty()) {
-          sep = "<LEGEND CLASS=\"mimeAttachmentName\">";
+          sep = "<LEGEND CLASS=\"mimeAttachmentHeaderName\">";
           lstatus = opt->output_fn(sep, strlen(sep), closure);
           opt->state->separator_suppressed_p = PR_FALSE;
           if (lstatus < 0) return lstatus;
 
           lstatus = opt->output_fn(name.get(), name.Length(), closure);
           opt->state->separator_suppressed_p = PR_FALSE;
           if (lstatus < 0) return lstatus;
 
--- a/suite/locales/en-US/chrome/mailnews/messenger.properties
+++ b/suite/locales/en-US/chrome/mailnews/messenger.properties
@@ -334,16 +334,19 @@ detachAttachments=The following attachme
 deleteAttachmentFailure=Failed to delete the selected attachments.
 
 # This is the format for prepending accesskeys to the
 # each of the attachments in the file|attachments menu:
 #   ie: 1 file.txt
 #       2 another file.txt
 attachmentDisplayNameFormat=%S %S
 
+# This is the heading for the attachment summary when printing an email
+attachmentsPrintHeader=Attachments:
+
 # Connection Error Messages
 101=Unknown Error 
 102=Failed to connect to server %S.
 103=Could not connect to server %S; the connection was refused.
 104=Connection to server %S timed out.
 
 # LOCALIZATION NOTE(biffNotification): %1$S is the number of new messages  
 biffNotification_message=has %1$S new message
--- a/suite/themes/classic/messenger/messageBody.css
+++ b/suite/themes/classic/messenger/messageBody.css
@@ -175,17 +175,38 @@ body[selected="false"] {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   border: none;
 }
 
+/* Attachment display styling (for inline attachments and printing) */
 .mimeAttachmentHeader {
   border-style: none;
   border-top: 1px solid gray;
 }
 
-.mimeAttachmentName {
+.mimeAttachmentHeaderName {
   color: gray;
   font-size: 80%;
 }
+
+div.mimeAttachmentWrap {
+  padding: 0 1em;
+}
+
+table.mimeAttachmentTable {
+  width: 100%;
+  border-collapse: collapse;
+}
+
+table.mimeAttachmentTable tr + tr > td {
+  border-top: 1px solid gray;
+}
+
+.mimeAttachmentFile {
+}
+
+.mimeAttachmentSize {
+  text-align: right;
+}
--- a/suite/themes/modern/messenger/messageBody.css
+++ b/suite/themes/modern/messenger/messageBody.css
@@ -178,17 +178,38 @@ body[selected="false"] {
   position: fixed;
   top: 0;
   left: 0;
   width: 100%;
   height: 100%;
   border: none;
 }
 
+/* Attachment display styling (for inline attachments and printing) */
 .mimeAttachmentHeader {
   border-style: none;
   border-top: 1px solid gray;
 }
 
-.mimeAttachmentName {
+.mimeAttachmentHeaderName {
   color: gray;
   font-size: 80%;
 }
+
+div.mimeAttachmentWrap {
+  padding: 0 1em;
+}
+
+table.mimeAttachmentTable {
+  width: 100%;
+  border-collapse: collapse;
+}
+
+table.mimeAttachmentTable tr + tr > td {
+  border-top: 1px solid gray;
+}
+
+.mimeAttachmentFile {
+}
+
+.mimeAttachmentSize {
+  text-align: right;
+}