diff --git a/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.cpp b/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.cpp index 79789f33a2b..17507e0aa49 100644 --- a/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.cpp +++ b/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.cpp @@ -360,3 +360,8 @@ NS_IMETHODIMP ImportComm4xMailImpl::GetImportProgress(PRUint32 *pDoneSoFar) return NS_OK; } +NS_IMETHODIMP ImportComm4xMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval) +{ + _retval = aFolderName; + return NS_OK; +} diff --git a/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.h b/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.h index 086336a0d73..e0aaf3b4928 100644 --- a/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.h +++ b/mozilla/mailnews/import/comm4x/src/nsComm4xMailImport.h @@ -99,6 +99,8 @@ public: /* unsigned long GetImportProgress (); */ NS_IMETHOD GetImportProgress(PRUint32 *_retval); + NS_IMETHOD TranslateFolderName(const nsAString & aFolderName, nsAString & _retval); + public: static void SetLogs(nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess); void ReportStatus(PRInt32 errorNum, nsString& name, nsString *pStream); diff --git a/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp b/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp index ecde993a80d..a4dee538898 100644 --- a/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp +++ b/mozilla/mailnews/import/eudora/src/nsEudoraImport.cpp @@ -113,6 +113,8 @@ public: /* unsigned long GetImportProgress (); */ NS_IMETHOD GetImportProgress(PRUint32 *_retval); + NS_IMETHOD TranslateFolderName(const nsAString & aFolderName, nsAString & _retval); + public: static void AddLinebreak( nsString *pStream); static void SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess); @@ -557,6 +559,11 @@ NS_IMETHODIMP ImportEudoraMailImpl::GetImportProgress( PRUint32 *pDoneSoFar) } +NS_IMETHODIMP ImportEudoraMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval) +{ + _retval = aFolderName; + return NS_OK; +} nsresult ImportEudoraAddressImpl::Create(nsIImportAddressBooks** aImport) { @@ -762,3 +769,5 @@ NS_IMETHODIMP ImportEudoraAddressImpl::GetImportProgress(PRUint32 *_retval) return( NS_OK); } + + diff --git a/mozilla/mailnews/import/oexpress/Makefile.in b/mozilla/mailnews/import/oexpress/Makefile.in index 13c46b4a698..b1b8598dded 100644 --- a/mozilla/mailnews/import/oexpress/Makefile.in +++ b/mozilla/mailnews/import/oexpress/Makefile.in @@ -72,6 +72,7 @@ REQUIRES = xpcom \ msgbaseutil \ msgcompose \ msglocal \ + unicharutil \ $(NULL) CPPSRCS = \ diff --git a/mozilla/mailnews/import/oexpress/nsOEImport.cpp b/mozilla/mailnews/import/oexpress/nsOEImport.cpp index 9026f9ff76c..cf864e58902 100644 --- a/mozilla/mailnews/import/oexpress/nsOEImport.cpp +++ b/mozilla/mailnews/import/oexpress/nsOEImport.cpp @@ -75,6 +75,7 @@ #include "nsTextFormatter.h" #include "nsOEStringBundle.h" #include "nsIStringBundle.h" +#include "nsUnicharUtils.h" #include "OEDebugLog.h" @@ -107,6 +108,8 @@ public: /* unsigned long GetImportProgress (); */ NS_IMETHOD GetImportProgress(PRUint32 *_retval); + NS_IMETHOD TranslateFolderName(const nsAString & aFolderName, nsAString & _retval); + public: static void ReportSuccess( nsString& name, PRInt32 count, nsString *pStream); static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream); @@ -346,10 +349,22 @@ ImportOEMailImpl::~ImportOEMailImpl() { } - - NS_IMPL_THREADSAFE_ISUPPORTS1(ImportOEMailImpl, nsIImportMail) +NS_IMETHODIMP ImportOEMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval) +{ + if (aFolderName.Equals(NS_LITERAL_STRING("Deleted Items"), nsCaseInsensitiveStringComparator())) + _retval = NS_LITERAL_STRING(kDestTrashFolderName); + else if (aFolderName.Equals(NS_LITERAL_STRING("Sent Items"), nsCaseInsensitiveStringComparator())) + _retval = NS_LITERAL_STRING(kDestSentFolderName); + else if (aFolderName.Equals(NS_LITERAL_STRING("Outbox"), nsCaseInsensitiveStringComparator())) + _retval = NS_LITERAL_STRING(kDestUnsentMessagesFolderName); + else + _retval = aFolderName; + + return NS_OK; +} + NS_IMETHODIMP ImportOEMailImpl::GetDefaultLocation( nsIFileSpec **ppLoc, PRBool *found, PRBool *userVerify) { NS_PRECONDITION(ppLoc != nsnull, "null ptr"); diff --git a/mozilla/mailnews/import/oexpress/nsOESettings.cpp b/mozilla/mailnews/import/oexpress/nsOESettings.cpp index ade1ebdcb52..c6151b2bd08 100644 --- a/mozilla/mailnews/import/oexpress/nsOESettings.cpp +++ b/mozilla/mailnews/import/oexpress/nsOESettings.cpp @@ -61,6 +61,7 @@ #include "nsOEStringBundle.h" #include "OEDebugLog.h" #include "nsIPop3IncomingServer.h" +#include "nsIMessengerMigrator.h" class OESettings { public: @@ -414,6 +415,45 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS rv = in->SetHostName( pServerName); rv = in->SetUsername( (char *)pBytes); + nsCOMPtr pop3Server = do_QueryInterface(in); + if (pop3Server) { + // set local folders as the Inbox to use for this POP3 server + nsCOMPtr localFoldersServer; + pMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer)); + + if (!localFoldersServer) + { + // XXX: We may need to move this local folder creation code to the generic nsImportSettings code + // if the other import modules end up needing to do this too. + + // if Local Folders does not exist already, create it + nsCOMPtr messengerMigrator = do_GetService(NS_MESSENGERMIGRATOR_CONTRACTID, &rv); + if (NS_FAILED(rv)) { + IMPORT_LOG0( "*** Failed to create messenger migrator!\n"); + return PR_FALSE; + } + + rv = messengerMigrator->CreateLocalMailAccount(PR_FALSE); + if (NS_FAILED(rv)) { + IMPORT_LOG0( "*** Failed to create Local Folders!\n"); + return PR_FALSE; + } + + pMgr->GetLocalFoldersServer(getter_AddRefs(localFoldersServer)); + } + + // now get the account for this server + nsCOMPtr localFoldersAccount; + pMgr->FindAccountForServer(localFoldersServer, getter_AddRefs(localFoldersAccount)); + if (localFoldersAccount) + { + nsXPIDLCString localFoldersAcctKey; + localFoldersAccount->GetKey(getter_Copies(localFoldersAcctKey)); + pop3Server->SetDeferredToAccount(localFoldersAcctKey.get()); + pop3Server->SetDeferGetNewMail(PR_TRUE); + } + } + IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", pServerName, (char *)pBytes); nsString prettyName; @@ -432,7 +472,6 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS rv = pMgr->CreateAccount( getter_AddRefs( account)); if (NS_SUCCEEDED( rv) && account) { rv = account->SetIncomingServer( in); - IMPORT_LOG0( "Created a new account and set the incoming server to the POP3 server.\n"); nsCOMPtr pop3Server = do_QueryInterface(in, &rv); diff --git a/mozilla/mailnews/import/outlook/src/nsOutlookImport.cpp b/mozilla/mailnews/import/outlook/src/nsOutlookImport.cpp index 9dfd5a271f3..b4ae0aff5c1 100644 --- a/mozilla/mailnews/import/outlook/src/nsOutlookImport.cpp +++ b/mozilla/mailnews/import/outlook/src/nsOutlookImport.cpp @@ -106,6 +106,8 @@ public: /* unsigned long GetImportProgress (); */ NS_IMETHOD GetImportProgress(PRUint32 *_retval); + NS_IMETHOD TranslateFolderName(const nsAString & aFolderName, nsAString & _retval); + public: static void ReportSuccess( nsString& name, PRInt32 count, nsString *pStream); static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream); @@ -517,6 +519,11 @@ NS_IMETHODIMP ImportOutlookMailImpl::GetImportProgress( PRUint32 *pDoneSoFar) return( NS_OK); } +NS_IMETHODIMP ImportOutlookMailImpl::TranslateFolderName(const nsAString & aFolderName, nsAString & _retval) +{ + _retval = aFolderName; + return NS_OK; +} nsresult ImportOutlookAddressImpl::Create(nsIImportAddressBooks** aImport) @@ -676,4 +683,3 @@ void ImportOutlookAddressImpl::ReportSuccess( nsString& name, nsString *pStream) ImportOutlookMailImpl::AddLinebreak( pStream); NS_IF_RELEASE( pBundle); } - diff --git a/mozilla/mailnews/import/public/nsIImportMail.idl b/mozilla/mailnews/import/public/nsIImportMail.idl index 791ab88c37b..475814dbc24 100644 --- a/mozilla/mailnews/import/public/nsIImportMail.idl +++ b/mozilla/mailnews/import/public/nsIImportMail.idl @@ -110,10 +110,20 @@ interface nsIImportMail : nsISupports a different thread than ImportMailbox() */ unsigned long GetImportProgress(); + + /* + * When migrating the local folders from the import source into mozilla, + * we want to translate reserved folder names from the import source to + * equivalent values for Mozilla. + * Localization Impact is unknown here. + */ + AString translateFolderName(in AString aFolderName); }; %{ C++ - +#define kDestTrashFolderName "Trash" +#define kDestUnsentMessagesFolderName "Unsent Messages" +#define kDestSentFolderName "Sent" %} diff --git a/mozilla/mailnews/import/src/nsImportAddressBooks.cpp b/mozilla/mailnews/import/src/nsImportAddressBooks.cpp index cc52ddeb7a7..d1a4f505368 100644 --- a/mozilla/mailnews/import/src/nsImportAddressBooks.cpp +++ b/mozilla/mailnews/import/src/nsImportAddressBooks.cpp @@ -62,6 +62,7 @@ #include "nsRDFCID.h" #include "nsAbBaseCID.h" #include "nsIAbDirectory.h" +#include "nsIAddressBook.h" #include "nsImportStringBundle.h" #include "nsTextFormatter.h" #include "nsIProxyObjectManager.h" @@ -256,11 +257,10 @@ NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISuppor if (!nsCRT::strcasecmp( dataId, "addressDestination")) { if (m_pDestinationUri) { - nsCOMPtr url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv); - if (NS_SUCCEEDED(rv)) { - url->SetSpec( nsDependentCString(m_pDestinationUri)); - NS_IF_ADDREF(*_retval = url); - } + nsCOMPtr abString = do_CreateInstance(NS_SUPPORTS_CSTRING_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + abString->SetData(nsDependentCString(m_pDestinationUri)); + NS_IF_ADDREF( *_retval = abString); } } @@ -352,15 +352,15 @@ NS_IMETHODIMP nsImportGenericAddressBooks::SetData( const char *dataId, nsISuppo if (!nsCRT::strcasecmp( dataId, "addressDestination")) { if (item) { - nsCOMPtr url; - item->QueryInterface( NS_GET_IID(nsIURL), getter_AddRefs( url)); - if (url) { + nsCOMPtr abString; + item->QueryInterface( NS_GET_IID(nsISupportsCString), getter_AddRefs( abString)); + if (abString) { if (m_pDestinationUri) nsCRT::free( m_pDestinationUri); m_pDestinationUri = nsnull; - nsCAutoString spec; - url->GetSpec(spec); - m_pDestinationUri = ToNewCString(spec); + nsCAutoString tempUri; + abString->GetData(tempUri); + m_pDestinationUri = ToNewCString(tempUri); } } } @@ -745,7 +745,15 @@ void AddressThreadData::DriverAbort() nsIAddrDatabase *GetAddressBookFromUri( const char *pUri) { - return( nsnull); + nsIAddrDatabase * pDatabase = nsnull; + if (pUri) { + nsresult rv = NS_OK; + NS_WITH_PROXIED_SERVICE(nsIAddressBook, addressBook, NS_ADDRESSBOOK_CONTRACTID, NS_UI_THREAD_EVENTQ, &rv); + if (addressBook) + rv = addressBook->GetAbDatabaseFromURI(pUri, &pDatabase); + } + + return pDatabase; } nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew) diff --git a/mozilla/mailnews/import/src/nsImportMail.cpp b/mozilla/mailnews/import/src/nsImportMail.cpp index bbc9e97e051..d714fa6ca6d 100644 --- a/mozilla/mailnews/import/src/nsImportMail.cpp +++ b/mozilla/mailnews/import/src/nsImportMail.cpp @@ -147,6 +147,7 @@ private: PRUint32 m_totalSize; PRBool m_doImport; ImportThreadData * m_pThreadData; + PRBool m_performingMigration; }; class ImportThreadData { @@ -164,6 +165,7 @@ public: nsISupportsString * successLog; nsISupportsString * errorLog; PRUint32 currentMailbox; + PRBool performingMigration; ImportThreadData(); ~ImportThreadData(); @@ -207,6 +209,7 @@ nsImportGenericMail::nsImportGenericMail() m_pDestFolder = nsnull; m_deleteDestFolder = PR_FALSE; m_createdFolder = PR_FALSE; + m_performingMigration = PR_FALSE; // Init logging module. if (!IMPORTLOGMODULE) @@ -267,6 +270,13 @@ NS_IMETHODIMP nsImportGenericMail::GetData(const char *dataId, nsISupports **_re NS_IF_ADDREF( m_pDestFolder); } + if (!nsCRT::strcasecmp( dataId, "migration")) { + nsCOMPtr migrationString = do_CreateInstance(NS_SUPPORTS_PRBOOL_CONTRACTID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + migrationString->SetData(m_performingMigration); + NS_IF_ADDREF( *_retval = migrationString); + } + if (!nsCRT::strcasecmp( dataId, "currentMailbox")) { // create an nsISupportsString, get the current mailbox // name being imported and put it in the string @@ -330,6 +340,14 @@ NS_IMETHODIMP nsImportGenericMail::SetData( const char *dataId, nsISupports *ite } } + if (!nsCRT::strcasecmp( dataId, "migration")) { + nsCOMPtr migrationString; + if (item) { + item->QueryInterface( NS_GET_IID(nsISupportsPRBool), getter_AddRefs(migrationString)); + rv = migrationString->GetData(&m_performingMigration); + } + } + return rv; } @@ -531,6 +549,7 @@ NS_IMETHODIMP nsImportGenericMail::BeginImport(nsISupportsString *successLog, ns m_pThreadData->ownsDestRoot = m_deleteDestFolder; m_pThreadData->destRoot = m_pDestFolder; + m_pThreadData->performingMigration = m_performingMigration; NS_IF_ADDREF( m_pDestFolder); @@ -844,9 +863,18 @@ ImportMailThread( void *stuff) else lastName.AssignLiteral("Unknown!"); + // translate the folder name if we are doing migration + if (pData->performingMigration) + pData->mailImport->TranslateFolderName(lastName, lastName); + exists = PR_FALSE; rv = curProxy->ContainsChildNamed( lastName.get(), &exists); - if (exists) { + + // If we are performing profile migration (as opposed to importing) then we are starting + // with empty local folders. In that case, always choose to over-write the existing local folder + // with this name. Don't create a unique subfolder name. Otherwise you end up with "Inbox, Inbox0" + // or "Unsent Folders, UnsentFolders0" + if (exists && !pData->performingMigration) { nsXPIDLString subName; curProxy->GenerateUniqueSubfolderName( lastName.get(), nsnull, getter_Copies(subName)); if (!subName.IsEmpty()) @@ -854,10 +882,8 @@ ImportMailThread( void *stuff) } IMPORT_LOG1("ImportMailThread: Creating new import folder '%s'.", NS_ConvertUCS2toUTF8(lastName).get()); + curProxy->CreateSubfolder( lastName.get(),nsnull); // this may fail if the folder already exists..that's ok - rv = curProxy->CreateSubfolder( lastName.get(),nsnull); - - if (NS_SUCCEEDED( rv)) { rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder)); if (NS_SUCCEEDED( rv)) { newFolder = do_QueryInterface( subFolder); @@ -870,9 +896,6 @@ ImportMailThread( void *stuff) } else IMPORT_LOG1("*** ImportMailThread: Failed to locate subfolder '%s' after it's been created.", lastName.get()); - } - else - IMPORT_LOG1("*** ImportMailThread: Failed to create subfolder '%s'.", lastName.get()); if (NS_FAILED( rv)) { nsImportGenericMail::ReportError( IMPORT_ERROR_MB_CREATE, lastName.get(), &error); @@ -926,7 +949,6 @@ ImportMailThread( void *stuff) IMPORT_LOG0( "*** ImportMailThread: Abort or fatalError flag was set\n"); if (pData->ownsDestRoot) { IMPORT_LOG0( "Calling destRoot->RecursiveDelete\n"); - destRoot->RecursiveDelete( PR_TRUE, nsnull); } else { @@ -991,8 +1013,10 @@ PRBool nsImportGenericMail::CreateFolder( nsIMsgFolder **ppFolder) IMPORT_LOG0( "*** Failed to create Local Folders!\n"); return PR_FALSE; } + rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server)); } + if (NS_SUCCEEDED(rv) && server) { nsCOMPtr localRootFolder; rv = server->GetRootMsgFolder(getter_AddRefs(localRootFolder)); @@ -1016,6 +1040,16 @@ PRBool nsImportGenericMail::CreateFolder( nsIMsgFolder **ppFolder) } } IMPORT_LOG1( "Creating folder for importing mail: '%s'\n", NS_ConvertUCS2toUTF8(folderName).get()); + + // if we are doing migration, don't bother putting the local folders we are importing as a + // sub folder of local folders. + if (m_performingMigration) + { + NS_IF_ADDREF(*ppFolder = localRootFolder); + return PR_TRUE; + } + else + { rv = localRootFolder->CreateSubfolder(folderName.get(), nsnull); if (NS_SUCCEEDED(rv)) { nsCOMPtr subFolder; @@ -1028,6 +1062,7 @@ PRBool nsImportGenericMail::CreateFolder( nsIMsgFolder **ppFolder) } } // if subFolder } + } // if not performing migration } } // if localRootFolder } // if server