Bug 1514951 - Fix filter creation from subject header. r=arshad
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Wed, 19 Dec 2018 12:30:03 +0200
changeset 34040 e27c47602ff5d5ec7e7b18aa233f43f22cef6d11
parent 34039 1481cb94d41e940d40ea97e8825d8b37d154e406
child 34041 927874d67aa0ab461e8d41799b4f23373fd2c152
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersarshad
bugs1514951
Bug 1514951 - Fix filter creation from subject header. r=arshad
mail/base/content/mainPopupSet.inc
mail/base/content/msgHdrView.js
--- a/mail/base/content/mainPopupSet.inc
+++ b/mail/base/content/mainPopupSet.inc
@@ -1199,17 +1199,17 @@
               tooltiptext="&copyCmd.label;"
               oncommand="Cc['@mozilla.org/widget/clipboardhelper;1']
                            .getService(Ci.nsIClipboardHelper)
                            .copyString(window.getSelection().isCollapsed ?
                              document.popupNode.textContent :
                              window.getSelection().toString());"/>
     <menuitem id="createFilterFromMenuItem" label="&CreateFilterFrom.label;"
               accesskey="&CreateFilterFrom.accesskey;"
-              oncommand="CreateFilter(this.parentNode.triggerNode.parentNode, gMessageDisplay.displayedMessage)"
+              oncommand="CreateFilter(document.popupNode, gMessageDisplay.displayedMessage)"
               observes="cmd_createFilterFromPopup"/>
   </menupopup>
   <!-- "Please keep all items and separators up to date in nsContextMenu.js when making changes here" -->
   <menupopup id="mailContext"
              pagemenu="start"
              onpopupshowing="return fillMailContextMenu(event);"
              onpopuphiding="mailContextOnPopupHiding(event);">
 
--- a/mail/base/content/msgHdrView.js
+++ b/mail/base/content/msgHdrView.js
@@ -160,17 +160,20 @@ function createHeaderEntry(prefix, heade
     this.outputFunction = headerListInfo.outputFunction;
   else
     this.outputFunction = updateHeaderValue;
 
   // Stash this so that the <mail-multi-emailheaderfield/> binding can
   // later attach it to any <mail-emailaddress> tags it creates for later
   // extraction and use by UpdateEmailNodeDetails.
   this.enclosingBox.headerName = headerListInfo.name;
-
+  // Set the headerName attribute for the value nodes too.
+  this.enclosingBox.querySelectorAll(".headerValue").forEach(e => {
+    e.setAttribute("headerName", headerListInfo.name);
+  });
 }
 
 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.
   for (let header of gExpandedHeaderList) {
     gExpandedHeaderView[header.name] = new createHeaderEntry("expanded", header);
@@ -1582,29 +1585,36 @@ function CopyEmailNewsAddress(addressNod
                 addressNode.getAttribute("newsgroup");
   clipboard.copyString(address);
 }
 
 /**
  * Causes the filter dialog to pop up, prefilled for the specified e-mail
  * address or header value.
  *
- * @param aHeaderNode  A node which has an "emailAddress" attribute
- *                     or a "headerName" attribute.
+ * @param aHeaderNode  Node for which to create the filter. This can be a node
+ *                     in an mail-emailaddress element, or a node with just
+ *                     textual data, like Subject or Date.
  * @param aMessage     Optional nsIMsgHdr of the message from which the values
  *                     are taken. Will be used to preselect its folder in the
  *                     filter list.
  */
 function CreateFilter(aHeaderNode, aMessage) {
-  aHeaderNode = aHeaderNode.closest("mail-emailaddress");
-  let nodeIsAddress = aHeaderNode.hasAttribute("emailAddress");
-  let nodeValue = nodeIsAddress ? aHeaderNode.getAttribute("emailAddress") :
-                                  aHeaderNode.textContent;
+  let addressNode = aHeaderNode.closest("mail-emailaddress");
+  let value;
+  let name;
+  if (addressNode) {
+    name = addressNode.getAttribute("headerName");
+    value = addressNode.getAttribute("emailAddress");
+  } else {
+    name = aHeaderNode.getAttribute("headerName");
+    value = aHeaderNode.textContent;
+  }
   let folder = aMessage ? aMessage.folder : null;
-  top.MsgFilters(nodeValue, folder, aHeaderNode.getAttribute("headerName"));
+  top.MsgFilters(value, folder, name);
 }
 
 /**
  * Get the newsgroup server corresponding to the currently selected message.
  *
  * @return nsISubscribableServer for the newsgroup, or null
  */
 function GetNewsgroupServer() {