зеркало из https://github.com/mozilla/pjs.git
backend part of fix for #14798, r=mscott
This commit is contained in:
Родитель
dfb859e472
Коммит
a56b50c8f6
|
@ -700,14 +700,24 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount)
|
|||
nsresult rv;
|
||||
rv = LoadAccounts();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// order is important!
|
||||
// remove it from the prefs first
|
||||
nsXPIDLCString key;
|
||||
rv = aAccount->GetKey(getter_Copies(key));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = m_accounts->RemoveElement(aAccount);
|
||||
|
||||
#ifdef DEBUG_alecf
|
||||
if (NS_FAILED(rv))
|
||||
printf("error removing account. perhaps we need a NS_STATIC_CAST?\n");
|
||||
#endif
|
||||
rv = removeKeyedAccount(key);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// we were able to save the new prefs (i.e. not locked) so now remove it
|
||||
// from the account manager... ignore the error though, because the only
|
||||
// possible problem is that it wasn't in the hash table anyway... and if
|
||||
// so, it doesn't matter.
|
||||
m_accounts->RemoveElement(aAccount);
|
||||
|
||||
// XXX - need to figure out if this is the last time this server is
|
||||
// being used, and only send notification then.
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
rv = aAccount->GetIncomingServer(getter_AddRefs(server));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
|
@ -717,6 +727,51 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// remove the account with the given key.
|
||||
// note that this does NOT remove any of the related prefs
|
||||
// (like the server, identity, etc)
|
||||
nsresult
|
||||
nsMsgAccountManager::removeKeyedAccount(const char *key)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString accountList;
|
||||
rv = m_prefs->CopyCharPref(PREF_MAIL_ACCOUNTMANAGER_ACCOUNTS,
|
||||
getter_Copies(accountList));
|
||||
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// reconstruct the new account list, re-adding all accounts except
|
||||
// the one with 'key'
|
||||
nsCString newAccountList;
|
||||
char *rest = NS_CONST_CAST(char *,(const char*)accountList);
|
||||
|
||||
char *token = nsCRT::strtok(rest, ",", &rest);
|
||||
while (token) {
|
||||
nsCAutoString testKey(token);
|
||||
testKey.StripWhitespace();
|
||||
|
||||
// re-add the candidate key only if it's not the key we're looking for
|
||||
if (!testKey.IsEmpty() && !testKey.Equals(key)) {
|
||||
if (!newAccountList.IsEmpty())
|
||||
newAccountList += ',';
|
||||
newAccountList += testKey;
|
||||
}
|
||||
|
||||
token = nsCRT::strtok(rest, ",", &rest);
|
||||
}
|
||||
|
||||
// now write the new account list back to the prefs
|
||||
rv = m_prefs->SetCharPref(PREF_MAIL_ACCOUNTMANAGER_ACCOUNTS,
|
||||
newAccountList.GetBuffer());
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* get the default account. If no default account, pick the first account */
|
||||
NS_IMETHODIMP
|
||||
nsMsgAccountManager::GetDefaultAccount(nsIMsgAccount * *aDefaultAccount)
|
||||
|
@ -1044,7 +1099,7 @@ nsMsgAccountManager::LoadAccounts()
|
|||
nsCAutoString str;
|
||||
|
||||
token = nsCRT::strtok(rest, ",", &rest);
|
||||
while (token && *token) {
|
||||
while (token) {
|
||||
str = token;
|
||||
str.StripWhitespace();
|
||||
|
||||
|
|
|
@ -111,7 +111,10 @@ private:
|
|||
|
||||
nsresult createKeyedIdentity(const char* key,
|
||||
nsIMsgIdentity **_retval);
|
||||
|
||||
|
||||
/* internal destruction routines - fixes prefs */
|
||||
nsresult removeKeyedAccount(const char *key);
|
||||
|
||||
// hash table enumerators
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче