diff --git a/mailnews/base/build/nsMsgBaseCID.h b/mailnews/base/build/nsMsgBaseCID.h index fd44cc4aaffe..5961e633ecca 100644 --- a/mailnews/base/build/nsMsgBaseCID.h +++ b/mailnews/base/build/nsMsgBaseCID.h @@ -89,6 +89,19 @@ 0xd2876e50, 0xe62c, 0x11d2, \ {0xb7, 0xfc, 0x0, 0x80, 0x5f, 0x5, 0xff, 0xa5 }} +// +// nsMessengerMigrator +// +#define NS_MESSENGERMIGRATOR_PROGID \ + "component://netscape/messenger/migrator" + +#define NS_MESSENGERMIGRATOR_CID \ +{ /* 54818d98-1dd2-11b2-82aa-a9197f997503 */ \ + 0x54818d98, 0x1dd2, 0x11b2, \ + { 0x82, 0xaa, 0xa9, 0x19, 0x7f, 0x99, 0x75, 0x03}} + + + // // nsMsgIdentity // diff --git a/mailnews/base/build/nsMsgFactory.cpp b/mailnews/base/build/nsMsgFactory.cpp index 1c5ecc3a7fd4..c67758e900e0 100644 --- a/mailnews/base/build/nsMsgFactory.cpp +++ b/mailnews/base/build/nsMsgFactory.cpp @@ -48,6 +48,7 @@ #include "nsMsgMailSession.h" #include "nsMsgAccount.h" #include "nsMsgAccountManager.h" +#include "nsMessengerMigrator.h" #include "nsMsgIdentity.h" #include "nsMsgIncomingServer.h" #include "nsMessageViewDataSource.h" @@ -95,6 +96,8 @@ static NS_DEFINE_CID(kMsgIncomingServerCID, NS_MSGINCOMINGSERVER_CID); // account manager RDF stuff static NS_DEFINE_CID(kMsgAccountManagerDataSourceCID, NS_MSGACCOUNTMANAGERDATASOURCE_CID); +// migrator stuff +static NS_DEFINE_CID(kMessengerMigratorCID, NS_MESSENGERMIGRATOR_CID); // search and filter stuff static NS_DEFINE_CID(kMsgSearchSessionCID, NS_MSGSEARCHSESSION_CID); static NS_DEFINE_CID(kMsgFilterServiceCID, NS_MSGFILTERSERVICE_CID); @@ -127,6 +130,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsUrlListenerManager) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgMailSession, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMessenger) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgAccountManager, Init) +NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMessengerMigrator, Init) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgAccount) NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgIdentity) NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsMsgFolderDataSource, Init) @@ -165,6 +169,7 @@ protected: nsCOMPtr mMsgMailSessionFactory; nsCOMPtr mMessengerFactory; nsCOMPtr mMsgAccountManagerFactory; + nsCOMPtr mMessengerMigratorFactory; nsCOMPtr mMsgAccountFactory; nsCOMPtr mMsgIdentityFactory; nsCOMPtr mMsgFolderDataSourceFactory; @@ -213,6 +218,7 @@ void nsMsgBaseModule::Shutdown() mMsgMailSessionFactory = null_nsCOMPtr(); mMessengerFactory = null_nsCOMPtr(); mMsgAccountManagerFactory = null_nsCOMPtr(); + mMessengerMigratorFactory = null_nsCOMPtr(); mMsgAccountFactory = null_nsCOMPtr(); mMsgIdentityFactory = null_nsCOMPtr(); mMsgFolderDataSourceFactory = null_nsCOMPtr(); @@ -285,6 +291,12 @@ NS_IMETHODIMP nsMsgBaseModule::GetClassObject(nsIComponentManager *aCompMgr, rv = NS_NewGenericFactory(getter_AddRefs(mMsgAccountManagerFactory), &nsMsgAccountManagerConstructor); fact = mMsgAccountManagerFactory; } + else if (aClass.Equals(kMessengerMigratorCID)) + { + if (!mMessengerMigratorFactory) + rv = NS_NewGenericFactory(getter_AddRefs(mMessengerMigratorFactory), &nsMessengerMigratorConstructor); + fact = mMessengerMigratorFactory; + } else if (aClass.Equals(kMsgAccountCID)) { if (!mMsgAccountFactory) @@ -395,6 +407,8 @@ static Components gComponents[] = { NS_MESSENGER_PROGID }, { "Messenger Account Manager", &kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_PROGID }, + { "Messenger Migrator", &kMessengerMigratorCID, + NS_MESSENGERMIGRATOR_PROGID }, { "Messenger User Account", &kMsgAccountCID, NS_MSGACCOUNT_PROGID }, { "Messenger User Identity", &kMsgIdentityCID, diff --git a/mailnews/base/prefs/resources/content/AccountWizard.js b/mailnews/base/prefs/resources/content/AccountWizard.js index 1b48e1c6ca74..3852f9d36b65 100644 --- a/mailnews/base/prefs/resources/content/AccountWizard.js +++ b/mailnews/base/prefs/resources/content/AccountWizard.js @@ -272,7 +272,8 @@ function createAccount(hash) { if (!localMailServer) { // dump("Creating local mail account\n"); // creates a copy of the identity you pass in - am.createLocalMailAccount(identity, false); + messengerMigrator = Components.classes["component://netscape/messenger/migrator"].getService(Components.interfaces.nsIMessengerMigrator); + messengerMigrator.createLocalMailAccount(identity, false); // find the local mail server that we just created localMailServer = am.FindServer("","","none"); diff --git a/mailnews/base/public/Makefile.in b/mailnews/base/public/Makefile.in index c843efb36529..ad0be0c6f9cc 100644 --- a/mailnews/base/public/Makefile.in +++ b/mailnews/base/public/Makefile.in @@ -71,6 +71,7 @@ XPIDLSRCS = \ nsIMsgRDFDataSource.idl \ nsIIncomingServerListener.idl \ nsIMsgHdr.idl \ + nsIMessengerMigrator.idl \ $(NULL) include $(topsrcdir)/config/rules.mk diff --git a/mailnews/base/public/makefile.win b/mailnews/base/public/makefile.win index 21dae56532a6..21a31b6666a5 100644 --- a/mailnews/base/public/makefile.win +++ b/mailnews/base/public/makefile.win @@ -32,6 +32,7 @@ XPIDLSRCS = \ .\nsIMessageView.idl \ .\nsIMsgAccount.idl \ .\nsIMsgAccountManager.idl \ + .\nsIMessengerMigrator.idl \ .\nsIMsgFolder.idl \ .\nsIMsgFolderCache.idl \ .\nsIMsgFolderCacheElement.idl \ diff --git a/mailnews/base/public/nsIMsgAccountManager.idl b/mailnews/base/public/nsIMsgAccountManager.idl index 8372986b158e..442bea78cec7 100644 --- a/mailnews/base/public/nsIMsgAccountManager.idl +++ b/mailnews/base/public/nsIMsgAccountManager.idl @@ -138,14 +138,9 @@ interface nsIMsgAccountManager : nsISupports { void CloseCachedConnections(); - /* search for 4.x mailnews prefs, and migrate to 5.0 prefs */ - void UpgradePrefs(); - void AddIncomingServerListener(in nsIIncomingServerListener serverListener); void RemoveIncomingServerListener(in nsIIncomingServerListener serverListener); void NotifyServerLoaded(in nsIMsgIncomingServer server); void NotifyServerUnloaded(in nsIMsgIncomingServer server); - - void createLocalMailAccount(in nsIMsgIdentity identity, in boolean migrating); }; diff --git a/mailnews/base/resources/content/msgMail3PaneWindow.js b/mailnews/base/resources/content/msgMail3PaneWindow.js index b4d2d9310078..725f6a860c88 100644 --- a/mailnews/base/resources/content/msgMail3PaneWindow.js +++ b/mailnews/base/resources/content/msgMail3PaneWindow.js @@ -26,6 +26,7 @@ var statusFeedbackProgID = "component://netscape/messenger/statusfeedback"; var messageViewProgID = "component://netscape/messenger/messageview"; var mailSessionProgID = "component://netscape/messenger/services/session"; var accountManagerProgID = "component://netscape/messenger/account-manager"; +var messengerMigratorProgID = "component://netscape/messenger/migrator"; var prefProgID = "component://netscape/preferences"; var msgWindowProgID = "component://netscape/messenger/msgwindow"; @@ -227,8 +228,9 @@ function verifyAccounts() { if (accounts.Count() > 0) return; try { + messengerMigrator = Components.classes[messengerMigratorProgID].getService(Components.interfaces.nsIMessengerMigrator); dump("attempt to UpgradePrefs. If that fails, open the account wizard.\n"); - am.UpgradePrefs(); + messengerMigrator.UpgradePrefs(); refreshFolderPane(); } catch (ex) { diff --git a/mailnews/base/src/Makefile.in b/mailnews/base/src/Makefile.in index 2c46ddca52f1..e40673536d0d 100644 --- a/mailnews/base/src/Makefile.in +++ b/mailnews/base/src/Makefile.in @@ -53,6 +53,7 @@ CPPSRCS = \ nsMsgStatusFeedback.cpp \ nsMessageView.cpp \ nsMsgWindow.cpp \ + nsMessengerMigrator.cpp \ $(NULL) EXPORTS = \ @@ -76,6 +77,7 @@ EXPORTS = \ nsMsgStatusFeedback.h \ nsMessageView.h \ nsMsgWindow.h \ + nsMessengerMigrator.h \ $(NULL) # we don't want the shared lib, but we want to force the creation of a static lib. diff --git a/mailnews/base/src/makefile.win b/mailnews/base/src/makefile.win index 15297543a956..367fb069e030 100644 --- a/mailnews/base/src/makefile.win +++ b/mailnews/base/src/makefile.win @@ -49,6 +49,7 @@ EXPORTS= \ nsMsgStatusFeedback.h \ nsMessageView.h \ nsMsgWindow.h \ + nsMessengerMigrator.h \ $(NULL) @@ -80,6 +81,7 @@ CPP_OBJS= \ .\$(OBJDIR)\nsMsgStatusFeedback.obj \ .\$(OBJDIR)\nsMessageView.obj \ .\$(OBJDIR)\nsMsgWindow.obj \ + .\$(OBJDIR)\nsMessengerMigrator.obj \ $(NULL) diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index cacde9c6015d..047ec63bd590 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -50,21 +50,13 @@ #include "nsIMsgBiffManager.h" #include "nsIObserverService.h" -// this should eventually be moved to the pop3 server for upgrading -#include "nsIPop3IncomingServer.h" -// this should eventually be moved to the imap server for upgrading -#include "nsIImapIncomingServer.h" -// this should eventually be moved to the nntp server for upgrading -#include "nsINntpIncomingServer.h" -// this should eventually be moved to the no server for upgrading -#include "nsINoIncomingServer.h" - -#define BUF_STR_LEN 1024 - #if defined(DEBUG_alecf) || defined(DEBUG_sspitzer_) || defined(DEBUG_seth_) #define DEBUG_ACCOUNTMANAGER 1 #endif +#define PREF_MAIL_ACCOUNTMANAGER_ACCOUNTS "mail.accountmanager.accounts" +#define PREF_MAIL_SERVER_PREFIX "mail.server." + static NS_DEFINE_CID(kMsgAccountCID, NS_MSGACCOUNT_CID); static NS_DEFINE_CID(kMsgIdentityCID, NS_MSGIDENTITY_CID); static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); @@ -77,296 +69,6 @@ static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID); static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID); static NS_DEFINE_CID(kMsgFolderCacheCID, NS_MSGFOLDERCACHE_CID); -#define IMAP_SCHEMA "imap:/" -#define IMAP_SCHEMA_LENGTH 6 -#define MAILBOX_SCHEMA "mailbox:/" -#define MAILBOX_SCHEMA_LENGTH 9 - -#define POP_4X_MAIL_TYPE 0 -#define IMAP_4X_MAIL_TYPE 1 -#ifdef HAVE_MOVEMAIL -#define MOVEMAIL_4X_MAIL_TYPE 2 -#endif /* HAVE_MOVEMAIL */ - -#define PREF_MAIL_ACCOUNTMANAGER_ACCOUNTS "mail.accountmanager.accounts" -#define PREF_MAIL_SERVER_PREFIX "mail.server." - -/* TODO: do we want to clear these after migration? */ -#define PREF_NEWS_DIRECTORY "news.directory" -#define PREF_MAIL_DIRECTORY "mail.directory" -#define PREF_PREMIGRATION_MAIL_DIRECTORY "premigration.mail.directory" -#define PREF_PREMIGRATION_NEWS_DIRECTORY "premigration.news.directory" -#define PREF_IMAP_DIRECTORY "mail.imap.root_dir" -#define PREF_MAIL_DEFAULT_SENDLATER_URI "mail.default_sendlater_uri" - -/* - * TODO: these need to be put into a string bundle - * see bug #18364 - */ -#define LOCAL_MAIL_FAKE_USER_NAME "nobody" -#define LOCAL_MAIL_FAKE_HOST_NAME "Local Folders" -#ifdef HAVE_MOVEMAIL -#define MOVEMAIL_FAKE_HOST_NAME "movemail" -#endif /* HAVE_MOVEMAIL */ -#define NEW_MAIL_DIR_NAME "Mail" -#define NEW_NEWS_DIR_NAME "News" -#define NEW_IMAPMAIL_DIR_NAME "ImapMail" -#define DEFAULT_4X_DRAFTS_FOLDER_NAME "Drafts" -#define DEFAULT_4X_SENT_FOLDER_NAME "Sent" -#define DEFAULT_4X_TEMPLATES_FOLDER_NAME "Templates" -#define UNSENT_MESSAGES_FOLDER_NAME "Unsent Messages" - -/* we are going to clear these after migration */ -#define PREF_4X_MAIL_IDENTITY_USEREMAIL "mail.identity.useremail" -#define PREF_4X_MAIL_IDENTITY_USERNAME "mail.identity.username" -#define PREF_4X_MAIL_IDENTITY_REPLY_TO "mail.identity.reply_to" -#define PREF_4X_MAIL_IDENTITY_ORGANIZATION "mail.identity.organization" -#define PREF_4X_MAIL_SIGNATURE_FILE "mail.signature_file" -#define PREF_4X_MAIL_SIGNATURE_DATE "mail.signature_date" -#define PREF_4X_MAIL_COMPOSE_HTML "mail.html_compose" -#define PREF_4X_MAIL_POP_NAME "mail.pop_name" -#define PREF_4X_MAIL_REMEMBER_PASSWORD "mail.remember_password" -#define PREF_4X_MAIL_POP_PASSWORD "mail.pop_password" -#define PREF_4X_NETWORK_HOSTS_POP_SERVER "network.hosts.pop_server" -#define PREF_4X_MAIL_CHECK_NEW_MAIL "mail.check_new_mail" -#define PREF_4X_MAIL_POP3_GETS_NEW_MAIL "mail.pop3_gets_new_mail" -#define PREF_4X_MAIL_CHECK_TIME "mail.check_time" -#define PREF_4X_MAIL_LEAVE_ON_SERVER "mail.leave_on_server" -#define PREF_4X_MAIL_DELETE_MAIL_LEFT_ON_SERVER "mail.delete_mail_left_on_server" -#define PREF_4X_NETWORK_HOSTS_SMTP_SERVER "network.hosts.smtp_server" -#define PREF_4X_MAIL_SMTP_NAME "mail.smtp_name" -#define PREF_4X_MAIL_SERVER_TYPE "mail.server_type" -#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER "network.hosts.imap_servers" -#define PREF_4X_MAIL_USE_IMAP_SENTMAIL "mail.use_imap_sentmail" -#define PREF_4X_NEWS_USE_IMAP_SENTMAIL "news.use_imap_sentmail" -#define PREF_4X_MAIL_IMAP_SENTMAIL_PATH "mail.imap_sentmail_path" -#define PREF_4X_NEWS_IMAP_SENTMAIL_PATH "news.imap_sentmail_path" -#define PREF_4X_MAIL_DEFAULT_CC "mail.default_cc" -#define PREF_4X_NEWS_DEFAULT_CC "news.default_cc" -#define PREF_4X_MAIL_DEFAULT_FCC "mail.default_fcc" -#define PREF_4X_NEWS_DEFAULT_FCC "news.default_fcc" -#define PREF_4X_MAIL_USE_DEFAULT_CC "mail.use_default_cc" -#define PREF_4X_NEWS_USE_DEFAULT_CC "news.use_default_cc" -#define PREF_4X_MAIL_DEFAULT_DRAFTS "mail.default_drafts" -#define PREF_4X_MAIL_DEFAULT_TEMPLATES "mail.default_templates" -#define PREF_4X_MAIL_CC_SELF "mail.cc_self" -#define PREF_4X_NEWS_CC_SELF "news.cc_self" -#define PREF_4X_MAIL_USE_FCC "mail.use_fcc" -#define PREF_4X_NEWS_USE_FCC "news.use_fcc" -#define PREF_4X_NEWS_MAX_ARTICLES "news.max_articles" -#define PREF_4X_NEWS_NOTIFY_ON "news.notify.on" -#define PREF_4X_NEWS_MARK_OLD_READ "news.mark_old_read" - -#define CONVERT_4X_URI(IDENTITY,FOR_NEWS,USERNAME,HOSTNAME,DEFAULT_FOLDER_NAME,MACRO_GETTER,MACRO_SETTER) \ -{ \ - nsXPIDLCString macro_oldStr; \ - nsresult macro_rv; \ - macro_rv = IDENTITY->MACRO_GETTER(getter_Copies(macro_oldStr)); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - if (!macro_oldStr) { \ - IDENTITY->MACRO_SETTER(""); \ - }\ - else { \ - char *converted_uri = nsnull; \ - macro_rv = Convert4XUri((const char *)macro_oldStr, FOR_NEWS, USERNAME, HOSTNAME, DEFAULT_FOLDER_NAME, &converted_uri); \ - if (NS_FAILED(macro_rv)) { \ - IDENTITY->MACRO_SETTER(""); \ - } \ - else { \ - IDENTITY->MACRO_SETTER(converted_uri); \ - } \ - PR_FREEIF(converted_uri); \ - } \ -} - -#define COPY_IDENTITY_FILE_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \ - { \ - nsresult macro_rv; \ - nsCOMPtr macro_spec; \ - macro_rv = SRC_ID->MACRO_GETTER(getter_AddRefs(macro_spec)); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - DEST_ID->MACRO_SETTER(macro_spec); \ - } - -#define COPY_IDENTITY_INT_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \ - { \ - nsresult macro_rv; \ - PRInt32 macro_oldInt; \ - macro_rv = SRC_ID->MACRO_GETTER(¯o_oldInt); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - DEST_ID->MACRO_SETTER(macro_oldInt); \ - } - -#define COPY_IDENTITY_BOOL_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \ - { \ - nsresult macro_rv; \ - PRBool macro_oldBool; \ - macro_rv = SRC_ID->MACRO_GETTER(¯o_oldBool); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - DEST_ID->MACRO_SETTER(macro_oldBool); \ - } - -#define COPY_IDENTITY_STR_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \ - { \ - nsXPIDLCString macro_oldStr; \ - nsresult macro_rv; \ - macro_rv = SRC_ID->MACRO_GETTER(getter_Copies(macro_oldStr)); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - if (!macro_oldStr) { \ - DEST_ID->MACRO_SETTER(""); \ - } \ - else { \ - DEST_ID->MACRO_SETTER(macro_oldStr); \ - } \ - } - -static const PRUnichar unicharEmptyString[] = { (PRUnichar)'\0' }; - -#define COPY_IDENTITY_WSTR_VALUE(SRC_ID,DEST_ID,MACRO_GETTER,MACRO_SETTER) \ - { \ - nsXPIDLString macro_oldStr; \ - nsresult macro_rv; \ - macro_rv = SRC_ID->MACRO_GETTER(getter_Copies(macro_oldStr)); \ - if (NS_FAILED(macro_rv)) return macro_rv; \ - if (!macro_oldStr) { \ - DEST_ID->MACRO_SETTER(unicharEmptyString); \ - } \ - else { \ - DEST_ID->MACRO_SETTER(macro_oldStr); \ - } \ - } - -#define MIGRATE_SIMPLE_FILE_PREF_TO_BOOL_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - nsCOMPtr macro_spec; \ - macro_rv = m_prefs->GetFilePref(PREFNAME, getter_AddRefs(macro_spec)); \ - if (NS_SUCCEEDED(macro_rv)) { \ - char *macro_oldStr = nsnull; \ - macro_rv = macro_spec->GetUnixStyleFilePath(¯o_oldStr); \ - if (NS_SUCCEEDED(macro_rv) && macro_oldStr && (PL_strlen(macro_oldStr) > 0)) { \ - MACRO_OBJECT->MACRO_METHOD(PR_TRUE); \ - } \ - else { \ - MACRO_OBJECT->MACRO_METHOD(PR_FALSE); \ - } \ - PR_FREEIF(macro_oldStr); \ - } \ - } - - -#define MIGRATE_SIMPLE_FILE_PREF_TO_CHAR_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - nsCOMPtr macro_spec; \ - char *macro_val = nsnull; \ - macro_rv = m_prefs->CopyCharPref(PREFNAME, ¯o_val); \ - if (NS_SUCCEEDED(macro_rv) && macro_val && PL_strlen(macro_val)) { \ - macro_rv = m_prefs->GetFilePref(PREFNAME, getter_AddRefs(macro_spec)); \ - if (NS_SUCCEEDED(macro_rv)) { \ - char *macro_oldStr = nsnull; \ - macro_rv = macro_spec->GetUnixStyleFilePath(¯o_oldStr); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(macro_oldStr); \ - } \ - PR_FREEIF(macro_oldStr); \ - } \ - } \ - else { \ - MACRO_OBJECT->MACRO_METHOD(""); \ - } \ - } - -#define MIGRATE_SIMPLE_FILE_PREF_TO_FILE_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - nsCOMPtr macro_spec; \ - macro_rv = m_prefs->GetFilePref(PREFNAME, getter_AddRefs(macro_spec)); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(macro_spec); \ - } \ - } - -#define MIGRATE_SIMPLE_STR_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - char *macro_oldStr = nsnull; \ - macro_rv = m_prefs->CopyCharPref(PREFNAME, ¯o_oldStr); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(macro_oldStr); \ - PR_FREEIF(macro_oldStr); \ - } \ - } - -#define MIGRATE_SIMPLE_WSTR_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - PRUnichar *macro_oldStr = nsnull; \ - macro_rv = m_prefs->CopyUnicharPref(PREFNAME, ¯o_oldStr); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(macro_oldStr); \ - PR_FREEIF(macro_oldStr); \ - } \ - } - -#define MIGRATE_SIMPLE_INT_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - PRInt32 oldInt; \ - macro_rv = m_prefs->GetIntPref(PREFNAME, &oldInt); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(oldInt); \ - } \ - } - -#define MIGRATE_SIMPLE_BOOL_PREF(PREFNAME,MACRO_OBJECT,MACRO_METHOD) \ - { \ - nsresult macro_rv; \ - PRBool macro_oldBool; \ - macro_rv = m_prefs->GetBoolPref(PREFNAME, ¯o_oldBool); \ - if (NS_SUCCEEDED(macro_rv)) { \ - MACRO_OBJECT->MACRO_METHOD(macro_oldBool); \ - } \ - } - -#define MIGRATE_STR_PREF(PREFFORMATSTR,PREFFORMATVALUE,INCOMINGSERVERPTR,INCOMINGSERVERMETHOD) \ - { \ - nsresult macro_rv; \ - char prefName[BUF_STR_LEN]; \ - char *macro_oldStr = nsnull; \ - PR_snprintf(prefName, BUF_STR_LEN, PREFFORMATSTR, PREFFORMATVALUE); \ - macro_rv = m_prefs->CopyCharPref(prefName, ¯o_oldStr); \ - if (NS_SUCCEEDED(macro_rv)) { \ - INCOMINGSERVERPTR->INCOMINGSERVERMETHOD(macro_oldStr); \ - PR_FREEIF(macro_oldStr); \ - } \ - } - -#define MIGRATE_INT_PREF(PREFFORMATSTR,PREFFORMATVALUE,INCOMINGSERVERPTR,INCOMINGSERVERMETHOD) \ - { \ - nsresult macro_rv; \ - PRInt32 oldInt; \ - char prefName[BUF_STR_LEN]; \ - PR_snprintf(prefName, BUF_STR_LEN, PREFFORMATSTR, PREFFORMATVALUE); \ - macro_rv = m_prefs->GetIntPref(prefName, &oldInt); \ - if (NS_SUCCEEDED(macro_rv)) { \ - INCOMINGSERVERPTR->INCOMINGSERVERMETHOD(oldInt); \ - } \ - } - -#define MIGRATE_BOOL_PREF(PREFFORMATSTR,PREFFORMATVALUE,INCOMINGSERVERPTR,INCOMINGSERVERMETHOD) \ - { \ - nsresult macro_rv; \ - PRBool macro_oldBool; \ - char prefName[BUF_STR_LEN]; \ - PR_snprintf(prefName, BUF_STR_LEN, PREFFORMATSTR, PREFFORMATVALUE); \ - macro_rv = m_prefs->GetBoolPref(prefName, ¯o_oldBool); \ - if (NS_SUCCEEDED(macro_rv)) { \ - INCOMINGSERVERPTR->INCOMINGSERVERMETHOD(macro_oldBool); \ - } \ - } - - // use this to search for all servers with the given hostname/iid and // put them in "servers" typedef struct _findServerEntry { @@ -409,10 +111,6 @@ nsMsgAccountManager::nsMsgAccountManager() : m_prefs(0) { NS_INIT_REFCNT(); - - m_alreadySetImapDefaultLocalPath = PR_FALSE; - m_alreadySetNntpDefaultLocalPath = PR_FALSE; - m_oldMailType = -1; } nsMsgAccountManager::~nsMsgAccountManager() @@ -452,11 +150,7 @@ nsresult nsMsgAccountManager::Init() observerService->AddObserver(this, topic.GetUnicode()); } - rv = getPrefService(); - if (NS_FAILED(rv)) return rv; - - rv = m_prefs->GetIntPref(PREF_4X_MAIL_SERVER_TYPE, &m_oldMailType); - return rv; + return NS_OK; } nsresult nsMsgAccountManager::Shutdown() @@ -1352,139 +1046,6 @@ nsMsgAccountManager::findAccountByKey(nsISupports* element, void *aData) return PR_TRUE; } -nsresult -nsMsgAccountManager::ProceedWithMigration() -{ - char *prefvalue = nsnull; - nsresult rv = NS_OK; - - if ((m_oldMailType == POP_4X_MAIL_TYPE) -#ifdef HAVE_MOVEMAIL - || (m_oldMailType == MOVEMAIL_4X_MAIL_TYPE) -#endif /* HAVE_MOVEMAIL */ - ) { - // if they were using pop or movemail, "mail.pop_name" must have been set - // otherwise, they don't really have anything to migrate - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &prefvalue); - if (NS_SUCCEEDED(rv)) { - if (!prefvalue || (PL_strlen(prefvalue) == 0)) { - rv = NS_ERROR_FAILURE; - } - } - } - else if (m_oldMailType == IMAP_4X_MAIL_TYPE) { - // if they were using imap, "network.hosts.imap_servers" must have been set - // otherwise, they don't really have anything to migrate - rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_IMAP_SERVER, &prefvalue); - if (NS_SUCCEEDED(rv)) { - if (!prefvalue || (PL_strlen(prefvalue) == 0)) { - rv = NS_ERROR_FAILURE; - } - } - } - else { -#ifdef DEBUG_ACCOUNTMANAGER - printf("Unrecognized server type %d\n", m_oldMailType); -#endif - rv = NS_ERROR_UNEXPECTED; - } - - PR_FREEIF(prefvalue); - return rv; -} - -NS_IMETHODIMP -nsMsgAccountManager::UpgradePrefs() -{ - nsresult rv; - - rv = getPrefService(); - if (NS_FAILED(rv)) return rv; - - // because mail.server_type defaults to 0 (pop) it will look the user - // has something to migrate, even with an empty prefs.js file - // ProceedWithMigration will check if there is something to migrate - // if not, NS_FAILED(rv) will be true, and we'll return. - // this plays nicely with msgMail3PaneWindow.js, which will launch the - // Account Manager if UpgradePrefs() fails. - rv = ProceedWithMigration(); - if (NS_FAILED(rv)) { -#ifdef DEBUG_ACCOUNTMANAGER - printf("FAIL: don't proceed with migration.\n"); -#endif - return rv; - } -#ifdef DEBUG_ACCOUNTMANAGER - else { - printf("PASS: proceed with migration.\n"); - } -#endif - - // create a dummy identity, for migration only - nsCOMPtr identity; - rv = createKeyedIdentity("migration", getter_AddRefs(identity)); - if (NS_FAILED(rv)) return rv; - - rv = MigrateIdentity(identity); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr smtpServer; - NS_WITH_SERVICE(nsISmtpService, smtpService, kSmtpServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = smtpService->GetDefaultServer(getter_AddRefs(smtpServer)); - if (NS_FAILED(rv)) return rv; - - rv = MigrateSmtpServer(smtpServer); - if (NS_FAILED(rv)) return rv; - - if ( m_oldMailType == POP_4X_MAIL_TYPE) { - // in 4.x, you could only have one pop account - rv = MigratePopAccount(identity); - if (NS_FAILED(rv)) return rv; - - // everyone gets a local mail account in 5.0 - rv = CreateLocalMailAccount(identity, PR_TRUE); - if (NS_FAILED(rv)) return rv; - } - else if (m_oldMailType == IMAP_4X_MAIL_TYPE) { - rv = MigrateImapAccounts(identity); - if (NS_FAILED(rv)) return rv; - - // if they had IMAP in 4.x, they also had "Local Mail" - // we need to migrate that, too. - rv = MigrateLocalMailAccount(identity); - if (NS_FAILED(rv)) return rv; - } -#ifdef HAVE_MOVEMAIL - else if (m_oldMailType == MOVEMAIL_4X_MAIL_TYPE) { - // if 4.x, you could only have one movemail account - rv = MigrateMovemailAccount(identity); - if (NS_FAILED(rv)) return rv; - - // everyone gets a local mail account in 5.0 - rv = CreateLocalMailAccount(identity, PR_TRUE); - if (NS_FAILED(rv)) return rv; - } -#endif /* HAVE_MOVEMAIL */ - else { -#ifdef DEBUG_ACCOUNTMANAGER - printf("Unrecognized server type %d\n", m_oldMailType); -#endif - return NS_ERROR_UNEXPECTED; - } - - rv = MigrateNewsAccounts(identity); - if (NS_FAILED(rv)) return rv; - - // we're done migrating, let's save the prefs - rv = m_prefs->SavePrefFile(); - if (NS_FAILED(rv)) return rv; - - // XXX TODO: remove dummy migration identity - return NS_OK; -} - NS_IMETHODIMP nsMsgAccountManager::AddIncomingServerListener(nsIIncomingServerListener *serverListener) { m_incomingServerListeners->AppendElement(serverListener); @@ -1534,1380 +1095,6 @@ NS_IMETHODIMP nsMsgAccountManager::NotifyServerUnloaded(nsIMsgIncomingServer *se return NS_OK; } - -nsresult -nsMsgAccountManager::MigrateIdentity(nsIMsgIdentity *identity) -{ - /* NOTE: if you add prefs here, make sure you update CopyIdentity() */ - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_USEREMAIL,identity,SetEmail) - MIGRATE_SIMPLE_WSTR_PREF(PREF_4X_MAIL_IDENTITY_USERNAME,identity,SetFullName) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IDENTITY_REPLY_TO,identity,SetReplyTo) - MIGRATE_SIMPLE_WSTR_PREF(PREF_4X_MAIL_IDENTITY_ORGANIZATION,identity,SetOrganization) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_COMPOSE_HTML,identity,SetComposeHtml) - MIGRATE_SIMPLE_FILE_PREF_TO_FILE_PREF(PREF_4X_MAIL_SIGNATURE_FILE,identity,SetSignature); - MIGRATE_SIMPLE_FILE_PREF_TO_BOOL_PREF(PREF_4X_MAIL_SIGNATURE_FILE,identity,SetAttachSignature); - MIGRATE_SIMPLE_INT_PREF(PREF_4X_MAIL_SIGNATURE_DATE,identity,SetSignatureDate); - /* NOTE: if you add prefs here, make sure you update CopyIdentity() */ - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateSmtpServer(nsISmtpServer *server) -{ - MIGRATE_SIMPLE_STR_PREF(PREF_4X_NETWORK_HOSTS_SMTP_SERVER,server,SetHostname) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_SMTP_NAME,server,SetUsername) - return NS_OK; -} - -nsresult -nsMsgAccountManager::SetNewsCopiesAndFolders(nsIMsgIdentity *identity) -{ - nsresult rv; - - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_NEWS_CC_SELF,identity,SetBccSelf) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_NEWS_USE_DEFAULT_CC,identity,SetBccOthers) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_NEWS_DEFAULT_CC,identity,SetBccList) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_NEWS_USE_FCC,identity,SetDoFcc) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_DRAFTS,identity,SetDraftFolder) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_TEMPLATES,identity,SetStationeryFolder) - - PRBool news_used_uri_for_sent_in_4x; - rv = m_prefs->GetBoolPref(PREF_4X_NEWS_USE_IMAP_SENTMAIL, &news_used_uri_for_sent_in_4x); - if (NS_FAILED(rv)) { - MIGRATE_SIMPLE_FILE_PREF_TO_CHAR_PREF(PREF_4X_NEWS_DEFAULT_FCC,identity,SetFccFolder) - } - else { - if (news_used_uri_for_sent_in_4x) { - MIGRATE_SIMPLE_STR_PREF(PREF_4X_NEWS_IMAP_SENTMAIL_PATH,identity,SetFccFolder) - } - else { - MIGRATE_SIMPLE_FILE_PREF_TO_CHAR_PREF(PREF_4X_NEWS_DEFAULT_FCC,identity,SetFccFolder) - } - } - - if (m_oldMailType == IMAP_4X_MAIL_TYPE) { - CONVERT_4X_URI(identity, PR_TRUE /* for news */, LOCAL_MAIL_FAKE_USER_NAME, LOCAL_MAIL_FAKE_HOST_NAME, DEFAULT_4X_SENT_FOLDER_NAME,GetFccFolder,SetFccFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, LOCAL_MAIL_FAKE_USER_NAME, LOCAL_MAIL_FAKE_HOST_NAME, DEFAULT_4X_TEMPLATES_FOLDER_NAME,GetStationeryFolder,SetStationeryFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, LOCAL_MAIL_FAKE_USER_NAME, LOCAL_MAIL_FAKE_HOST_NAME, DEFAULT_4X_DRAFTS_FOLDER_NAME,GetDraftFolder,SetDraftFolder) - } - else if (m_oldMailType == POP_4X_MAIL_TYPE) { - char *pop_username = nsnull; - char *pop_hostname = nsnull; - - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &pop_username); - if (NS_FAILED(rv)) return rv; - - rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_POP_SERVER, &pop_hostname); - if (NS_FAILED(rv)) return rv; - - CONVERT_4X_URI(identity, PR_TRUE /* for news */, (const char *)pop_username, (const char *)pop_hostname, DEFAULT_4X_SENT_FOLDER_NAME,GetFccFolder,SetFccFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, (const char *)pop_username, (const char *)pop_hostname, DEFAULT_4X_TEMPLATES_FOLDER_NAME,GetStationeryFolder,SetStationeryFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, (const char *)pop_username, (const char *)pop_hostname, DEFAULT_4X_DRAFTS_FOLDER_NAME,GetDraftFolder,SetDraftFolder) - - PR_FREEIF(pop_username); - PR_FREEIF(pop_hostname); - } -#ifdef HAVE_MOVEMAIL - else if (m_oldMailType == MOVEMAIL_4X_MAIL_TYPE) { - char *pop_username = nsnull; - - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &pop_username); - if (NS_FAILED(rv)) return rv; - - CONVERT_4X_URI(identity, PR_TRUE /* for news */, pop_username, MOVEMAIL_FAKE_HOST_NAME, DEFAULT_4X_SENT_FOLDER_NAME,GetFccFolder,SetFccFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, pop_username, MOVEMAIL_FAKE_HOST_NAME, DEFAULT_4X_TEMPLATES_FOLDER_NAME,GetStationeryFolder,SetStationeryFolder) - CONVERT_4X_URI(identity, PR_TRUE /* for news */, pop_username, MOVEMAIL_FAKE_HOST_NAME, DEFAULT_4X_DRAFTS_FOLDER_NAME,GetDraftFolder,SetDraftFolder) - - PR_FREEIF(pop_username); - } -#endif /* HAVE_MOVEMAIL */ - else { - return NS_ERROR_UNEXPECTED; - } - - return NS_OK; -} - -nsresult -nsMsgAccountManager::SetMailCopiesAndFolders(nsIMsgIdentity *identity, const char *username, const char *hostname) -{ - nsresult rv; - - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_CC_SELF,identity,SetBccSelf) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_USE_DEFAULT_CC,identity,SetBccOthers) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_CC,identity,SetBccList) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_USE_FCC,identity,SetDoFcc) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_DRAFTS,identity,SetDraftFolder) - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_DEFAULT_TEMPLATES,identity,SetStationeryFolder) - - PRBool imap_used_uri_for_sent_in_4x; - rv = m_prefs->GetBoolPref(PREF_4X_MAIL_USE_IMAP_SENTMAIL, &imap_used_uri_for_sent_in_4x); - - - if (NS_FAILED(rv)) { - MIGRATE_SIMPLE_FILE_PREF_TO_CHAR_PREF(PREF_4X_MAIL_DEFAULT_FCC,identity,SetFccFolder) - } - else { - if (imap_used_uri_for_sent_in_4x) { - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_IMAP_SENTMAIL_PATH,identity,SetFccFolder) - } - else { - MIGRATE_SIMPLE_FILE_PREF_TO_CHAR_PREF(PREF_4X_MAIL_DEFAULT_FCC,identity,SetFccFolder) - } - } - CONVERT_4X_URI(identity, PR_FALSE /* for news */, username, hostname, DEFAULT_4X_SENT_FOLDER_NAME,GetFccFolder,SetFccFolder) - CONVERT_4X_URI(identity, PR_FALSE /* for news */, username, hostname, DEFAULT_4X_TEMPLATES_FOLDER_NAME,GetStationeryFolder,SetStationeryFolder) - CONVERT_4X_URI(identity, PR_FALSE /* for news */, username, hostname, DEFAULT_4X_DRAFTS_FOLDER_NAME,GetDraftFolder,SetDraftFolder) - - return NS_OK; -} - -// caller will free the memory -nsresult -nsMsgAccountManager::Convert4XUri(const char *old_uri, PRBool for_news, const char *aUsername, const char *aHostname, const char *default_folder_name, char **new_uri) -{ - nsresult rv; - *new_uri = nsnull; - - if (!old_uri) { - return NS_ERROR_NULL_POINTER; - } - - // if the old_uri is "", do some default conversion - if (PL_strlen(old_uri) == 0) { - if (!aUsername || !aHostname) { - // if the old uri was "", and we don't know the username or the hostname - // leave it blank. either someone will be back to fix it, - // SetNewsCopiesAndFolders() and SetMailCopiesAndFolders() - // or we are out of luck. - *new_uri = PR_smprintf(""); - return NS_OK; - } - -#ifdef NEWS_FCC_DEFAULT_TO_IMAP_SENT - // another case of mac vs. windows in 4.x - // on mac, the default for news fcc, if you used imap, was "Sent on Local Mail" - // on windows, the default for news fcc, if you used imap, was "Sent on " - for_news = PR_FALSE; -#endif /* NEWS_FCC_DEFAULT_TO_IMAP_SENT */ - - if ((m_oldMailType == IMAP_4X_MAIL_TYPE) && !for_news) { - *new_uri = PR_smprintf("%s/%s@%s/%s",IMAP_SCHEMA,aUsername,aHostname,default_folder_name); - } - else if ((m_oldMailType == POP_4X_MAIL_TYPE) -#ifdef HAVE_MOVEMAIL - || (m_oldMailType == MOVEMAIL_4X_MAIL_TYPE) -#endif /* HAVE_MOVEMAIL */ - || (m_oldMailType == IMAP_4X_MAIL_TYPE)) { - *new_uri = PR_smprintf("%s/%s@%s/%s",MAILBOX_SCHEMA,aUsername,aHostname,default_folder_name); - } - else { - *new_uri = PR_smprintf(""); - return NS_ERROR_UNEXPECTED; - } - return NS_OK; - } - -#ifdef DEBUG_ACCOUNTMANAGER - printf("old 4.x folder uri = >%s<\n", old_uri); -#endif /* DEBUG_ACCOUNTMANAGER */ - - if (PL_strncasecmp(IMAP_SCHEMA,old_uri,IMAP_SCHEMA_LENGTH) == 0) { - nsCOMPtr url; - nsXPIDLCString hostname; - nsXPIDLCString username; - - rv = nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, NS_GET_IID(nsIURL), getter_AddRefs(url)); - if (NS_FAILED(rv)) return rv; - - rv = url->SetSpec(old_uri); - if (NS_FAILED(rv)) return rv; - - rv = url->GetHost(getter_Copies(hostname)); - if (NS_FAILED(rv)) return rv; - rv = url->GetPreHost(getter_Copies(username)); - if (NS_FAILED(rv)) return rv; - - // in 4.x, mac and windows stored the URI as IMAP:// - // if the URI was the default folder on the server. - // If it wasn't the default folder, they would have stored it as - if (!username || (PL_strlen((const char *)username) == 0)) { - char *imap_username = nsnull; - char *prefname = nsnull; - prefname = PR_smprintf("mail.imap.server.%s.userName", (const char *)hostname); - if (!prefname) return NS_ERROR_FAILURE; - - rv = m_prefs->CopyCharPref(prefname, &imap_username); - PR_FREEIF(prefname); - if (NS_FAILED(rv) || !imap_username || !*imap_username) { - *new_uri = PR_smprintf(""); - return NS_ERROR_FAILURE; - } - else { - // new_uri = imap://@/ -#ifdef DEBUG_ACCOUNTMANAGER - printf("new_uri = %s/%s@%s/%s\n",IMAP_SCHEMA, imap_username, (const char *)hostname, default_folder_name); -#endif /* DEBUG_ACCOUNTMANAGER */ - *new_uri = PR_smprintf("%s/%s@%s/%s",IMAP_SCHEMA, imap_username, (const char *)hostname, default_folder_name); - return NS_OK; - } - } - else { - // IMAP uri's began with "IMAP:/". we need that to be "imap:/" -#ifdef DEBUG_ACCOUNTMANAGER - printf("new_uri = %s%s\n",IMAP_SCHEMA,old_uri+IMAP_SCHEMA_LENGTH); -#endif /* DEBUG_ACCOUNTMANAGER */ - *new_uri = PR_smprintf("%s%s",IMAP_SCHEMA,old_uri+IMAP_SCHEMA_LENGTH); - return NS_OK; - } - } - - char *usernameAtHostname = nsnull; - nsCOMPtr mail_dir; - char *mail_directory_value = nsnull; - rv = m_prefs->GetFilePref(PREF_PREMIGRATION_MAIL_DIRECTORY, getter_AddRefs(mail_dir)); - if (NS_SUCCEEDED(rv)) { - rv = mail_dir->GetUnixStyleFilePath(&mail_directory_value); - } - if (NS_FAILED(rv) || !mail_directory_value || (PL_strlen(mail_directory_value) == 0)) { -#ifdef DEBUG_ACCOUNTMANAGER - printf("%s was not set, attempting to use %s instead.\n",PREF_PREMIGRATION_MAIL_DIRECTORY,PREF_MAIL_DIRECTORY); -#endif - PR_FREEIF(mail_directory_value); - - rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mail_dir)); - if (NS_SUCCEEDED(rv)) { - rv = mail_dir->GetUnixStyleFilePath(&mail_directory_value); - } - - if (NS_FAILED(rv) || !mail_directory_value || (PL_strlen(mail_directory_value) == 0)) { - NS_ASSERTION(0,"failed to get a base value for the mail.directory"); - return NS_ERROR_UNEXPECTED; - } - } - - if (m_oldMailType == POP_4X_MAIL_TYPE) { - char *pop_username = nsnull; - char *pop_hostname = nsnull; - - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &pop_username); - if (NS_FAILED(rv)) return rv; - - rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_POP_SERVER, &pop_hostname); - if (NS_FAILED(rv)) return rv; - - usernameAtHostname = PR_smprintf("%s@%s",pop_username, pop_hostname); - - PR_FREEIF(pop_username); - PR_FREEIF(pop_hostname); - } - else if (m_oldMailType == IMAP_4X_MAIL_TYPE) { - usernameAtHostname = PR_smprintf("%s@%s",LOCAL_MAIL_FAKE_USER_NAME,LOCAL_MAIL_FAKE_HOST_NAME); - } -#ifdef HAVE_MOVEMAIL - else if (m_oldMailType == MOVEMAIL_4X_MAIL_TYPE) { - char *movemail_username = nsnull; - - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, &movemail_username); - if (NS_FAILED(rv)) return rv; - - usernameAtHostname = PR_smprintf("%s@%s",movemail_username,MOVEMAIL_FAKE_HOST_NAME); - - PR_FREEIF(movemail_username); - } -#endif /* HAVE_MOVEMAIL */ - else { -#ifdef DEBUG_ACCOUNTMANAGER - printf("Unrecognized server type %d\n", m_oldMailType); -#endif - return NS_ERROR_UNEXPECTED; - } - - const char *folderPath; - - // mail_directory_value is already in UNIX style at this point... - if (PL_strncasecmp(MAILBOX_SCHEMA,old_uri,MAILBOX_SCHEMA_LENGTH) == 0) { -#ifdef DEBUG_ACCOUNTMANAGER - printf("turn %s into %s/%s/(%s - %s)\n",old_uri,MAILBOX_SCHEMA,usernameAtHostname,old_uri + MAILBOX_SCHEMA_LENGTH,mail_directory_value); -#endif - // the extra -1 is because in 4.x, we had this: - // mailbox: instead of mailbox:/ - folderPath = old_uri + MAILBOX_SCHEMA_LENGTH + PL_strlen(mail_directory_value) -1; - } - else { -#ifdef DEBUG_ACCOUNTMANAGER - printf("turn %s into %s/%s/(%s - %s)\n",old_uri,MAILBOX_SCHEMA,usernameAtHostname,old_uri,mail_directory_value); -#endif - folderPath = old_uri + PL_strlen(mail_directory_value); - } - - - // if folder path is "", then the URI was mailbox:/ - // and the directory pref was - // this meant it was reall / - // this insanity only happened on mac and windows. - if (!folderPath || (PL_strlen(folderPath) == 0)) { - *new_uri = PR_smprintf("%s/%s/%s",MAILBOX_SCHEMA,usernameAtHostname, default_folder_name); - } - else { - // if the folder path starts with a /, we don't need to add one. - // the reason for this is on UNIX, we store mail.directory as "/home/sspitzer/nsmail" - // but on windows, its "C:\foo\bar\mail" - *new_uri = PR_smprintf("%s/%s%s%s",MAILBOX_SCHEMA,usernameAtHostname,(folderPath[0] == '/')?"":"/",folderPath); - } - - if (!*new_uri) { -#ifdef DEBUG_ACCOUNTMANAGER - printf("failed to convert 4.x uri: %s\n", old_uri); -#endif - NS_ASSERTION(0,"uri conversion code not complete"); - return NS_ERROR_FAILURE; - } - - PR_FREEIF(usernameAtHostname); - PR_FREEIF(mail_directory_value); - - return NS_OK; -} - -NS_IMETHODIMP -nsMsgAccountManager::CreateLocalMailAccount(nsIMsgIdentity *identity, PRBool migrating) -{ - nsresult rv; - - // create the account - nsCOMPtr account; - rv = CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - - // create the server - nsCOMPtr server; - rv = CreateIncomingServer(LOCAL_MAIL_FAKE_USER_NAME, - LOCAL_MAIL_FAKE_HOST_NAME, - "none", getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // we don't want "nobody at Local Folders" to show up in the - // folder pane, so we set the pretty name to "Local Folders" - nsAutoString localMailFakeHostName(LOCAL_MAIL_FAKE_HOST_NAME); - server->SetPrettyName(localMailFakeHostName.ToNewUnicode()); - - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // this only makes sense if we have 4.x prefs, but we don't if identity is null - if (identity) { - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - // only set the cc and fcc values if we were migrating. - // otherwise, we won't have them. - if (migrating) { - rv = SetMailCopiesAndFolders(copied_identity, LOCAL_MAIL_FAKE_USER_NAME, LOCAL_MAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - } - } - else { - char *profileName = nsnull; - NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = profile->GetCurrentProfile(&profileName); - if (NS_FAILED(rv)) return rv; - - rv = copied_identity->SetEmail(profileName); - // find out the proper way to delete this - // until then, leak it. - // PR_FREEIF(profileName); - if (NS_FAILED(rv)) return rv; - } - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - nsCOMPtr noServer; - noServer = do_QueryInterface(server, &rv); - if (NS_FAILED(rv)) return rv; - - // create the directory structure for old 4.x "Local Mail" - // under /Mail/Local Folders or - // <"mail.directory" pref>/Local Folders - nsCOMPtr mailDir; - nsFileSpec dir; - PRBool dirExists; - - // if the "mail.directory" pref is set, use that. - // if they used -installer, this pref will point to where their files got copied - // this only makes sense when we are migrating - // for a new profile, that pref won't be set. - if (identity && migrating) { - rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir)); - } - else { - rv = NS_ERROR_FAILURE; - } - - if (NS_FAILED(rv)) { - // we want /Mail - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) return rv; - } - - // set the default local path for "none" - rv = server->SetDefaultLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // set the local path for this "none" server - // - // we need to set this to /Mail/Local Folders, because that's where - // the 4.x "Local Mail" (when using imap) got copied. - // it would be great to use the server key, but we don't know it - // when we are copying of the mail. - rv = mailDir->AppendRelativeUnixPath(LOCAL_MAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - rv = server->SetLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateLocalMailAccount(nsIMsgIdentity *identity) -{ - nsresult rv; - - // create the account - nsCOMPtr account; - rv = 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; - rv = CreateIncomingServer(LOCAL_MAIL_FAKE_USER_NAME, - LOCAL_MAIL_FAKE_HOST_NAME, - "none", getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - rv = SetMailCopiesAndFolders(copied_identity, LOCAL_MAIL_FAKE_USER_NAME, LOCAL_MAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - // now upgrade all the prefs - // some of this ought to be moved out into the NONE implementation - nsCOMPtr noServer; - noServer = do_QueryInterface(server, &rv); - if (NS_FAILED(rv)) return rv; - - // we don't want "nobody at Local Folders" to show up in the - // folder pane, so we set the pretty name to "Local Folders" - nsAutoString localMailFakeHostName(LOCAL_MAIL_FAKE_HOST_NAME); - server->SetPrettyName(localMailFakeHostName.ToNewUnicode()); - - // create the directory structure for old 4.x "Local Mail" - // under /Mail/Local Folders or - // <"mail.directory" pref>/Local Folders - nsCOMPtr mailDir; - nsFileSpec dir; - PRBool dirExists; - - // if the "mail.directory" pref is set, use that. - // if they used -installer, this pref will point to where their files got copied - rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) { - // we want /Mail - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) return rv; - } - - // set the default local path for "none" - rv = server->SetDefaultLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // set the local path for this "none" server - // - // we need to set this to /Mail/Local Folders, because that's where - // the 4.x "Local Mail" (when using imap) got copied. - // it would be great to use the server key, but we don't know it - // when we are copying of the mail. - rv = mailDir->AppendRelativeUnixPath(LOCAL_MAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - rv = server->SetLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // pass the "Local Folders" server so the send later uri pref - // will be "mailbox://nobody@Local Folders/Unsent Messages" - rv = SetSendLaterUriPref(server); - return rv; -} - -#ifdef HAVE_MOVEMAIL -nsresult -nsMsgAccountManager::MigrateMovemailAccount(nsIMsgIdentity *identity) -{ - nsresult rv; - - nsCOMPtr account; - nsCOMPtr server; - - rv = CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - - // get the pop username - // movemail used the pop username in 4.x - nsXPIDLCString username; - rv = m_prefs->CopyCharPref(PREF_4X_MAIL_POP_NAME, getter_Copies(username)); - if (NS_FAILED(rv)) return rv; - - // for right now, none. eventually, we'll have "movemail" - rv = CreateIncomingServer(username, MOVEMAIL_FAKE_HOST_NAME, - "none", getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - // XXX: this probably won't work yet... - // the cc and fcc values - rv = SetMailCopiesAndFolders(copied_identity, (const char *)username, MOVEMAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - // now upgrade all the prefs - nsCOMPtr mailDir; - nsFileSpec dir; - PRBool dirExists; - - rv = MigrateOldMailPrefs(server); - if (NS_FAILED(rv)) return rv; - - // if they used -installer, this pref will point to where their files got copied - rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir)); - // create the directory structure for old 4.x pop mail - // under /Mail/movemail or - // <"mail.directory" pref>/movemail - // - // if the "mail.directory" pref is set, use that. - if (NS_FAILED(rv)) { - // we wan't /Mail - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) return rv; - } - - // set the default local path for "none" (eventually, "movemail") - rv = server->SetDefaultLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // we want .../Mail/movemail, not .../Mail - rv = mailDir->AppendRelativeUnixPath(MOVEMAIL_FAKE_HOST_NAME); - if (NS_FAILED(rv)) return rv; - - // set the local path for this "none" (eventually, "movemail" server) - rv = server->SetLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // pass the server so the send later uri pref - // will be something like "mailbox://sspitzer@movemail/Unsent Messages" - rv = SetSendLaterUriPref(server); - return rv; -} -#endif /* HAVE_MOVEMAIL */ - -nsresult -nsMsgAccountManager::MigratePopAccount(nsIMsgIdentity *identity) -{ - nsresult rv; - - nsCOMPtr account; - nsCOMPtr server; - - rv = 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)); - if (NS_FAILED(rv)) return rv; - - // get the hostname and port - nsXPIDLCString hostAndPort; - rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_POP_SERVER, - getter_Copies(hostAndPort)); - if (NS_FAILED(rv)) return rv; - - PRInt32 port = -1; - nsCAutoString hostname(hostAndPort); - PRInt32 colonPos = hostname.FindChar(':'); - if (colonPos != -1) { - hostname.Truncate(colonPos); - - // migrate the port from hostAndPort - nsCAutoString portStr(hostAndPort + colonPos); - PRInt32 err; - port = portStr.ToInteger(&err); - NS_ASSERTION(err == 0, "failed to get the port\n"); - if (err != 0) port=-1; - } - - // - // create the server - // - rv = CreateIncomingServer(username, hostname, "pop3", - getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // if we got the port above, set it here - if (port != -1) { - server->SetPort(port); - } - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - rv = SetMailCopiesAndFolders(copied_identity, (const char *)username, (const char *)hostname); - if (NS_FAILED(rv)) return rv; - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - // now upgrade all the prefs - nsCOMPtr mailDir; - nsFileSpec dir; - PRBool dirExists; - -#ifdef DEBUG_ACCOUNTMANAGER - PRInt32 portValue; - rv = server->GetPort(&portValue); - printf("HOSTNAME = %s\n", (const char *)hostname); - printf("PORT = %d\n", portValue); -#endif /* DEBUG_ACCOUNTMANAGER */ - - rv = MigrateOldMailPrefs(server); - if (NS_FAILED(rv)) return rv; - - // if they used -installer, this pref will point to where their files got copied - rv = m_prefs->GetFilePref(PREF_MAIL_DIRECTORY, getter_AddRefs(mailDir)); - // create the directory structure for old 4.x pop mail - // under /Mail/ or - // <"mail.directory" pref>/ - // - // if the "mail.directory" pref is set, use that. - if (NS_FAILED(rv)) { - // we wan't /Mail - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_MailDirectory50, getter_AddRefs(mailDir)); - if (NS_FAILED(rv)) return rv; - } - - // set the default local path for "pop3" - rv = server->SetDefaultLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // we want .../Mail/, not .../Mail - rv = mailDir->AppendRelativeUnixPath(hostAndPort); - if (NS_FAILED(rv)) return rv; - - // set the local path for this "pop3" server - rv = server->SetLocalPath(mailDir); - if (NS_FAILED(rv)) return rv; - - rv = mailDir->Exists(&dirExists); - if (!dirExists) { - mailDir->CreateDir(); - } - - // pass the pop server so the send later uri pref - // will be something like "mailbox://sspitzer@tintin/Unsent Messages" - rv = SetSendLaterUriPref(server); - return rv; -} -nsresult -nsMsgAccountManager::SetSendLaterUriPref(nsIMsgIncomingServer *server) -{ - nsresult rv; - - // set "mail.default_sendlater_uri" to something like - // mailbox://nobody@Local Folders/Unsent Messages" - // mailbox://sspitzer@tintin/Unsent Messages" - // - // note, the schema is mailbox:/ - // Unsent is an off-line thing, and that needs to be - // on the disk, not on an imap server. - nsXPIDLCString username; - rv = server->GetUsername(getter_Copies(username)); - if (NS_FAILED(rv)) return rv; - - nsXPIDLCString hostname; - rv = server->GetHostName(getter_Copies(hostname)); - if (NS_FAILED(rv)) return rv; - - char *sendLaterUriStr = nsnull; - sendLaterUriStr = PR_smprintf("%s/%s@%s/%s", MAILBOX_SCHEMA, (const char *)username, (const char *)hostname, UNSENT_MESSAGES_FOLDER_NAME); - m_prefs->SetCharPref(PREF_MAIL_DEFAULT_SENDLATER_URI, sendLaterUriStr); - PR_FREEIF(sendLaterUriStr); - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateOldMailPrefs(nsIMsgIncomingServer * server) -{ - nsresult rv; - - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_REMEMBER_PASSWORD,server,SetRememberPassword) -#ifdef CAN_UPGRADE_4x_PASSWORDS - MIGRATE_SIMPLE_STR_PREF(PREF_4X_MAIL_POP_PASSWORD,server,SetPassword) -#else - rv = server->SetPassword(nsnull); - if (NS_FAILED(rv)) return rv; -#endif /* CAN_UPGRADE_4x_PASSWORDS */ - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_CHECK_NEW_MAIL,server,SetDoBiff) - MIGRATE_SIMPLE_INT_PREF(PREF_4X_MAIL_CHECK_TIME,server,SetBiffMinutes) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_POP3_GETS_NEW_MAIL,server,SetDownloadOnBiff) - - nsCOMPtr popServer; - popServer = do_QueryInterface(server, &rv); - if (NS_SUCCEEDED(rv) && popServer) { - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_LEAVE_ON_SERVER,popServer,SetLeaveMessagesOnServer) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_MAIL_DELETE_MAIL_LEFT_ON_SERVER,popServer,SetDeleteMailLeftOnServer) - } - else { - // could be a movemail server, in that case do nothing. - } - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateImapAccounts(nsIMsgIdentity *identity) -{ - nsresult rv; - char *hostList=nsnull; - rv = getPrefService(); - if (NS_FAILED(rv)) return rv; - - rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_IMAP_SERVER, &hostList); - if (NS_FAILED(rv)) return rv; - - if (!hostList || !*hostList) return NS_OK; // NS_ERROR_FAILURE? - - char *token = nsnull; - char *rest = NS_CONST_CAST(char*,(const char*)hostList); - nsCAutoString str; - - token = nsCRT::strtok(rest, ",", &rest); - while (token && *token) { - str = token; - str.StripWhitespace(); - - if (!str.IsEmpty()) { - // str is the hostname - rv = MigrateImapAccount(identity,str); - if (NS_FAILED(rv)) { - // failed to migrate. bail. - return rv; - } - str = ""; - } - token = nsCRT::strtok(rest, ",", &rest); - } - PR_FREEIF(hostList); - return NS_OK; -} - -nsresult -nsMsgAccountManager::CopyIdentity(nsIMsgIdentity *srcIdentity, nsIMsgIdentity *destIdentity) -{ - COPY_IDENTITY_BOOL_VALUE(srcIdentity,destIdentity,GetComposeHtml,SetComposeHtml) - COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetEmail,SetEmail) - COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetReplyTo,SetReplyTo) - COPY_IDENTITY_WSTR_VALUE(srcIdentity,destIdentity,GetFullName,SetFullName) - COPY_IDENTITY_WSTR_VALUE(srcIdentity,destIdentity,GetOrganization,SetOrganization) - COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetDraftFolder,SetDraftFolder) - COPY_IDENTITY_STR_VALUE(srcIdentity,destIdentity,GetStationeryFolder,SetStationeryFolder) - COPY_IDENTITY_BOOL_VALUE(srcIdentity,destIdentity,GetAttachSignature,SetAttachSignature) - COPY_IDENTITY_FILE_VALUE(srcIdentity,destIdentity,GetSignature,SetSignature) - COPY_IDENTITY_INT_VALUE(srcIdentity,destIdentity,GetSignatureDate,SetSignatureDate) - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateImapAccount(nsIMsgIdentity *identity, const char *hostAndPort) -{ - nsresult rv; - - if (!hostAndPort) return NS_ERROR_NULL_POINTER; - - // create the account - nsCOMPtr account; - rv = CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - - // get the old username - nsXPIDLCString username; - char *imapUsernamePref = - PR_smprintf("mail.imap.server.%s.userName", hostAndPort); - rv = m_prefs->CopyCharPref(imapUsernamePref, getter_Copies(username)); - PR_FREEIF(imapUsernamePref); - if (NS_FAILED(rv)) return rv; - - // get the old host (and possibly port) - PRInt32 port = -1; - nsCAutoString hostname(hostAndPort); - PRInt32 colonPos = hostname.FindChar(':'); - if (colonPos != -1) { - nsCAutoString portStr(hostAndPort + colonPos); - hostname.Truncate(colonPos); - PRInt32 err; - port = portStr.ToInteger(&err); - NS_ASSERTION(err == 0, "failed to get the port\n"); - if (err != 0) - port = -1; - } - - // - // create the server - // - nsCOMPtr server; - rv = CreateIncomingServer(username, hostname, "imap", - getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // now start migrating 4.x prefs - if (port != -1) - server->SetPort(port); - -#ifdef DEBUG_ACCOUNTMANAGER - PRInt32 portValue; - rv = server->GetPort(&portValue); - printf("HOSTNAME = %s\n", (const char *)hostname); - printf("PORT = %d\n", portValue); -#endif /* DEBUG_ACCOUNTMANAGER */ - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - rv = SetMailCopiesAndFolders(copied_identity, (const char *)username, (const char *)hostname); - if (NS_FAILED(rv)) return rv; - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - // now upgrade all the prefs - - rv = MigrateOldImapPrefs(server, hostAndPort); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr imapMailDir; - nsFileSpec dir; - PRBool dirExists; - - // if they used -installer, this pref will point to where their files got copied - rv = m_prefs->GetFilePref(PREF_IMAP_DIRECTORY, getter_AddRefs(imapMailDir)); - // if the "mail.imap.root_dir" pref is set, use that. - if (NS_FAILED(rv)) { - // we want /ImapMail - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_ImapMailDirectory50, getter_AddRefs(imapMailDir)); - if (NS_FAILED(rv)) return rv; - } - - // we only need to do this once - if (!m_alreadySetImapDefaultLocalPath) { - // set the default local path for "imap" - rv = server->SetDefaultLocalPath(imapMailDir); - if (NS_FAILED(rv)) return rv; - - m_alreadySetImapDefaultLocalPath = PR_TRUE; - } - - // we want .../ImapMail/, not .../ImapMail - rv = imapMailDir->AppendRelativeUnixPath((const char *)hostname); - if (NS_FAILED(rv)) return rv; - - // set the local path for this "imap" server - rv = server->SetLocalPath(imapMailDir); - if (NS_FAILED(rv)) return rv; - - rv = imapMailDir->Exists(&dirExists); - if (!dirExists) { - imapMailDir->CreateDir(); - } - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateOldImapPrefs(nsIMsgIncomingServer *server, const char *hostAndPort) -{ - nsresult rv; - - // some of this ought to be moved out into the IMAP implementation - nsCOMPtr imapServer; - imapServer = do_QueryInterface(server, &rv); - if (NS_FAILED(rv)) return rv; - - // upgrade the msg incoming server prefs - MIGRATE_BOOL_PREF("mail.imap.server.%s.remember_password",hostAndPort,server,SetRememberPassword) -#ifdef CAN_UPGRADE_4x_PASSWORDS - MIGRATE_STR_PREF("mail.imap.server.%s.password",hostAndPort,server,SetPassword) -#else - rv = server->SetPassword(nsnull); - if (NS_FAILED(rv)) return rv; -#endif /* CAN_UPGRADE_4x_PASSWORDS */ - // upgrade the imap incoming server specific prefs - MIGRATE_BOOL_PREF("mail.imap.server.%s.check_new_mail",hostAndPort,server,SetDoBiff) - MIGRATE_INT_PREF("mail.imap.server.%s.check_time",hostAndPort,server,SetBiffMinutes) - // "mail.imap.new_mail_get_headers" was a global pref across all imap servers in 4.x - // in 5.0, it's per server - MIGRATE_BOOL_PREF("%s","mail.imap.new_mail_get_headers",server,SetDownloadOnBiff) - MIGRATE_STR_PREF("mail.imap.server.%s.admin_url",hostAndPort,imapServer,SetAdminUrl) - MIGRATE_INT_PREF("mail.imap.server.%s.capability",hostAndPort,imapServer,SetCapabilityPref) - MIGRATE_BOOL_PREF("mail.imap.server.%s.cleanup_inbox_on_exit",hostAndPort,imapServer,SetCleanupInboxOnExit) - MIGRATE_INT_PREF("mail.imap.server.%s.delete_model",hostAndPort,imapServer,SetDeleteModel) - MIGRATE_BOOL_PREF("mail.imap.server.%s.dual_use_folders",hostAndPort,imapServer,SetDualUseFolders) - MIGRATE_BOOL_PREF("mail.imap.server.%s.empty_trash_on_exit",hostAndPort,imapServer,SetEmptyTrashOnExit) - MIGRATE_INT_PREF("mail.imap.server.%s.empty_trash_threshhold",hostAndPort,imapServer,SetEmptyTrashThreshhold) - MIGRATE_STR_PREF("mail.imap.server.%s.namespace.other_users",hostAndPort,imapServer,SetOtherUsersNamespace) - MIGRATE_STR_PREF("mail.imap.server.%s.namespace.personal",hostAndPort,imapServer,SetPersonalNamespace) - MIGRATE_STR_PREF("mail.imap.server.%s.namespace.public",hostAndPort,imapServer,SetPublicNamespace) - MIGRATE_BOOL_PREF("mail.imap.server.%s.offline_download",hostAndPort,imapServer,SetOfflineDownload) - MIGRATE_BOOL_PREF("mail.imap.server.%s.override_namespaces",hostAndPort,imapServer,SetOverrideNamespaces) - MIGRATE_BOOL_PREF("mail.imap.server.%s.using_subscription",hostAndPort,imapServer,SetUsingSubscription) - - return NS_OK; -} - -#ifdef USE_NEWSRC_MAP_FILE -#define NEWSRC_MAP_FILE_COOKIE "netscape-newsrc-map-file" -#endif /* USE_NEWSRC_MAP_FILE */ - -nsresult -nsMsgAccountManager::MigrateNewsAccounts(nsIMsgIdentity *identity) -{ - nsresult rv; - nsCOMPtr newsDir; - nsFileSpec newsrcDir; // the directory that holds the newsrc files (and the fat file, if we are using one) - nsFileSpec newsHostsDir; // the directory that holds the host directory, and the summary files. - // the host directories will be under /News or - // <"news.directory" pref>/News. - // - // the newsrc file don't necessarily live under there. - // - // if we didn't use the map file (UNIX) then we want to force the newsHostsDir to be - // /News. in 4.x, on UNIX, the summary files lived in ~/.netscape/xover-cache/ - // in 5.0, they will live under /News/, like the other platforms. - // in 4.x, on UNIX, the "news.directory" pref pointed to the directory to where - // the newsrc files lived. we don't want that for the newsHostsDir. -#ifdef USE_NEWSRC_MAP_FILE - // if they used -installer, this pref will point to where their files got copied - rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir)); - if (NS_SUCCEEDED(rv)) { - rv = newsDir->GetFileSpec(&newsHostsDir); - } -#else - rv = NS_ERROR_FAILURE; -#endif /* USE_NEWSRC_MAP_FILE */ - if (NS_FAILED(rv)) { - NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = locator->GetFileLocation(nsSpecialFileSpec::App_NewsDirectory50, getter_AddRefs(newsDir)); - if (NS_FAILED(rv)) return rv; - } - - PRBool dirExists; - rv = newsDir->Exists(&dirExists); - if (!dirExists) { - newsDir->CreateDir(); - } - -#ifdef USE_NEWSRC_MAP_FILE - // if we are using the fat file, it lives in the newsHostsDir. - newsrcDir = newsHostsDir; - - // the fat file is really / - // example: News\fat on Windows, News\NewsFAT on the Mac - // don't worry, after we migrate, the fat file is going away - nsFileSpec fatFile(newsrcDir); - fatFile += NEWS_FAT_FILE_NAME; - - // for each news server in the fat file call MigrateNewsAccount(); - char buffer[512]; - char psuedo_name[512]; - char filename[512]; - char is_newsgroup[512]; - PRBool ok; - - nsInputFileStream inputStream(fatFile); - - if (inputStream.eof()) { - inputStream.close(); - return NS_ERROR_FAILURE; - } - - /* we expect the first line to be NEWSRC_MAP_FILE_COOKIE */ - ok = inputStream.readline(buffer, sizeof(buffer)); - - if ((!ok) || (PL_strncmp(buffer, NEWSRC_MAP_FILE_COOKIE, PL_strlen(NEWSRC_MAP_FILE_COOKIE)))) { - inputStream.close(); - return NS_ERROR_FAILURE; - } - - while (!inputStream.eof()) { - char * p; - PRInt32 i; - - ok = inputStream.readline(buffer, sizeof(buffer)); - if (!ok) { - inputStream.close(); - return NS_ERROR_FAILURE; - } - - /* TODO: replace this with nsString code? */ - - /* - This used to be scanf() call which would incorrectly - parse long filenames with spaces in them. - JRE - */ - - filename[0] = '\0'; - is_newsgroup[0]='\0'; - - for (i = 0, p = buffer; *p && *p != '\t' && i < 500; p++, i++) - psuedo_name[i] = *p; - psuedo_name[i] = '\0'; - if (*p) - { - for (i = 0, p++; *p && *p != '\t' && i < 500; p++, i++) - filename[i] = *p; - filename[i]='\0'; - if (*p) - { - for (i = 0, p++; *p && *p != '\r' && i < 500; p++, i++) - is_newsgroup[i] = *p; - is_newsgroup[i]='\0'; - } - } - - if(PL_strncmp(is_newsgroup, "TRUE", 4)) { -#ifdef NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS - // most likely, the fat file has been copied (or moved ) from - // its old location. So the absolute file paths will be wrong. - // all we care about is the leaf, so use that. - nsFileSpec oldRcFile(filename); - char *leaf = oldRcFile.GetLeafName(); - - nsFileSpec rcFile(newsrcDir); - rcFile += leaf; - nsCRT::free(leaf); - leaf = nsnull; -#else - nsFileSpec rcFile(newsrcDir); - rcFile += filename; -#endif /* NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS */ - - // psuedo-name is of the form newsrc- or snewsrc-. - // right now, we can't handle snewsrc, so if we get one of those - // gracefully handle it by ignoring it. - if (PL_strncmp(PSUEDO_NAME_PREFIX,psuedo_name,PL_strlen(PSUEDO_NAME_PREFIX)) != 0) { - continue; - } - - // check that there is a hostname to get after the "newsrc-" part - NS_ASSERTION(PL_strlen(psuedo_name) > PL_strlen(PSUEDO_NAME_PREFIX), "psuedo_name is too short"); - if (PL_strlen(psuedo_name) <= PL_strlen(PSUEDO_NAME_PREFIX)) { - return NS_ERROR_FAILURE; - } - - char *hostname = psuedo_name + PL_strlen(PSUEDO_NAME_PREFIX); - rv = MigrateNewsAccount(identity, hostname, rcFile, newsHostsDir); - if (NS_FAILED(rv)) { - // failed to migrate. bail out - return rv; - } - } - } - - inputStream.close(); -#else /* USE_NEWSRC_MAP_FILE */ - rv = m_prefs->GetFilePref(PREF_NEWS_DIRECTORY, getter_AddRefs(newsDir)); - if (NS_FAILED(rv)) return rv; - - rv = newsDir->GetFileSpec(&newsrcDir); - if (NS_FAILED(rv)) return rv; - - for (nsDirectoryIterator i(newsrcDir, PR_FALSE); i.Exists(); i++) { - nsFileSpec possibleRcFile = i.Spec(); - - char *filename = possibleRcFile.GetLeafName(); - - if ((PL_strncmp(NEWSRC_FILE_PREFIX_5x, filename, PL_strlen(NEWSRC_FILE_PREFIX_5x)) == 0) && (PL_strlen(filename) > PL_strlen(NEWSRC_FILE_PREFIX_5x))) { -#ifdef DEBUG_ACCOUNTMANAGER - printf("found a newsrc file: %s\n", filename); -#endif - char *hostname = filename + PL_strlen(NEWSRC_FILE_PREFIX_5x); - rv = MigrateNewsAccount(identity, hostname, possibleRcFile, newsHostsDir); - if (NS_FAILED(rv)) { - // failed to migrate. bail out - return rv; - } - } - nsCRT::free(filename); - filename = nsnull; - } -#endif /* USE_NEWSRC_MAP_FILE */ - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostAndPort, nsFileSpec & newsrcfile, nsFileSpec & newsHostsDir) -{ - nsresult rv; - nsFileSpec thisNewsHostsDir = newsHostsDir; - if (!identity) return NS_ERROR_NULL_POINTER; - if (!hostAndPort) return NS_ERROR_NULL_POINTER; - - // create the account - nsCOMPtr account; - rv = CreateAccount(getter_AddRefs(account)); - if (NS_FAILED(rv)) return rv; - - PRInt32 port=-1; - nsCAutoString hostname(hostAndPort); - PRInt32 colonPos = hostname.FindChar(':'); - if (colonPos != -1) { - nsCAutoString portStr(hostAndPort + colonPos); - hostname.Truncate(colonPos); - PRInt32 err; - port = portStr.ToInteger(&err); - NS_ASSERTION(err == 0, "failed to get the port\n"); - if (err != 0) - port=-1; - } - - // create the server - nsCOMPtr server; - rv = CreateIncomingServer(nsnull, hostname, "nntp", - getter_AddRefs(server)); - if (NS_FAILED(rv)) return rv; - - // now upgrade all the prefs - if (port != -1) - server->SetPort(port); - -#ifdef DEBUG_ACCOUNTMANAGER - PRInt32 portValue; - rv = server->GetPort(&portValue); - printf("HOSTNAME = %s\n", (const char *)hostname); - printf("PORT = %d\n", portValue); -#endif /* DEBUG_ACCOUNTMANAGER */ - - // we only need to do this once - if (!m_alreadySetNntpDefaultLocalPath) { - nsCOMPtr nntpRootDir; - rv = NS_NewFileSpecWithSpec(newsHostsDir, getter_AddRefs(nntpRootDir)); - if (NS_FAILED(rv)) return rv; - - // set the default local path for "nntp" - rv = server->SetDefaultLocalPath(nntpRootDir); - if (NS_FAILED(rv)) return rv; - - // set the newsrc root for "nntp" - // we really want /News or /home/sspitzer/ - // not /News/news.rc or /home/sspitzer/.newsrc-news - nsFileSpec newsrcFileDir; - newsrcfile.GetParent(newsrcFileDir); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr newsrcRootDir; - rv = NS_NewFileSpecWithSpec(newsrcFileDir, getter_AddRefs(newsrcRootDir)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr nntpServer; - nntpServer = do_QueryInterface(server, &rv); - if (NS_FAILED(rv)) return rv; - rv = nntpServer->SetNewsrcRootPath(newsrcRootDir); - if (NS_FAILED(rv)) return rv; - - m_alreadySetNntpDefaultLocalPath = PR_TRUE; - } - - // create the identity - nsCOMPtr copied_identity; - rv = CreateIdentity(getter_AddRefs(copied_identity)); - if (NS_FAILED(rv)) return rv; - - // make this new identity to copy of the identity - // that we created out of the 4.x prefs - rv = CopyIdentity(identity,copied_identity); - if (NS_FAILED(rv)) return rv; - - rv = SetNewsCopiesAndFolders(copied_identity); - if (NS_FAILED(rv)) return rv; - - // hook them together - account->SetIncomingServer(server); - account->AddIdentity(copied_identity); - - rv = MigrateOldNntpPrefs(server, hostAndPort, newsrcfile); - if (NS_FAILED(rv)) return rv; - - // can't do dir += "host-"; dir += hostname; - // because += on a nsFileSpec inserts a separator - // so we'd end up with host-/ and not host- - nsCAutoString alteredHost ((const char *) "host-"); - alteredHost += hostAndPort; - NS_MsgHashIfNecessary(alteredHost); - thisNewsHostsDir += (const char *) alteredHost; - - nsCOMPtr newsDir; - PRBool dirExists; - rv = NS_NewFileSpecWithSpec(thisNewsHostsDir, getter_AddRefs(newsDir)); - if (NS_FAILED(rv)) return rv; - - // set the local path for this "nntp" server - rv = server->SetLocalPath(newsDir); - if (NS_FAILED(rv)) return rv; - - rv = newsDir->Exists(&dirExists); - if (!dirExists) { - newsDir->CreateDir(); - } - - return NS_OK; -} - -nsresult -nsMsgAccountManager::MigrateOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostAndPort, nsFileSpec & newsrcfile) -{ - nsresult rv; - - // some of this ought to be moved out into the NNTP implementation - nsCOMPtr nntpServer; - nntpServer = do_QueryInterface(server, &rv); - if (NS_FAILED(rv)) return rv; - - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_NEWS_NOTIFY_ON,nntpServer,SetNotifyOn) - MIGRATE_SIMPLE_BOOL_PREF(PREF_4X_NEWS_MARK_OLD_READ,nntpServer,SetMarkOldRead) - MIGRATE_SIMPLE_INT_PREF(PREF_4X_NEWS_MAX_ARTICLES,nntpServer,SetMaxArticles) - - -#ifdef SUPPORT_SNEWS -#error THIS_CODE_ISNT_DONE_YET -#ifdef CAN_UPGRADE_4x_PASSWORDS - MIGRATE_STR_PREF("???nntp.server.%s.password",hostAndPort,server,SetPassword) -#else - rv = server->SetPassword(nsnull); - if (NS_FAILED(rv)) return rv; -#endif /* CAN_UPGRADE_4x_PASSWORDS */ -#endif /* SUPPORT_SNEWS */ - - nsCOMPtr path; - rv = NS_NewFileSpecWithSpec(newsrcfile, getter_AddRefs(path)); - if (NS_FAILED(rv)) return rv; - - nntpServer->SetNewsrcFilePath(path); - - return NS_OK; -} - NS_IMETHODIMP nsMsgAccountManager::FindServer(const char* username, const char* hostname, diff --git a/mailnews/base/src/nsMsgAccountManager.h b/mailnews/base/src/nsMsgAccountManager.h index 81180ca547cf..af5999ee4878 100644 --- a/mailnews/base/src/nsMsgAccountManager.h +++ b/mailnews/base/src/nsMsgAccountManager.h @@ -30,41 +30,6 @@ #include "nsIObserver.h" #include "nsWeakReference.h" -/* - * some platforms (like Windows and Mac) use a map file, because of - * file name length limitations. - */ -#if defined(XP_UNIX) || defined(XP_BEOS) -/* in 4.x, the prefix was ".newsrc-", in 5.0, the profile migrator code copies the newsrc files from - * ~/.newsrc-* to ~/.mozilla//News/newsrc-* - */ -#define NEWSRC_FILE_PREFIX_5x "newsrc-" -#else -#define USE_NEWSRC_MAP_FILE - -// in the fat file, the hostname is prefix by this string: -#define PSUEDO_NAME_PREFIX "newsrc-" - -#if defined(XP_PC) -#define NEWS_FCC_DEFAULT_TO_IMAP_SENT -#define NEWS_FAT_FILE_NAME "fat" -/* - * on the PC, the fat file stores absolute paths to the newsrc files - * on the Mac, the fat file stores relative paths to the newsrc files - */ -#define NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS 1 -#elif defined(XP_MAC) -#define NEWS_FAT_FILE_NAME "NewsFAT" -#else -#error dont_know_what_your_news_fat_file_is -#endif /* XP_PC, XP_MAC */ - -#endif /* XP_UNIX || XP_BEOS */ - -#ifdef XP_UNIX -#define HAVE_MOVEMAIL 1 -#endif /* HAVE_MOVEMAIL */ - class nsMsgAccountManager : public nsIMsgAccountManager, public nsIObserver, @@ -88,8 +53,6 @@ public: private: PRBool m_accountsLoaded; - PRBool m_alreadySetNntpDefaultLocalPath; - PRBool m_alreadySetImapDefaultLocalPath; nsCOMPtr m_msgFolderCache; nsISupportsArray *m_accounts; @@ -174,44 +137,13 @@ private: static PRBool writeFolderCache(nsHashKey *aKey, void *aData, void *closure); static PRBool closeCachedConnections(nsHashKey *aKey, void *aData, void *closure); - // methods for migration / upgrading - nsresult MigrateIdentity(nsIMsgIdentity *identity); - nsresult MigrateSmtpServer(nsISmtpServer *server); - nsresult CopyIdentity(nsIMsgIdentity *srcIdentity, nsIMsgIdentity *destIdentity); - nsresult SetMailCopiesAndFolders(nsIMsgIdentity *identity, const char *username, const char *hostname); - nsresult SetNewsCopiesAndFolders(nsIMsgIdentity *identity); - - nsresult MigrateImapAccounts(nsIMsgIdentity *identity); - nsresult MigrateImapAccount(nsIMsgIdentity *identity, const char *hostAndPort); - - nsresult MigrateOldImapPrefs(nsIMsgIncomingServer *server, const char *hostAndPort); - - nsresult MigratePopAccount(nsIMsgIdentity *identity); - -#ifdef HAVE_MOVEMAIL - nsresult MigrateMovemailAccount(nsIMsgIdentity *identity); -#endif /* HAVE_MOVEMAIL */ - - nsresult MigrateLocalMailAccount(nsIMsgIdentity *identity); - - nsresult MigrateOldMailPrefs(nsIMsgIncomingServer *server); - - nsresult MigrateNewsAccounts(nsIMsgIdentity *identity); - nsresult MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostAndPort, nsFileSpec &newsrcfile, nsFileSpec &newsHostsDir); - nsresult MigrateOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostAndPort, nsFileSpec &newsrcfile); - - nsresult ProceedWithMigration(); - static char *getUniqueKey(const char* prefix, nsHashtable *hashTable); static char *getUniqueAccountKey(const char* prefix, nsISupportsArray *accounts); - nsresult Convert4XUri(const char *old_uri, PRBool for_news, const char *aUsername, const char *aHostname, const char *default_folder_name, char **new_uri); - nsresult SetSendLaterUriPref(nsIMsgIncomingServer *server); nsresult getPrefService(); nsIPref *m_prefs; - PRInt32 m_oldMailType; }; diff --git a/mailnews/compose/resources/content/MsgComposeCommands.js b/mailnews/compose/resources/content/MsgComposeCommands.js index 896cf0d44e81..0d80419b6d8f 100644 --- a/mailnews/compose/resources/content/MsgComposeCommands.js +++ b/mailnews/compose/resources/content/MsgComposeCommands.js @@ -21,6 +21,8 @@ var accountManagerProgID = "component://netscape/messenger/account-manager"; var accountManager = Components.classes[accountManagerProgID].getService(Components.interfaces.nsIMsgAccountManager); +var messengerMigratorProgID = "component://netscape/messenger/migrator"; + var msgComposeService = Components.classes["component://netscape/messengercompose"].getService(); msgComposeService = msgComposeService.QueryInterface(Components.interfaces.nsIMsgComposeService); var msgCompose = null; @@ -281,7 +283,8 @@ function MigratePrefsIfNecessary() if (accounts.Count() > 0) return; try { - accountManager.UpgradePrefs(); + messengerMigrator = Components.classes[messengerMigratorProgID].getService(Components.interfaces.nsIMessengerMigrator); + messengerMigrator.UpgradePrefs(); } catch (ex) { var alertText = Bundle.GetStringFromName("noIdentities");