m_accounts->RemoveElement(aAccount);   if (m_defaultAccount.get() == aAccount) { SetDefaultAccount(nsnull); }     nsCOMPtr<nsIMsgIncomingServer> server; rv = aAccount->GetIncomingServer(getter_AddRefs(server)); if (NS_SUCCEEDED(rv) && server) { nsXPIDLCString serverKey; rv = server->GetKey(getter_Copies(serverKey)); NS_ENSURE_SUCCESS(rv,rv);  LogoutOfServer(server);   if (m_lastFindServerResult) { nsXPIDLCString cachedServerKey; rv = m_lastFindServerResult->GetKey(getter_Copies(cachedServerKey)); NS_ENSURE_SUCCESS(rv,rv);  if (!nsCRT::strcmp((const char *)serverKey,(const char *)cachedServerKey)) { rv = SetLastServerFound(nsnull,"","",""); NS_ENSURE_SUCCESS(rv,rv); } }  nsCStringKey hashKey(serverKey);  nsIMsgIncomingServer* removedServer = (nsIMsgIncomingServer*) m_incomingServers.Remove(&hashKey);     NS_IF_RELEASE(removedServer);  nsCOMPtr<nsIFolder> rootFolder; server->GetRootFolder(getter_AddRefs(rootFolder)); nsCOMPtr<nsISupportsArray> allDescendents; NS_NewISupportsArray(getter_AddRefs(allDescendents)); rootFolder->ListDescendents(allDescendents); PRUint32 cnt =0; rv = allDescendents->Count(&cnt); NS_ENSURE_SUCCESS(rv,rv); for (PRUint32 i=0; i< cnt;i++) { nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allDescendents, i, &rv); folder->ForceDBClosed(); }  mFolderListeners->EnumerateForwards(removeListenerFromFolder, (void*)rootFolder);  NotifyServerUnloaded(server);   rv = server->RemoveFiles(); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove the files associated with server");     server->ClearAllValues();  rootFolder->Shutdown(PR_TRUE); } nsCOMPtr<nsISupportsArray> identityArray;  rv = aAccount->GetIdentities(getter_AddRefs(identityArray)); if (NS_SUCCEEDED(rv)) {  PRUint32 count=0; identityArray->Count(&count);  PRUint32 i; for (i=0; i<count; i++) { nsCOMPtr<nsIMsgIdentity> identity; rv = identityArray->QueryElementAt(i, NS_GET_IID(nsIMsgIdentity), (void **)getter_AddRefs(identity)); if (NS_SUCCEEDED(rv))   identity->ClearAllValues(); }  }  aAccount->ClearAllValues();
nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount){  nsresult rv;  rv = LoadAccounts();  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  return NS_OK;}