Bug 1498491 - don't create extra header elements when extraExpandedHeaders is not set. r=jorgk
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Fri, 12 Oct 2018 12:26:03 +0300
changeset 33357 22016492fb10c5d1b4175047c095d935c19de151
parent 33356 283c828650e3acf302b844263cedb609b2a88cb7
child 33358 e2b203306dad4554844efa16f2c43cba60cee85e
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk
bugs1498491
Bug 1498491 - don't create extra header elements when extraExpandedHeaders is not set. r=jorgk If mailnews.headers.extraExpandedHeaders is not set, split(" ") would still return length 1... Also the lower casing of IDs was not enforced, and not followed.
mail/base/content/msgHdrView.js
--- a/mail/base/content/msgHdrView.js
+++ b/mail/base/content/msgHdrView.js
@@ -164,29 +164,28 @@ function createHeaderEntry(prefix, heade
 
 }
 
 function initializeHeaderViewTables()
 {
   // Iterate over each header in our header list arrays and create header entries
   // for each one. These header entries are then stored in the appropriate header
   // table.
-  var index;
-  for (index = 0; index < gExpandedHeaderList.length; index++) {
-    var headerName = gExpandedHeaderList[index].name;
-    gExpandedHeaderView[headerName] =
-      new createHeaderEntry("expanded", gExpandedHeaderList[index]);
+  for (let header of gExpandedHeaderList) {
+    gExpandedHeaderView[header.name] = new createHeaderEntry("expanded", header);
   }
 
-  var extraHeaders =
+  let extraHeaders =
     Services.prefs.getCharPref("mailnews.headers.extraExpandedHeaders").split(" ");
-  for (index = 0; index < extraHeaders.length; index++) {
-    var extraHeader = extraHeaders[index];
-    gExpandedHeaderView[extraHeader.toLowerCase()] =
-      new HeaderView(extraHeader, extraHeader);
+  for (let extraHeaderName of extraHeaders) {
+    if (!extraHeaderName.trim()) {
+      continue;
+    }
+    gExpandedHeaderView[extraHeaderName.toLowerCase()] =
+      new HeaderView(extraHeaderName, extraHeaderName);
   }
 
   if (Services.prefs.getBoolPref("mailnews.headers.showOrganization")) {
     var organizationEntry = { name: "organization",
                               outputFunction: updateHeaderValue };
     gExpandedHeaderView[organizationEntry.name] =
       new createHeaderEntry("expanded", organizationEntry);
   }
@@ -1006,22 +1005,23 @@ function updateHeaderValue(aHeaderEntry,
 {
   aHeaderEntry.enclosingBox.headerValue = aHeaderValue;
 }
 
 /**
  * Create the DOM nodes (aka "View") for a non-standard header and insert them
  * into the grid.  Create and return the corresponding headerEntry object.
  *
- * @param {String} headerName  name of the header we're adding, all lower-case;
- *                             used to construct element ids
+ * @param {String} headerName  name of the header we're adding, used to
+ *                             construct the element IDs (in lower case)
  * @param {String} label       name of the header as displayed in the UI
  */
 function HeaderView(headerName, label)
 {
+  headerName = headerName.toLowerCase();
   let rowId = "expanded" + headerName + "Row";
   let idName = "expanded" + headerName + "Box";
   let newHeaderNode;
   // If a row for this header already exists, do not create another one.
   let newRowNode = document.getElementById(rowId);
   if (!newRowNode) {
     // Create new collapsed row.
     newRowNode = document.createElement("row");