nsCOMPtr<nsISupports> element; rv = m_accounts->GetElementAt(0, getter_AddRefs(element));
nsXPIDLCString defaultKey; rv = m_prefs->CopyCharPref(PREF_MAIL_ACCOUNTMANAGER_DEFAULTACCOUNT, getter_Copies(defaultKey));  if (NS_SUCCEEDED(rv)) { GetAccount(defaultKey, getter_AddRefs(m_defaultAccount)); } else { PRUint32 index; PRBool foundValidDefaultAccount = PR_FALSE; for (index = 0; index < count; index++) { nsCOMPtr<nsIMsgAccount> aAccount; rv = m_accounts->QueryElementAt(index, NS_GET_IID(nsIMsgAccount), (void **)getter_AddRefs(aAccount)); if (NS_SUCCEEDED(rv)) {  nsCOMPtr <nsIMsgIncomingServer> server; rv = aAccount->GetIncomingServer(getter_AddRefs(server)); NS_ENSURE_SUCCESS(rv,rv);  PRBool canBeDefaultServer = PR_FALSE; if (server) server->GetCanBeDefaultServer(&canBeDefaultServer);    if (canBeDefaultServer) { SetDefaultAccount(aAccount); foundValidDefaultAccount = PR_TRUE; break; } } } if (!foundValidDefaultAccount) {   nsCOMPtr<nsIMsgAccount> firstAccount; rv = m_accounts->QueryElementAt(0, NS_GET_IID(nsIMsgAccount), (void **)getter_AddRefs(firstAccount));
nsMsgAccountManager::GetDefaultAccount(nsIMsgAccount * *aDefaultAccount){  nsresult rv;  rv = LoadAccounts();  if (NS_FAILED(rv)) return rv;    if (!aDefaultAccount) return NS_ERROR_NULL_POINTER;  if (!m_defaultAccount) {    PRUint32 count;    m_accounts->Count(&count);#ifdef DEBUG_ACCOUNTMANAGER    printf("There are %d accounts\n", count);#endif    if (count == 0) {      *aDefaultAccount=nsnull;      return NS_ERROR_FAILURE;    }    nsCOMPtr<nsISupports> element;    rv = m_accounts->GetElementAt(0, getter_AddRefs(element));    if (NS_SUCCEEDED(rv)) {      m_defaultAccount = do_QueryInterface(element, &rv);      NS_ASSERTION(NS_SUCCEEDED(rv), "GetDefaultAccount(): bad array");    }  }    *aDefaultAccount = m_defaultAccount;  NS_IF_ADDREF(*aDefaultAccount);  return NS_OK;}