Bug 709581 - if server.spamSettings.initialize throws, offer the user to check Junk settings again. r=IanN, r=standard8, ui-r=bwinton
authoraceman <acelists@atlas.sk>
Tue, 24 Apr 2012 15:09:22 +0100
changeset 11718 e46f87c271f14a7d03feebe02ac03f87313c543c
parent 11717 fbc7135f80a7d1672bf6a5dd40d2f89b6fd97b89
child 11719 f93bfa99a73176e674940de03397cf956dd9369b
push idunknown
push userunknown
push dateunknown
reviewersIanN, standard8, bwinton
bugs709581
Bug 709581 - if server.spamSettings.initialize throws, offer the user to check Junk settings again. r=IanN, r=standard8, ui-r=bwinton
mail/locales/en-US/chrome/messenger/prefs.properties
mailnews/base/prefs/content/AccountManager.js
mailnews/base/prefs/content/AccountManager.xul
suite/locales/en-US/chrome/mailnews/pref/prefs.properties
--- a/mail/locales/en-US/chrome/messenger/prefs.properties
+++ b/mail/locales/en-US/chrome/messenger/prefs.properties
@@ -1,15 +1,17 @@
 # The following are used by the Account Wizard
 #
 enterValidEmail=Please enter a valid email address.
 accountExists=A mail or newsgroup account with the same user name and server name already exists. Click Back and enter a different server name, or click Cancel.
 modifiedAccountExists=An account with that user name and server name already exists. Please enter a different user name and/or server name.
 userNameChanged=Your User Name has been updated. You may also need to update your Email Address and/or User Name associated with this account.
 serverNameChanged=The server name setting has changed. Please verify that any folders used by filters exist on the new server.
+# LOCALIZATION NOTE (junkSettingsBroken): %1$S is the account name
+junkSettingsBroken=The Junk settings on account "%1$S" have a possible problem. Would you like to review them before saving Account Settings?
 # LOCALIZATION NOTE (localDirectoryChanged): %1$S is program name (&brandShortName;)
 localDirectoryChanged=%1$S needs to restart now to apply the change to the Local directory setting.
 localDirectoryRestart=Restart
 serverNameEmpty=Neither the server name nor the user name can be empty.
 # if the user chooses to cancel the wizard when no accounts are there throw a message
 # LOCALIZATION NOTE (cancelWizard)
 # do not localize "\n\n"
 cancelWizard=Are you sure you want to exit the Account Wizard?\n\nIf you exit, any information you have entered will be lost and the account will not be created.
--- a/mailnews/base/prefs/content/AccountManager.js
+++ b/mailnews/base/prefs/content/AccountManager.js
@@ -235,17 +235,19 @@ function onAccept() {
   if (!checkUserServerChanges(true))
     return false;
 
   if (gSmtpHostNameIsIllegal) {
     gSmtpHostNameIsIllegal = false;
     return false;
   }
 
-  onSave();
+  if (!onSave())
+    return false;
+
   // hack hack - save the prefs file NOW in case we crash
   Services.prefs.savePrefFile(null);
 
   if (gRestartNeeded) {
     gRestartNeeded = !Application.restart();
     // returns false so that Account manager is not exited when restart failed
     return !gRestartNeeded;
   }
@@ -390,27 +392,30 @@ function checkUserServerChanges(showAler
   }
 
   return true;
 }
 
 function onSave() {
   if (pendingPageId) {
     dump("ERROR: " + pendingPageId + " hasn't loaded yet! Not saving.\n");
-    return;
+    return false;
   }
 
   // make sure the current visible page is saved
   savePage(currentAccount);
 
   for (var accountid in accountArray) {
     var accountValues = accountArray[accountid];
     var account = accountArray[accountid]._account;
-    saveAccount(accountValues, account);
+    if (!saveAccount(accountValues, account))
+      return false;
   }
+
+ return true;
 }
 
 function onAddAccount() {
   MsgAccountWizard();
 }
 
 function AddMailAccount()
 {
@@ -577,33 +582,48 @@ function saveAccount(accountValues, acco
             break;
         }
         methodName += ((methodName + "Value") in dest ? "Value" : "Attribute");
         if (dest[methodName](slot) != typeArray[slot]) {
           methodName = methodName.replace("get", "set");
           dest[methodName](slot, typeArray[slot]);
         }
       }
