diff --git a/mailnews/base/prefs/resources/content/am-server.js b/mailnews/base/prefs/resources/content/am-server.js index d2bd252d94c..be5ae9dd353 100644 --- a/mailnews/base/prefs/resources/content/am-server.js +++ b/mailnews/base/prefs/resources/content/am-server.js @@ -186,6 +186,12 @@ function onAdvanced() var identity = account.defaultIdentity; var accountManager = Components.classes["@mozilla.org/messenger/account-manager;1"].getService(Components.interfaces.nsIMsgAccountManager); account = accountManager.getAccount(serverSettings.deferredToAccount); + if (!account) + { + throw "UNEXPECTED: deferredToAccount '" + + serverSettings.deferredToAccount + "' not found!"; + } + if (identity.fccFolder == (pop3Server.serverURI + "/Sent")) identity.fccFolder = account.incomingServer.serverURI + "/Sent"; diff --git a/mailnews/base/public/nsIMsgAccountManager.idl b/mailnews/base/public/nsIMsgAccountManager.idl index bdd833de33a..a34c9f798e7 100644 --- a/mailnews/base/public/nsIMsgAccountManager.idl +++ b/mailnews/base/public/nsIMsgAccountManager.idl @@ -51,6 +51,9 @@ interface nsIFolderListener; interface nsIMsgAccountManager : nsISupports { nsIMsgAccount createAccount(); + /* + * Return the account with the provided key, or null if none found. + */ nsIMsgAccount getAccount(in string key); void removeAccount(in nsIMsgAccount account); diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index 62c8bc6dbcd..afb51de70d7 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * @@ -788,9 +788,10 @@ nsMsgAccountManager::GetDefaultAccount(nsIMsgAccount * *aDefaultAccount) nsXPIDLCString defaultKey; rv = m_prefs->GetCharPref(PREF_MAIL_ACCOUNTMANAGER_DEFAULTACCOUNT, getter_Copies(defaultKey)); - if (NS_SUCCEEDED(rv)) { + if (NS_SUCCEEDED(rv)) GetAccount(defaultKey, getter_AddRefs(m_defaultAccount)); - } else { + + if (!m_defaultAccount) { PRUint32 index; PRBool foundValidDefaultAccount = PR_FALSE; for (index = 0; index < count; index++) { @@ -816,12 +817,14 @@ nsMsgAccountManager::GetDefaultAccount(nsIMsgAccount * *aDefaultAccount) } } } + if (!foundValidDefaultAccount) { // get the first account and use it. // we need to fix this scenario. + NS_WARNING("No valid default account found, just using first (FIXME)"); nsCOMPtr firstAccount; - rv = m_accounts->QueryElementAt(0, NS_GET_IID(nsIMsgAccount), - (void **)getter_AddRefs(firstAccount)); + m_accounts->QueryElementAt(0, NS_GET_IID(nsIMsgAccount), + (void **)getter_AddRefs(firstAccount)); SetDefaultAccount(firstAccount); } @@ -1434,36 +1437,40 @@ nsMsgAccountManager::LoadAccounts() if (!accountList || !accountList[0]) return NS_OK; - /* parse accountList and run loadAccount on each string, comma-separated */ - nsCOMPtr account; - char *newStr; - char *rest = accountList.BeginWriting(); - nsCAutoString str; - - char *token = nsCRT::strtok(rest, ",", &newStr); - while (token) { - str = token; - str.StripWhitespace(); + /* parse accountList and run loadAccount on each string, comma-separated */ + nsCOMPtr account; + char *newStr; + char *rest = accountList.BeginWriting(); + nsCAutoString str; + + for (char *token = nsCRT::strtok(rest, ",", &newStr); + token; + token = nsCRT::strtok(newStr, ",", &newStr)) + { + str = token; + str.StripWhitespace(); - if (!str.IsEmpty()) - rv = GetAccount(str.get(), getter_AddRefs(account)); - - // force load of accounts (need to find a better way to do this - nsCOMPtr identities; - account->GetIdentities(getter_AddRefs(identities)); - - nsCOMPtr server; - account->GetIncomingServer(getter_AddRefs(server)); - - token = nsCRT::strtok(newStr, ",", &newStr); + if (str.IsEmpty() || + NS_FAILED(createKeyedAccount(str.get(), getter_AddRefs(account))) || + !account) { + NS_WARNING("unexpected entry in account list; prefs corrupt?"); + continue; } - nsCOMPtr mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + // force load of accounts (need to find a better way to do this) + nsCOMPtr identities; + account->GetIdentities(getter_AddRefs(identities)); + + nsCOMPtr server; + account->GetIncomingServer(getter_AddRefs(server)); + } - if (NS_SUCCEEDED(rv)) - mailSession->AddFolderListener(this, nsIFolderListener::added | nsIFolderListener::removed); - /* finished loading accounts */ - return NS_OK; + nsCOMPtr mailSession = do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv); + + if (NS_SUCCEEDED(rv)) + mailSession->AddFolderListener(this, nsIFolderListener::added | nsIFolderListener::removed); + /* finished loading accounts */ + return NS_OK; } PRBool @@ -1666,13 +1673,13 @@ nsMsgAccountManager::GetAccount(const char* key, m_accounts->EnumerateForwards(findAccountByKey, (void *)&findEntry); - if (findEntry.account) { + if (findEntry.account) NS_ADDREF(*_retval = findEntry.account); - return NS_OK; - } + else + *_retval = nsnull; // not found, create on demand - return createKeyedAccount(key, _retval); + return NS_OK; } nsresult @@ -2735,7 +2742,7 @@ NS_IMETHODIMP VirtualFolderChangeListener::OnHdrDeleted(nsIMsgDBHdr *aHdrDeleted nsCOMPtr virtDatabase; nsCOMPtr dbFolderInfo; - nsresult rv = m_virtualFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo), getter_AddRefs(virtDatabase)); + rv = m_virtualFolder->GetDBFolderInfoAndDB(getter_AddRefs(dbFolderInfo), getter_AddRefs(virtDatabase)); PRBool msgHdrIsRead; aHdrDeleted->GetIsRead(&msgHdrIsRead); if (!msgHdrIsRead) @@ -2961,7 +2968,7 @@ NS_IMETHODIMP nsMsgAccountManager::SaveVirtualFolders() { PRUint32 count = 0; allServers->Count(&count); - PRInt32 i; + PRUint32 i; nsCOMPtr outputStream; for (i = 0; i < count; i++) { @@ -2988,7 +2995,7 @@ NS_IMETHODIMP nsMsgAccountManager::SaveVirtualFolders() WriteLineToOutputStream("version=", "1", outputStream); } - for (PRInt32 folderIndex = 0; folderIndex < vfCount; folderIndex++) + for (PRUint32 folderIndex = 0; folderIndex < vfCount; folderIndex++) { nsCOMPtr folderRes (do_QueryElementAt(virtualFolders, folderIndex)); nsCOMPtr msgFolder = do_QueryInterface(folderRes); diff --git a/mailnews/compose/resources/content/MsgComposeCommands.js b/mailnews/compose/resources/content/MsgComposeCommands.js index 556fed0351a..bc1e3022bfd 100644 --- a/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mailnews/compose/resources/content/MsgComposeCommands.js @@ -1673,6 +1673,11 @@ function GenericSendMessage( msgType ) // check if the user tries to send a message to a newsgroup through a mail account var currentAccountKey = getCurrentAccountKey(); var account = gAccountManager.getAccount(currentAccountKey); + if (!account) + { + throw "UNEXPECTED: currentAccountKey '" + currentAccountKey + + "' has no matching account!"; + } var servertype = account.incomingServer.type; if (servertype != "nntp" && msgCompFields.newsgroups != "")