Bug 1250295 - preset folder to run filters on in the filter editor in more cases. r=squib
authoraceman <acelists@atlas.sk>
Thu, 10 Mar 2016 11:03:00 +0100
changeset 24692 3d9fb0a3003fd150576b6962201356b171b8c1ba
parent 24691 bb1fbfbdb47f67169eea6d4c58cbda2d44eca22e
child 24693 601b90ee6cc7183dc78086bcd46cc6e379d71498
push id1657
push userclokep@gmail.com
push dateMon, 06 Jun 2016 19:50:21 +0000
treeherdercomm-beta@9fac989284b5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssquib
bugs1250295
Bug 1250295 - preset folder to run filters on in the filter editor in more cases. r=squib
mail/base/content/mailWindowOverlay.js
mail/base/content/mailWindowOverlay.xul
mail/base/content/msgHdrViewOverlay.js
--- a/mail/base/content/mailWindowOverlay.js
+++ b/mail/base/content/mailWindowOverlay.js
@@ -1952,17 +1952,17 @@ function MsgComposeDraftMessage()
 }
 
 function MsgCreateFilter()
 {
   // retrieve Sender direct from selected message's headers
   var msgHdr = gFolderDisplay.selectedMessage;
   let emailAddress = MailServices.headerParser.extractHeaderAddressMailboxes(msgHdr.author);
   if (emailAddress)
-    top.MsgFilters(emailAddress, null);
+    top.MsgFilters(emailAddress, msgHdr.folder);
 }
 
 function MsgNewFolder(callBackFunctionName)
 {
   var preselectedFolder = GetFirstSelectedMsgFolder();
   var dualUseFolders = true;
   var server = null;
   var destinationFolder = null;
@@ -2327,17 +2327,19 @@ function MsgMarkReadByDate()
 function MsgMarkAllRead()
 {
   let folders = gFolderTreeView.getSelectedFolders();
   for (let i = 0; i < folders.length; i++)
     folders[i].markAllMessagesRead(msgWindow);
 }
 
 /**
- * Create a new filter with the passed in data prefilled.
+ * Opens the filter list.
+ * If an email address was passed, first a new filter is offered for creation
+ * with the data prefilled.
  *
  * @param emailAddress  An email address to use as value in the first search term.
  * @param folder        The filter will be created in this folder's filter list.
  * @param fieldName     Search field string, from nsMsgSearchTerm.cpp::SearchAttribEntryTable.
  */
 function MsgFilters(emailAddress, folder, fieldName)
 {
   if (!folder)
@@ -2353,19 +2355,16 @@ function MsgFilters(emailAddress, folder
        *  manual scope. This is the best solution for POP3 with global
        *  inbox (as then both manual and incoming filters work correctly),
        *  but may not be what IMAP users who filter to a local folder
        *  really want.
        */
       try
       {
         folder = gFolderDisplay.selectedMessage.folder;
-        // except for news, we define the filter on the account's root
-        if (!gFolderDisplay.selectedMessageIsNews)
-          folder = folder.rootFolder;
       }
       catch (ex) {}
     }
     if (!folder)
       folder = GetFirstSelectedMsgFolder();
   }
   var args;
   if (emailAddress)
@@ -2376,17 +2375,17 @@ function MsgFilters(emailAddress, folder
              filterName: emailAddress };
     // Set the field name to prefill in the filter, if one was specified.
     if (fieldName)
       args.fieldName = fieldName;
 
     window.openDialog("chrome://messenger/content/FilterEditor.xul", "",
                       "chrome, modal, resizable,centerscreen,dialog=yes", args);
 
-    // If the user hits ok in the filterEditor dialog we set args.refresh=true
+    // If the user hits OK in the filterEditor dialog we set args.refresh=true
     // there and we check this here in args to show filterList dialog.
     // We also received the filter created via args.newFilter.
     if ("refresh" in args && args.refresh)
     {
       args = { refresh: true, folder: folder, filter: args.newFilter };
       MsgFilterList(args);
     }
   }
--- a/mail/base/content/mailWindowOverlay.xul
+++ b/mail/base/content/mailWindowOverlay.xul
@@ -2163,33 +2163,33 @@
               accesskey="&CopyEmailAddress.accesskey;"
               oncommand="CopyEmailNewsAddress(findEmailNodeFromPopupNode(document.popupNode, 'emailAddressPopup'))"/>
     <menuitem id="copyNameAndEmailAddressItem" label="&CopyNameAndEmailAddress.label;"
               accesskey="&CopyNameAndEmailAddress.accesskey;"
               oncommand="CopyEmailNewsAddress(findEmailNodeFromPopupNode(document.popupNode, 'emailAddressPopup'), true)"/>
     <menuseparator/>
     <menuitem id="createFilterFromItem" label="&CreateFilterFrom.label;"
               accesskey="&CreateFilterFrom.accesskey;"
-              oncommand="CreateFilter(findEmailNodeFromPopupNode(document.popupNode, 'emailAddressPopup'))"
+              oncommand="CreateFilter(findEmailNodeFromPopupNode(document.popupNode, 'emailAddressPopup'), gMessageDisplay.displayedMessage)"
               observes="cmd_createFilterFromPopup"/>
   </menupopup>
 
   <menupopup id="copyPopup">
     <menuitem id="copyMenuitem"
               label="&copyCmd.label;"
               accesskey="&copyCmd.accesskey;"
               tooltiptext="&copyCmd.label;"
               oncommand="Components.classes['@mozilla.org/widget/clipboardhelper;1']
                          .getService(Components.interfaces.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)"
+              oncommand="CreateFilter(this.parentNode.triggerNode.parentNode, gMessageDisplay.displayedMessage)"
               observes="cmd_createFilterFromPopup"/>
   </menupopup>
 
 </popupset>
 
 <!-- The reason we put the menubar inside a toolbox is due to the labelalign and
      defaultlabelalign attributes that the toolbars might expect from their
      parent toolboxes.  This lets us control how toolbar buttons appear in the
--- a/mail/base/content/msgHdrViewOverlay.js
+++ b/mail/base/content/msgHdrViewOverlay.js
@@ -1642,23 +1642,27 @@ function CopyEmailNewsAddress(addressNod
 }
 
 /**
  * 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 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)
+function CreateFilter(aHeaderNode, aMessage)
 {
   let nodeIsAddress = aHeaderNode.hasAttribute("emailAddress");
   let nodeValue = nodeIsAddress ? aHeaderNode.getAttribute("emailAddress") :
                                   document.getAnonymousNodes(aHeaderNode)[0].textContent;
-  top.MsgFilters(nodeValue, null, aHeaderNode.getAttribute("headerName"));
+  let folder = aMessage ? aMessage.folder : null;
+  top.MsgFilters(nodeValue, folder, aHeaderNode.getAttribute("headerName"));
 }
 
 /**
  * Get the newsgroup server corresponding to the currently selected message.
  *
  * @return nsISubscribableServer for the newsgroup, or null
  */
 function GetNewsgroupServer()