From 5d21f962db500a22697221d985709d5f24fa27f5 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Sun, 10 Nov 2019 22:51:10 -0500 Subject: Bug 342632 - Allow defaultAccount to return success with nullptr result when there is no usable account. Tag #1273 --- mailnews/base/prefs/content/AccountManager.js | 20 ++++---------------- mailnews/base/prefs/content/AccountWizard.js | 26 +++++++++++--------------- 2 files changed, 15 insertions(+), 31 deletions(-) (limited to 'mailnews/base/prefs') diff --git a/mailnews/base/prefs/content/AccountManager.js b/mailnews/base/prefs/content/AccountManager.js index 83117f4ad..81fb115de 100644 --- a/mailnews/base/prefs/content/AccountManager.js +++ b/mailnews/base/prefs/content/AccountManager.js @@ -704,7 +704,7 @@ function onSetDefault(event) { if (event.target.getAttribute("disabled") == "true") return; - let previousDefault = getDefaultAccount(); + let previousDefault = MailServices.accounts.defaultAccount; MailServices.accounts.defaultAccount = currentAccount; markDefaultServer(currentAccount, previousDefault); @@ -771,7 +771,7 @@ function onRemoveAccount(event) { // Either the default account was deleted so there is a new one // or the default account was not changed. Either way, there is // no need to unmark the old one. - markDefaultServer(getDefaultAccount(), null); + markDefaultServer(MailServices.accounts.defaultAccount, null); } function saveAccount(accountValues, account) @@ -928,7 +928,7 @@ function updateItems(tree, account, addAccountItem, setDefaultItem, removeItem) // problem. Either way, we don't want the user to act on it. let server = account.incomingServer; - if (account != getDefaultAccount() && + if (account != MailServices.accounts.defaultAccount && server.canBeDefaultServer && account.identities.length > 0) canSetDefault = true; @@ -1378,18 +1378,6 @@ function getCurrentAccount() return currentAccount; } -/** - * Returns the default account without throwing exception if there is none. - * The account manager can be opened even if there are no account yet. - */ -function getDefaultAccount() { - try { - return MailServices.accounts.defaultAccount; - } catch (e) { - return null; // No default account yet. - } -} - /** * Get the array of persisted form elements for the given page. */ @@ -1605,7 +1593,7 @@ var gAccountTree = { treeitem._account = account; } - markDefaultServer(getDefaultAccount(), null); + markDefaultServer(MailServices.accounts.defaultAccount, null); // Now add the outgoing server node. var treeitem = document.createElement("treeitem"); diff --git a/mailnews/base/prefs/content/AccountWizard.js b/mailnews/base/prefs/content/AccountWizard.js index 1903cbc88..90d729418 100644 --- a/mailnews/base/prefs/content/AccountWizard.js +++ b/mailnews/base/prefs/content/AccountWizard.js @@ -53,7 +53,9 @@ var gPrefsBundle, gMessengerBundle; // the current nsIMsgAccount var gCurrentAccount; -// default account +// The default account before we create a new account. +// We need to store this as just asking for the default account may switch +// it to the newly created one if there was none before. var gDefaultAccount; // the current associative array that @@ -85,14 +87,9 @@ function onAccountWizardLoad() { checkForInvalidAccounts(); - try { - gDefaultAccount = MailServices.accounts.defaultAccount; - } - catch (ex) { - // no default account, this is expected the first time you launch mail - // on a new profile - gDefaultAccount = null; - } + // It is fine if there is no default account, this is expected the first + // time you launch mail on a new profile. + gDefaultAccount = MailServices.accounts.defaultAccount; // Set default value for global inbox checkbox var checkGlobalInbox = document.getElementById("deferStorage"); @@ -799,8 +796,7 @@ function getPreConfigDataForAccount(account) function AccountToAccountData(account, defaultAccountData) { - dump("AccountToAccountData(" + account + ", " + - defaultAccountData + ")\n"); + dump("AccountToAccountData(" + account + ", " + defaultAccountData + ")\n"); var accountData = defaultAccountData; if (!accountData) accountData = new Object; @@ -966,10 +962,10 @@ function onFlush() { */ function EnableCheckMailAtStartUpIfNeeded(newAccount) { - // Check if default account exists and if that account is alllowed to be - // a default account. If no such account, make this one as the default account + // Check if default account existed. + // If no such account, make this one the default account // and turn on the new mail check at startup for the current account - if (!(gDefaultAccount && gDefaultAccount.incomingServer.canBeDefaultServer)) { + if (!gDefaultAccount) { MailServices.accounts.defaultAccount = newAccount; newAccount.incomingServer.loginAtStartUp = true; newAccount.incomingServer.downloadOnBiff = true; @@ -981,7 +977,7 @@ function SetSmtpRequiresUsernameAttribute(accountData) // If this is the default server, time to set the smtp user name // Set the generic attribute for requiring user name for smtp to true. // ISPs can override the pref via rdf files. - if (!(gDefaultAccount && gDefaultAccount.incomingServer.canBeDefaultServer)) { + if (!gDefaultAccount) { accountData.smtpRequiresUsername = true; } } -- cgit v1.2.3