Bug 1414518 - introduce pref mailnews.headers.extraAddonHeaders to emit extra headers to currentHeaderData. r=jorgk
authorPatrick Brunschwig <patrick>
Thu, 14 Dec 2017 09:26:00 +0100
changeset 22869 68bfb968e75ed387acad1a4132b727807c4fe035
parent 22868 32ac7a019454be10f74362ed775af83a10e8bbab
child 22870 366a608bbf3be76e3e04163288a9341b4930133f
push id13853
push usermozilla@jorgk.com
push dateFri, 15 Dec 2017 22:35:23 +0000
treeherdercomm-central@68bfb968e75e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1414518
Bug 1414518 - introduce pref mailnews.headers.extraAddonHeaders to emit extra headers to currentHeaderData. r=jorgk
mailnews/mailnews.js
mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -45,16 +45,21 @@ pref("mailnews.messageid_browser.url", "
 
 
 // hidden pref for whether or not to warn when deleting filters. Default YES
 pref("mailnews.filters.confirm_delete", true);
 
 // space-delimited list of extra headers to show in msg header display area.
 pref("mailnews.headers.extraExpandedHeaders", "");
 
+// Space-delimited list of extra headers that will be pushed to
+// currentHeaderData for processing in add-ons (without being displayed).
+// Use a value of "*" to get all headers (other wildcards not supported).
+pref("mailnews.headers.extraAddonHeaders", "");
+
 // default sort order settings (when creating new folder views)
 // sort_order is an int value reflecting nsMsgViewSortOrder values
 //   as defined in nsIMsgDBView.idl (ascending = 1, descending = 2)
 // sort_type is an int value reflecting nsMsgViewSortType values
 //   as defined in nsIMsgDBView.idl (byDate = 18, byId = 21 etc.)
 pref("mailnews.default_sort_order", 1); // for Mail/RSS/... (nsMsgDatabase)
 pref("mailnews.default_sort_type", 18); //
 pref("mailnews.default_news_sort_order", 1); // for News (nsNewsDatabase)
--- a/mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
+++ b/mailnews/mime/emitters/nsMimeHtmlEmitter.cpp
@@ -163,75 +163,101 @@ nsresult nsMimeHtmlDisplayEmitter::Broad
   // two string enumerators to pass out to the header sink
   RefPtr<nsMimeStringEnumerator> headerNameEnumerator = new nsMimeStringEnumerator();
   NS_ENSURE_TRUE(headerNameEnumerator, NS_ERROR_OUT_OF_MEMORY);
   RefPtr<nsMimeStringEnumerator> headerValueEnumerator = new nsMimeStringEnumerator();
   NS_ENSURE_TRUE(headerValueEnumerator, NS_ERROR_OUT_OF_MEMORY);
 
   nsCString extraExpandedHeaders;
   nsTArray<nsCString> extraExpandedHeadersArray;
+  nsCString extraAddonHeaders;
+  nsTArray<nsCString> extraAddonHeadersArray;
   nsAutoCString convertedDateString;
+  bool pushAllHeaders = false;
+  bool checkExtraHeaders = false;
+  bool checkAddonHeaders = false;
 
   nsresult rv;
   nsCOMPtr<nsIPrefBranch> pPrefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID, &rv));
   if (pPrefBranch)
   {
     pPrefBranch->GetCharPref("mailnews.headers.extraExpandedHeaders", extraExpandedHeaders);
-    // todo - should make this upper case
     if (!extraExpandedHeaders.IsEmpty())
     {
       ToLowerCase(extraExpandedHeaders);
       ParseString(extraExpandedHeaders, ' ', extraExpandedHeadersArray);
+      checkExtraHeaders = true;
+    }
+
+    pPrefBranch->GetCharPref("mailnews.headers.extraAddonHeaders", extraAddonHeaders);
+    if (!extraAddonHeaders.IsEmpty())
+    {
+      // Push all headers if extraAddonHeaders is "*".
+      if (extraAddonHeaders.EqualsLiteral("*")) {
+        pushAllHeaders = true;
+      } else {
+        ToLowerCase(extraAddonHeaders);
+        ParseString(extraAddonHeaders, ' ', extraAddonHeadersArray);
+        checkAddonHeaders = true;
+      }
     }
   }
 
   for (size_t i = 0; i < mHeaderArray->Length(); i++)
   {
     headerInfoType * headerInfo = mHeaderArray->ElementAt(i);
     if ( (!headerInfo) || (!headerInfo->name) || (!(*headerInfo->name)) || (!headerInfo->value) || (!(*headerInfo->value)))
       continue;
 
     // optimization: if we aren't in view all header view mode, we only show a small set of the total # of headers.
     // don't waste time sending those out to the UI since the UI is going to ignore them anyway.
     if (aHeaderMode != VIEW_ALL_HEADERS && (mFormat != nsMimeOutput::nsMimeMessageFilterSniffer))
     {
       bool skip = true;
       const char * headerName = headerInfo->name;
+      if (pushAllHeaders) {
+        skip = false;
+
       // Accept the following:
-      if (!PL_strcasecmp("to",           headerName) ||
-          !PL_strcasecmp("from",         headerName) ||
-          !PL_strcasecmp("cc",           headerName) ||
-          !PL_strcasecmp("newsgroups",   headerName) ||
-          !PL_strcasecmp("bcc",          headerName) ||
-          !PL_strcasecmp("followup-to",  headerName) ||
-          !PL_strcasecmp("reply-to",     headerName) ||
-          !PL_strcasecmp("subject",      headerName) ||
-          !PL_strcasecmp("organization", headerName) ||
-          !PL_strcasecmp("user-agent",   headerName) ||
-          !PL_strcasecmp("content-base", headerName) ||
-          !PL_strcasecmp("sender",       headerName) ||
-          !PL_strcasecmp("date",         headerName) ||
-          !PL_strcasecmp("x-mailer",     headerName) ||
-          !PL_strcasecmp("content-type", headerName) ||
-          !PL_strcasecmp("message-id",   headerName) ||
-          !PL_strcasecmp("x-newsreader", headerName) ||
-          !PL_strcasecmp("x-mimeole",    headerName) ||
-          !PL_strcasecmp("references",   headerName) ||
-          !PL_strcasecmp("in-reply-to",  headerName) ||
-          !PL_strcasecmp("list-post",    headerName) ||
-          !PL_strcasecmp("delivered-to", headerName)) {
+      } else if (!PL_strcasecmp("to",           headerName) ||
+                 !PL_strcasecmp("from",         headerName) ||
+                 !PL_strcasecmp("cc",           headerName) ||
+                 !PL_strcasecmp("newsgroups",   headerName) ||
+                 !PL_strcasecmp("bcc",          headerName) ||
+                 !PL_strcasecmp("followup-to",  headerName) ||
+                 !PL_strcasecmp("reply-to",     headerName) ||
+                 !PL_strcasecmp("subject",      headerName) ||
+                 !PL_strcasecmp("organization", headerName) ||
+                 !PL_strcasecmp("user-agent",   headerName) ||
+                 !PL_strcasecmp("content-base", headerName) ||
+                 !PL_strcasecmp("sender",       headerName) ||
+                 !PL_strcasecmp("date",         headerName) ||
+                 !PL_strcasecmp("x-mailer",     headerName) ||
+                 !PL_strcasecmp("content-type", headerName) ||
+                 !PL_strcasecmp("message-id",   headerName) ||
+                 !PL_strcasecmp("x-newsreader", headerName) ||
+                 !PL_strcasecmp("x-mimeole",    headerName) ||
+                 !PL_strcasecmp("references",   headerName) ||
+                 !PL_strcasecmp("in-reply-to",  headerName) ||
+                 !PL_strcasecmp("list-post",    headerName) ||
+                 !PL_strcasecmp("delivered-to", headerName)) {
         skip = false;
-      } else if (extraExpandedHeadersArray.Length() > 0) {
-        // Make headerStr lower case because IndexOf is case-sensitive.
+
+      } else if (checkExtraHeaders || checkAddonHeaders) {
+        // Make headerStr lowercase because extraExpandedHeaders/extraAddonHeadersArray
+        // was made lowercase above.
         nsDependentCString headerStr(headerInfo->name);
         ToLowerCase(headerStr);
         // Accept if it's an "extra" header.
-        if (extraExpandedHeadersArray.Contains(headerStr))
+        if (checkExtraHeaders && extraExpandedHeadersArray.Contains(headerStr))
+          skip = false;
+        if (checkAddonHeaders && extraAddonHeadersArray.Contains(headerStr))
           skip = false;
       }
+
       if (skip)
         continue;
     }
 
     const char * headerValue = headerInfo->value;
     headerNameEnumerator->Append(headerInfo->name);
     headerValueEnumerator->Append(headerValue);