Bug 472959 - GUI leaves invalid junk settings when "spamActionTargetFolder" is moved FROM a deleted account. r=bienvenu,ui-review=bwinton
authoraceman <acelists@atlas.sk>
Mon, 13 Feb 2012 14:08:41 +0000
changeset 10812 0ab0cc3496f8b7f1b1d27169b1942fcb3d716d6e
parent 10811 e0ccaae60f484b4dcb58fda70080fa1eb7d6e599
child 10813 4e8a635051f2ea903803ccb13ceac777c2e4b9ed
push id463
push userbugzilla@standard8.plus.com
push dateTue, 24 Apr 2012 17:34:51 +0000
treeherdercomm-beta@e53588e8f7b0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbienvenu
bugs472959
Bug 472959 - GUI leaves invalid junk settings when "spamActionTargetFolder" is moved FROM a deleted account. r=bienvenu,ui-review=bwinton
mailnews/base/prefs/content/am-junk.js
--- a/mailnews/base/prefs/content/am-junk.js
+++ b/mailnews/base/prefs/content/am-junk.js
@@ -31,62 +31,78 @@
 # use your version of this file under the terms of the MPL, indicate your
 # decision by deleting the provisions above and replace them with the notice
 # and other provisions required by the GPL or the LGPL. If you do not delete
 # the provisions above, a recipient may use your version of this file under
 # the terms of any one of the MPL, the GPL or the LGPL.
 #
 # ***** END LICENSE BLOCK *****
 */
+Components.utils.import("resource:///modules/mailServices.js");
+Components.utils.import("resource:///modules/iteratorUtils.jsm");
 
 const KEY_ISP_DIRECTORY_LIST = "ISPDL";
 var gPrefBranch = null;
 
 function onInit(aPageId, aServerId)
 {
-  Components.utils.import("resource:///modules/mailServices.js");
-  Components.utils.import("resource:///modules/iteratorUtils.jsm");
-
   // manually adjust several pref UI elements
   document.getElementById('spamLevel').checked =
     document.getElementById('server.spamLevel').value > 0;
-    
+
+  const am = MailServices.accounts;
+
   var spamActionTargetAccount = document.getElementById('server.spamActionTargetAccount').value;
-  var am = Components.classes["@mozilla.org/messenger/account-manager;1"]
-                     .getService(Components.interfaces.nsIMsgAccountManager);
+  try {
+    GetMsgFolderFromUri(spamActionTargetAccount + "/Junk", false).server;
+  } catch (e) {
+    // spamActionTargetAccount is not valid, reseting to default behavior to NOT move junk messages.
+    if (document.getElementById('server.moveTargetMode').value == 0)
+      document.getElementById('server.moveOnSpam').checked = false;
+    spamActionTargetAccount = null;
+  }
+
+  var spamActionTargetFolder = document.getElementById('server.spamActionTargetFolder').value;
+  try {
+    GetMsgFolderFromUri(spamActionTargetFolder, true).server;
+  } catch (e) {
+    // spamActionTargetFolder is not valid, reseting to default behavior to NOT move junk messages.
+    if (document.getElementById('server.moveTargetMode').value == 1)
+      document.getElementById('server.moveOnSpam').checked = false;
+    spamActionTargetFolder = null;
+  }
+
   if (!spamActionTargetAccount)
   {
     var server = GetMsgFolderFromUri(aServerId, false).server;
     if (server.canCreateFoldersOnServer && server.canSearchMessages)
       spamActionTargetAccount = aServerId;
     else
       spamActionTargetAccount = am.localFoldersServer.serverURI;
     document.getElementById('server.spamActionTargetAccount').value = spamActionTargetAccount;
   }
   document.getElementById("actionAccountPopup")
           .selectFolder(GetMsgFolderFromUri(spamActionTargetAccount));
-  var spamActionTargetFolder = document.getElementById('server.spamActionTargetFolder').value;
+
   if (!spamActionTargetFolder)
   {
     spamActionTargetFolder = am.localFoldersServer.serverURI + "/Junk";
     document.getElementById('server.spamActionTargetFolder').value = spamActionTargetFolder;
   }
 
   try
   {
     var folder = GetMsgFolderFromUri(spamActionTargetFolder);
     var longFolderName = document.getElementById("bundle_messenger")
                                  .getFormattedString("verboseFolderFormat",
                                  [folder.prettyName, folder.server.prettyName]);
     document.getElementById("actionTargetFolder")
             .setAttribute("label", longFolderName);
   }
-
-  // OK for folder to not exist
-  catch (e) {}
+  catch (e) { /* OK for folder to not exist */ }
 
   var currentArray = [];
   if (document.getElementById("server.useWhiteList").checked)
     currentArray = document.getElementById("server.whiteListAbURI").value.split(" ");
 
   // set up the whitelist UI
   var wList = document.getElementById("whiteListAbURI");
 
@@ -128,17 +144,17 @@ function onInit(aPageId, aServerId)
     wList.appendChild(abItems[i]);
 
   // set up trusted IP headers
   var serverFilterList = document.getElementById("useServerFilterList");
   serverFilterList.value =
     document.getElementById("server.serverFilterName").value;
   if (!serverFilterList.selectedItem)
     serverFilterList.selectedIndex = 0;
-   
+
   updateMoveTargetMode(document.getElementById('server.moveOnSpam').checked);
 
   // enable or disable the useServerFilter checkbox
   var checked = document.getElementById("server.useServerFilter").checked;
   onServerFilterToggle(checked);
 }
 
 function onPreInit(account, accountValues)