-      else {
-      if (slot in dest && typeArray[slot] != undefined && dest[slot] != typeArray[slot]) {
+      else if (slot in dest && typeArray[slot] != undefined && dest[slot] != typeArray[slot]) {
         try {
           dest[slot] = typeArray[slot];
-          } 
-          catch (ex) {
+        } catch (ex) {
           // hrm... need to handle special types here
         }
       }
     }
   }
- }
- 
- // if we made account changes to the spam settings, we'll need to re-initialize
- // our settings object
- if (server && server.spamSettings)
-   server.spamSettings.initialize(server);
+
+  // if we made account changes to the spam settings, we'll need to re-initialize
+  // our settings object
+  if (server && server.spamSettings) {
+    try {
+      server.spamSettings.initialize(server);
+    } catch(e) {
+      let accountName = getAccountValue(account, getValueArrayFor(account), "server",
+                                        "prettyName", null, false);
+      let alertText = document.getElementById("bundle_prefs")
+                              .getFormattedString("junkSettingsBroken", [accountName]);
+      let review = Services.prompt.confirmEx(window, null, alertText,
+        (Services.prompt.BUTTON_POS_0 * Services.prompt.BUTTON_TITLE_YES) +
+        (Services.prompt.BUTTON_POS_1 * Services.prompt.BUTTON_TITLE_NO),
+        null, null, null, null, {});
+      if (!review) {
+        onAccountTreeSelect("am-junk.xul", account);
+        return false;
+      }
+    }
+  }
+
+  return true;
 }
 
 function updateButtons(tree, account) {
   var canCreate = true;
   var canDelete = true;
   var canSetDefault = true;
 
   if (account) {
@@ -636,17 +656,17 @@ function updateButtons(tree, account) {
 
   // check for disabled preferences on the account buttons.  
   //  Not currently handled by WSM or the main loop yet since these buttons aren't
   //  under the IFRAME
   var addAccountButton = document.getElementById("addAccountButton");
   var removeButton = document.getElementById("removeButton");
   var setDefaultButton = document.getElementById("setDefaultButton");
 
-  if (!addAccountButton && !removeButton && !setDefaultButton)
+  if (!addAccountButton && !removeButton && !setDefaultButton)
     return; // tb isn't useing these anymore
 
   var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
                              .getService(Components.interfaces.nsIPrefBranch);
   if (prefBranch.prefIsLocked(addAccountButton.getAttribute("prefstring")))
     canCreate = false;
   if (prefBranch.prefIsLocked(setDefaultButton.getAttribute("prefstring")))
     canSetDefault = false;
@@ -716,55 +736,61 @@ function setEnabled(control, enabled)
     control.removeAttribute("disabled");
   else
     control.setAttribute("disabled", true);
 }
 
 // Called when someone clicks on an account. Figure out context by what they
 // clicked on. This is also called when an account is removed. In this case,
 // nothing is selected.
-function onAccountTreeSelect()
+function onAccountTreeSelect(pageId, account)
 {
-  var tree = document.getElementById("accounttree");
+  let tree = document.getElementById("accounttree");
 
-  if (tree.view.selection.count < 1)
-    return null;
-  var node = tree.contentView.getItemAtIndex(tree.currentIndex);
-  var account = node._account;
-  var pageId = node.getAttribute('PageTag')
+  let changeView = pageId && account;
+  if (!changeView) {
+    if (tree.view.selection.count < 1)
+      return null;
+
+    let node = tree.contentView.getItemAtIndex(tree.currentIndex);
+    account = node._account;
+    pageId = node.getAttribute("PageTag")
+  }
 
   if (pageId == currentPageId && account == currentAccount)
     return;
 
   // check if user/host names have been changed
   checkUserServerChanges(false);
 
   if (gSmtpHostNameIsIllegal) {
     gSmtpHostNameIsIllegal = false;
-    selectServer(currentAccount, currentPageId);
+    selectServer(currentAccount.incomingServer, currentPageId);
     return;
   }
 
   // save the previous page
   savePage(currentAccount);
 
-  var changeAccount = (account != currentAccount);
-  // loading a complete different page
+  let changeAccount = (account != currentAccount);
+
+  if (changeView)
+    selectServer(account.incomingServer, pageId);
+
   if (pageId != currentPageId) {
+    // loading a complete different page
 
     // prevent overwriting with bad stuff
     currentAccount = currentPageId = null;
 
     pendingAccount = account;
-    pendingPageId=pageId;
+    pendingPageId = pageId;
     loadPage(pageId);
-  }
-
-  // same page, different server
-  else if (changeAccount) {
+  } else if (changeAccount) {
+    // same page, different server
     restorePage(pageId, account);
   }
 
   if (changeAccount)
     updateButtons(tree, account);
 }
 
 // page has loaded
--- a/mailnews/base/prefs/content/AccountManager.xul
+++ b/mailnews/base/prefs/content/AccountManager.xul
@@ -18,17 +18,17 @@
 <script type="application/javascript" src="chrome://messenger/content/amUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/accountUtils.js"/>
 <script type="application/javascript" src="chrome://messenger/content/am-prefs.js"/>
 <script type="application/javascript" src="chrome://messenger/content/AccountManager.js"/>
 <script type="application/javascript" src="chrome://messenger/content/am-help.js"/>
 
   <hbox flex="1">
     <vbox style="&accountTree.width;">
-      <tree flex="1" onselect="onAccountTreeSelect()" id="accounttree"
+      <tree flex="1" onselect="onAccountTreeSelect(null, null);" id="accounttree"
             seltype="single" hidecolumnpicker="true">
         <treecols>
           <treecol id="AccountCol" flex="1" primary="true" hideheader="true"/>
         </treecols>
         <treechildren id="account-tree-children"/>
       </tree>
 
 #ifdef MOZ_THUNDERBIRD
--- a/suite/locales/en-US/chrome/mailnews/pref/prefs.properties
+++ b/suite/locales/en-US/chrome/mailnews/pref/prefs.properties
@@ -39,16 +39,18 @@
 #
 # The following are used by the Account Wizard
 #
 enterValidEmail=Please enter a valid email address.
 accountExists=A mail or newsgroup account with the same user name and server name already exists. Click Back and enter a different server name, or click Cancel.
 modifiedAccountExists=An account with that user name and server name already exists. Please enter a different user name and/or server name.
 userNameChanged=Your User Name has been updated. You may also need to update your Email Address and/or User Name associated with this account.
 serverNameChanged=The server name setting has changed. Please verify that any folders used by filters exist on the new server.
+# LOCALIZATION NOTE (junkSettingsBroken): %1$S is the account name
+junkSettingsBroken=The Junk settings on account "%1$S" have a possible problem. Would you like to review them before saving Account Settings?
 # LOCALIZATION NOTE (localDirectoryChanged): %1$S is program name (&brandShortName;)
 localDirectoryChanged=%1$S needs to restart now to apply the change to the Local directory setting.
 localDirectoryRestart=Restart
 serverNameEmpty=Neither the server name nor the user name can be empty.
 # if the user chooses to cancel the wizard when no accounts are there throw a message
 # LOCALIZATION NOTE (cancelWizard)
 # do not localize "\n\n"
 cancelWizard=Are you sure you want to exit the Account Wizard?\n\nIf you exit, any information you have entered will be lost and the account will not be created.