From d2eb40a48d41a2e19da63be9293bfee01fa65c06 Mon Sep 17 00:00:00 2001 From: "racham%netscape.com" Date: Mon, 7 Jan 2002 07:06:52 +0000 Subject: [PATCH] Fixing bug 100414. Make sure that an account is created only when server and identity info is avialable in the migration process. r=mscott, sr=sspitzer git-svn-id: svn://10.0.0.236/trunk@111475 18797224-902f-48f8-a5cc-f745e15eee43 --- .../mailnews/base/src/nsMessengerMigrator.cpp | 73 ++++++++++--------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp index 84038333fd9..d0d9b822098 100644 --- a/mozilla/mailnews/base/src/nsMessengerMigrator.cpp +++ b/mozilla/mailnews/base/src/nsMessengerMigrator.cpp @@ -508,11 +508,6 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating) do_GetService(kMsgAccountManagerCID, &rv); if (NS_FAILED(rv)) return rv; - // create the account - nsCOMPtr account; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - // create the server nsCOMPtr server; rv = accountManager->CreateIncomingServer(LOCAL_MAIL_FAKE_USER_NAME, @@ -594,6 +589,12 @@ nsMessengerMigrator::CreateLocalMailAccount(PRBool migrating) } } + // Create an account when valid server values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; + // notice, no identity for local mail // hook the server to the account // after we set the server's local path @@ -1092,11 +1093,6 @@ nsMessengerMigrator::MigrateLocalMailAccount() do_GetService(kMsgAccountManagerCID, &rv); if (NS_FAILED(rv)) return rv; - // create the account - nsCOMPtr account; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - // create the server // "none" is the type we use for migrating 4.x "Local Mail" nsCOMPtr server; @@ -1186,6 +1182,12 @@ nsMessengerMigrator::MigrateLocalMailAccount() rv = noneServer->CopyDefaultMessages("Templates",mailDirSpec); if (NS_FAILED(rv)) return rv; + // Create an account when valid server values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; + // notice, no identity for local mail // hook the server to the account // after we set the server's local path @@ -1206,16 +1208,12 @@ nsMessengerMigrator::MigrateMovemailAccount(nsIMsgIdentity *identity) { nsresult rv; - nsCOMPtr account; nsCOMPtr server; nsCOMPtr accountManager = do_GetService(kMsgAccountManagerCID, &rv); if (NS_FAILED(rv)) return rv; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - // get the pop username // movemail used the pop username in 4.x nsXPIDLCString username; @@ -1285,6 +1283,12 @@ nsMessengerMigrator::MigrateMovemailAccount(nsIMsgIdentity *identity) if (!dirExists) { mailDir->CreateDir(); } + + // Create an account when valid server and identity values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; // hook the server to the account // before setting the copies and folder prefs @@ -1323,13 +1327,8 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity) do_GetService(kMsgAccountManagerCID, &rv); if (NS_FAILED(rv)) return rv; - nsCOMPtr account; nsCOMPtr server; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - - // get the pop username nsXPIDLCString username; rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, getter_Copies(username)); @@ -1445,10 +1444,6 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity) rv = SetSendLaterUriPref(server); if (NS_FAILED(rv)) return rv; - // we could only have one pop account in 4.x, so we make it the default in 5.0 - rv = accountManager->SetDefaultAccount(account); - NS_ENSURE_SUCCESS(rv, rv); - // Set check for new mail option for default account to TRUE rv = server->SetLoginAtStartUp(PR_TRUE); @@ -1457,6 +1452,12 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity) rv = accountManager->CreateIdentity(getter_AddRefs(copied_identity)); if (NS_FAILED(rv)) return rv; + // Create an account when valid server and identity values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; + // hook the server to the account // before setting the copies and folder prefs // (see bug #31904) @@ -1465,6 +1466,10 @@ nsMessengerMigrator::MigratePopAccount(nsIMsgIdentity *identity) account->SetIncomingServer(server); account->AddIdentity(copied_identity); + // we could only have one pop account in 4.x, so we make it the default in 5.0 + rv = accountManager->SetDefaultAccount(account); + NS_ENSURE_SUCCESS(rv, rv); + // make this new identity a copy of the identity // that we created out of the 4.x prefs rv = copied_identity->Copy(identity); @@ -1589,11 +1594,6 @@ nsMessengerMigrator::MigrateImapAccount(nsIMsgIdentity *identity, const char *ho if (!hostAndPort) return NS_ERROR_NULL_POINTER; - // create the account - nsCOMPtr account; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - // get the old username nsXPIDLCString username; char *imapUsernamePref = @@ -1739,6 +1739,12 @@ nsMessengerMigrator::MigrateImapAccount(nsIMsgIdentity *identity, const char *ho rv = accountManager->CreateIdentity(getter_AddRefs(copied_identity)); if (NS_FAILED(rv)) return rv; + // Create an account when valid server and identity values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; + // hook the server to the account // before setting the copies and folder prefs // (see bug #31904) @@ -2265,11 +2271,6 @@ nsMessengerMigrator::MigrateNewsAccount(nsIMsgIdentity *identity, const char *ho if (!identity) return NS_ERROR_NULL_POINTER; if (!hostAndPort) return NS_ERROR_NULL_POINTER; - // create the account - nsCOMPtr account; - rv = accountManager->CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - PRInt32 port=-1; nsCAutoString hostname(hostAndPort); PRInt32 colonPos = hostname.FindChar(':'); @@ -2393,6 +2394,12 @@ nsMessengerMigrator::MigrateNewsAccount(nsIMsgIdentity *identity, const char *ho rv = accountManager->CreateIdentity(getter_AddRefs(copied_identity)); if (NS_FAILED(rv)) return rv; + // Create an account when valid server and identity values are established. + // This will keep the status of accounts sane by avoiding the addition of incomplete accounts. + nsCOMPtr account; + rv = accountManager->CreateAccount(getter_AddRefs(account)); + if (NS_FAILED(rv)) return rv; + // hook the server to the account // before setting the copies and folder prefs // (see bug #31904)