Bug #249614 --> Porting tbird branch changes back to the trunk.

Changes to make the import module better support the new migration wizard for Outlook Express migrations.

1) Allow a consumer to pass in an RDF URI for an address book (i.e. the
personal AB) to migrate address book data too. This allows the OE migrator to
migrate address book data directly to a Personal Address book instead of to
"Outlook Express Address Book"

2) When migrating OE Pop3 servers, make them use the deferred account by
default (Local folder Global Inbox)

3) Add folder translation code to translate Outlook Express Local Folder names
into folder names Mozilla will recognize (like Deleted Items --> Trash)

4) If we are migrating local folders (as opposed to importing), migrate
directly into local folders and not as a sub folder of Local Folders.

sr=bienvenu


git-svn-id: svn://10.0.0.236/trunk@158728 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
scott%scott-macgregor.org
2004-07-04 05:19:34 +00:00
parent c3136d2ff9
commit f3db0d7076
10 changed files with 155 additions and 25 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);
}

View File

@@ -72,6 +72,7 @@ REQUIRES = xpcom \
msgbaseutil \
msgcompose \
msglocal \
unicharutil \
$(NULL)
CPPSRCS = \

View File

@@ -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");

View File

@@ -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<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in);
if (pop3Server) {
// set local folders as the Inbox to use for this POP3 server
nsCOMPtr<nsIMsgIncomingServer> 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 <nsIMessengerMigrator> 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<nsIMsgAccount> 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<nsIPop3IncomingServer> pop3Server = do_QueryInterface(in, &rv);

View File

@@ -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);
}

View File

@@ -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"
%}

View File

@@ -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<nsIURL> url = do_CreateInstance(NS_STANDARDURL_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv)) {
url->SetSpec( nsDependentCString(m_pDestinationUri));
NS_IF_ADDREF(*_retval = url);
}
nsCOMPtr<nsISupportsCString> 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<nsIURL> url;
item->QueryInterface( NS_GET_IID(nsIURL), getter_AddRefs( url));
if (url) {
nsCOMPtr<nsISupportsCString> 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)

View File

@@ -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<nsISupportsPRBool> 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<nsISupportsPRBool> 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 <nsIMsgFolder> 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<nsISupports> subFolder;
@@ -1028,6 +1062,7 @@ PRBool nsImportGenericMail::CreateFolder( nsIMsgFolder **ppFolder)
}
} // if subFolder
}
} // if not performing migration
}
} // if localRootFolder
} // if server