server->SetKey(serverStr);  account->SetIncomingServer(server);
nsCOMPtr<nsIMsgIncomingServer> server; rv = createKeyedServer(serverStr, "imap", getter_AddRefs(server)); if (NS_FAILED(rv)) return rv;     char identityStr[BUF_STR_LEN]; PR_snprintf(identityStr,BUF_STR_LEN,"identity%d",accountNum);
nsMsgAccountManager::MigrateImapAccount(nsIMsgIdentity *identity, const char *hostname, PRInt32 accountNum){  nsresult rv;  PRInt32 oldint;  PRBool oldbool;  if (!hostname) return NS_ERROR_NULL_POINTER;  if (accountNum < 1) return NS_ERROR_FAILURE;    nsCOMPtr<nsIMsgAccount> account;  nsCOMPtr<nsIMsgIncomingServer> server;    rv = nsComponentManager::CreateInstance(kMsgAccountCID,                                          nsnull,                                          nsCOMTypeInfo<nsIMsgAccount>::GetIID(),                                          getter_AddRefs(account));  if (NS_FAILED(rv)) return rv;  rv = nsComponentManager::CreateInstance(NS_MSGINCOMINGSERVER_PROGID_PREFIX "imap",                                          nsnull,                                          nsCOMTypeInfo<nsIMsgIncomingServer>::GetIID(),                                          getter_AddRefs(server));  if (NS_FAILED(rv)) return rv;  char accountStr[BUF_STR_LEN];  char serverStr[BUF_STR_LEN];  char identityStr[BUF_STR_LEN];  PR_snprintf(accountStr,BUF_STR_LEN,"account%d",accountNum);#ifdef DEBUG_ACCOUNTMANAGER  printf("account str = %s\n",accountStr);#endif  account->SetKey(accountStr);  PR_snprintf(serverStr,BUF_STR_LEN,"server%d",accountNum);#ifdef DEBUG_ACCOUNTMANAGER  printf("server str = %s\n",serverStr);#endif  server->SetKey(serverStr);    account->SetIncomingServer(server);  nsCOMPtr<nsIMsgIdentity> copied_identity;  rv = nsComponentManager::CreateInstance(kMsgIdentityCID,                                            nsnull,                                            nsCOMTypeInfo<nsIMsgIdentity>::GetIID(),                                            getter_AddRefs(copied_identity));  if (NS_FAILED(rv)) return rv;  PR_snprintf(identityStr,BUF_STR_LEN,"identity%d",accountNum);  copied_identity->SetKey(identityStr);  rv = CopyIdentity(identity,copied_identity);  if (NS_FAILED(rv)) return rv;  account->AddIdentity(copied_identity);  // adds account to the hash table.  AddAccount(account);  // now upgrade all the prefs  char *oldstr = nsnull;  nsFileSpec profileDir;    NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv);  if (NS_FAILED(rv)) return NS_ERROR_FAILURE;    rv = profile->GetCurrentProfileDir(&profileDir);  if (NS_FAILED(rv)) return NS_ERROR_FAILURE;    // some of this ought to be moved out into the IMAP implementation  nsCOMPtr<nsIImapIncomingServer> imapServer;  imapServer = do_QueryInterface(server, &rv);  if (NS_FAILED(rv)) {    return rv;  }    server->SetType("imap");  server->SetHostName((char *)hostname);  char prefName[BUF_STR_LEN];  PR_snprintf(prefName, BUF_STR_LEN, "mail.imap.server.%s.userName",hostname);  rv = m_prefs->CopyCharPref(prefName, &oldstr);  if (NS_SUCCEEDED(rv)) {    server->SetUsername(oldstr);    PR_FREEIF(oldstr);    oldstr = nsnull;  }#ifdef CAN_UPGRADE_4x_PASSWORDS  // upgrade the password  PR_snprintf(prefName, BUF_STR_LEN, "mail.imap.server.%s.password",hostname);  rv = m_prefs->CopyCharPref(prefName, &oldstr);  if (NS_SUCCEEDED(rv)) {    server->SetPassword("enter your clear text password here");    PR_FREEIF(oldstr);    oldstr = nsnull;  }#else  rv = SetPasswordForServer(server);  if (NS_FAILED(rv)) return rv;#endif /* CAN_UPGRADE_4x_PASSWORDS */  // upgrade the biff prefs  PR_snprintf(prefName, BUF_STR_LEN, "mail.imap.server.%s.check_new_mail",hostname);  rv = m_prefs->GetBoolPref(prefName, &oldbool);  if (NS_SUCCEEDED(rv)) {    server->SetDoBiff(oldbool);  }  PR_snprintf(prefName, BUF_STR_LEN, "mail.imap.server.%s.check_time",hostname);  rv = m_prefs->GetIntPref(prefName, &oldint);  if (NS_SUCCEEDED(rv)) {    server->SetBiffMinutes(oldint);  }    // create the directory structure for this pop account  // under <profile dir>/Mail/<hostname>  nsCOMPtr <nsIFileSpec> imapMailDir;  nsFileSpec dir(profileDir);  PRBool dirExists;    // turn profileDir into the mail dir.  dir += "ImapMail";  if (!dir.Exists()) {    dir.CreateDir();  }  dir += hostname;    rv = NS_NewFileSpecWithSpec(dir, getter_AddRefs(imapMailDir));  if (NS_FAILED(rv)) return rv;  char *str = nsnull;  imapMailDir->GetNativePath(&str);  if (str && *str) {    server->SetLocalPath(str);    PR_FREEIF(str);    str = nsnull;  }    rv = imapMailDir->Exists(&dirExists);  if (NS_FAILED(rv)) return rv;    if (!dirExists) {    imapMailDir->CreateDir();  }    return NS_OK;}