Bug 1547664 - Ask for confirmation on the real trash folder if a non-trash folder was selected. r+a=jorgk
authoraceman <acelists@atlas.sk>
Sat, 04 May 2019 23:07:35 +0200
changeset 34001 006b4646c4f2e12645fcc5b6afd53da71d50da20
parent 34000 1889b7254762388c423a33d5403333c791814188
child 34002 7fcb16ec50b1465f4bd0e95215bb45284b5f6ade
push id2404
push usermozilla@jorgk.com
push dateTue, 07 May 2019 20:34:08 +0000
treeherdercomm-beta@ac7b1df1919b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1547664
Bug 1547664 - Ask for confirmation on the real trash folder if a non-trash folder was selected. r+a=jorgk
mail/base/content/folderPane.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -2635,23 +2635,24 @@ var gFolderTreeController = {
     let array = toXPCOMArray([folder], Ci.nsIMutableArray);
     folder.parent.deleteSubFolders(array, msgWindow);
   },
 
   /**
    * Prompts the user to confirm and empties the trash for the selected folder.
    * The folder and its children are only emptied if it has the proper Trash flag.
    *
-   * @param aFolder (optional)  the trash folder to empty
-   * @note Calling this function on a non-trash folder will result in strange
-   *       behavior!
+   * @param aFolder (optional)  The trash folder to empty. If unspecified or not
+   *                            a trash folder, the currently selected server's
+   *                            trash folder is used.
    */
   emptyTrash(aFolder) {
     let folder = aFolder || gFolderTreeView.getSelectedFolders()[0];
-
+    if (!folder.getFlag(Ci.nsMsgFolderFlags.Trash))
+      folder = folder.rootFolder.getFolderWithFlags(Ci.nsMsgFolderFlags.Trash);
     if (!folder)
       return;
 
     if (!this._checkConfirmationPrompt("emptyTrash", folder))
       return;
 
       // Check if this is a top-level smart folder. If so, we're going
       // to empty all the trash folders.
@@ -2666,17 +2667,18 @@ var gFolderTreeController = {
         folder.emptyTrash(msgWindow, null);
       }
   },
 
   /**
    * Deletes everything (folders and messages) in the selected folder.
    * The folder is only emptied if it has the proper Junk flag.
    *
-   * @param aFolder (optional)  the folder to empty
+   * @param aFolder (optional)  The folder to empty. If unspecified, the currently
+   *                            selected folder is used, if it is junk.
    */
   emptyJunk(aFolder) {
     let folder = aFolder || gFolderTreeView.getSelectedFolders()[0];
 
     if (!folder || !folder.getFlag(Ci.nsMsgFolderFlags.Junk))
       return;
 
     if (!this._checkConfirmationPrompt("emptyJunk", folder))
@@ -2786,32 +2788,31 @@ var gFolderTreeController = {
    * @param aCommand  the command to prompt for
    * @param aFolder   The folder for which the confirmation is requested.
    */
   _checkConfirmationPrompt(aCommand, aFolder) {
     // If no folder was specified, reject the operation.
     if (!aFolder)
       return false;
 
-    let showPrompt = true;
-    try {
-      showPrompt = !Services.prefs.getBoolPref("mailnews." + aCommand + ".dontAskAgain");
-    } catch (ex) {}
+    let showPrompt = !Services.prefs
+                       .getBoolPref("mailnews." + aCommand + ".dontAskAgain", false);
 
     if (showPrompt) {
       let checkbox = {value: false};
       let title = gFolderTreeView.messengerBundle
         .getFormattedString(aCommand + "FolderTitle", [aFolder.prettyName]);
       let msg = gFolderTreeView.messengerBundle.getString(aCommand + "FolderMessage");
       let ok = Services.prompt.confirmEx(window,
                                          title,
                                          msg,
                                          Services.prompt.STD_YES_NO_BUTTONS,
                                          null, null, null,
-                                         gFolderTreeView.messengerBundle.getString(aCommand + "DontAsk"),
+                                         gFolderTreeView.messengerBundle
+                                                        .getString(aCommand + "DontAsk"),
                                          checkbox) == 0;
       if (checkbox.value)
         Services.prefs.setBoolPref("mailnews." + aCommand + ".dontAskAgain", true);
       if (!ok)
         return false;
     }
     return true;
   },