From f938e3ca925e2ee9a3217c8e1ff1bcfe2969a5de Mon Sep 17 00:00:00 2001 From: "tonyr%fbdesigns.com" Date: Mon, 18 Oct 1999 19:58:07 +0000 Subject: [PATCH] Added string bundles for the mailnews import tools --- mailnews/import/oexpress/makefile.win | 4 + mailnews/import/oexpress/nsOE5File.cpp | 12 +- mailnews/import/oexpress/nsOE5File.h | 2 +- mailnews/import/oexpress/nsOEImport.cpp | 116 +++++-- mailnews/import/oexpress/nsOEMailbox.cpp | 219 ++----------- mailnews/import/oexpress/nsOEMailbox.h | 2 +- mailnews/import/oexpress/nsOESettings.cpp | 49 ++- mailnews/import/oexpress/nsOEStringBundle.cpp | 81 +++++ mailnews/import/oexpress/nsOEStringBundle.h | 46 +++ .../resources/locale/en-us/makefile.win | 27 ++ .../locale/en-us/oeImportMsgs.properties | 56 ++++ .../oexpress/resources/locale/makefile.win | 22 ++ .../import/oexpress/resources/makefile.win | 22 ++ .../import/public/nsIImportAddressBooks.idl | 4 +- mailnews/import/public/nsIImportGeneric.idl | 4 +- mailnews/import/public/nsIImportMail.idl | 4 +- .../import/resources/content/import-test.html | 35 +- .../locale/en-us/importMsgs.properties | 83 +++++ .../resources/locale/en-us/makefile.win | 27 ++ mailnews/import/resources/locale/makefile.win | 22 ++ mailnews/import/resources/makefile.win | 2 +- mailnews/import/src/makefile.win | 1 + mailnews/import/src/nsImportAddressBooks.cpp | 98 +++++- mailnews/import/src/nsImportMail.cpp | 300 ++++++++++++++---- mailnews/import/src/nsImportStringBundle.cpp | 81 +++++ mailnews/import/src/nsImportStringBundle.h | 50 +++ .../chrome/mailnews/importMsgs.properties | 83 +++++ .../chrome/mailnews/oeImportMsgs.properties | 56 ++++ 28 files changed, 1197 insertions(+), 311 deletions(-) create mode 100644 mailnews/import/oexpress/nsOEStringBundle.cpp create mode 100644 mailnews/import/oexpress/nsOEStringBundle.h create mode 100644 mailnews/import/oexpress/resources/locale/en-us/makefile.win create mode 100644 mailnews/import/oexpress/resources/locale/en-us/oeImportMsgs.properties create mode 100644 mailnews/import/oexpress/resources/locale/makefile.win create mode 100644 mailnews/import/oexpress/resources/makefile.win create mode 100644 mailnews/import/resources/locale/en-us/importMsgs.properties create mode 100644 mailnews/import/resources/locale/en-us/makefile.win create mode 100644 mailnews/import/resources/locale/makefile.win create mode 100644 mailnews/import/src/nsImportStringBundle.cpp create mode 100644 mailnews/import/src/nsImportStringBundle.h create mode 100644 suite/locales/en-US/chrome/mailnews/importMsgs.properties create mode 100644 suite/locales/en-US/chrome/mailnews/oeImportMsgs.properties diff --git a/mailnews/import/oexpress/makefile.win b/mailnews/import/oexpress/makefile.win index c044d94f2f2..3d850e0552a 100644 --- a/mailnews/import/oexpress/makefile.win +++ b/mailnews/import/oexpress/makefile.win @@ -16,6 +16,9 @@ # Reserved. DEPTH=..\..\.. + +DIRS=resources + MODULE=importOE MAKE_OBJ_TYPE=DLL @@ -33,6 +36,7 @@ CPP_OBJS=\ .\$(OBJDIR)\nsOERegUtil.obj \ .\$(OBJDIR)\nsOE5File.obj \ .\$(OBJDIR)\nsOESettings.obj \ + .\$(OBJDIR)\nsOEStringBundle.obj \ $(NULL) LLIBS=\ diff --git a/mailnews/import/oexpress/nsOE5File.cpp b/mailnews/import/oexpress/nsOE5File.cpp index 550f4dad24d..3fdc0d16e40 100644 --- a/mailnews/import/oexpress/nsOE5File.cpp +++ b/mailnews/import/oexpress/nsOE5File.cpp @@ -217,10 +217,13 @@ PRBool nsOE5File::IsFromLine( char *pLine, PRUint32 len) #define kMailboxBufferSize 0x4000 const char *nsOE5File::m_pFromLineSep = "From ????@???? 1 Jan 1965 00:00:00\x0D\x0A"; -nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination) +nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRInt32 *pCount) { nsresult rv; - + PRInt32 msgCount = 0; + if (pCount) + *pCount = 0; + rv = inFile->OpenStreamForReading(); if (NS_FAILED( rv)) return( rv); rv = pDestination->OpenStreamForWriting(); @@ -312,6 +315,8 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * last2[0] = 13; last2[1] = 10; } + + msgCount++; } else { // Error reading message, should this be logged??? @@ -324,6 +329,9 @@ nsresult nsOE5File::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * delete [] pBuffer; inFile->CloseStream(); pDestination->CloseStream(); + + if (pCount) + *pCount = msgCount; return( rv); } diff --git a/mailnews/import/oexpress/nsOE5File.h b/mailnews/import/oexpress/nsOE5File.h index d6b0a69bbf8..0d6ca3bd0b6 100644 --- a/mailnews/import/oexpress/nsOE5File.h +++ b/mailnews/import/oexpress/nsOE5File.h @@ -32,7 +32,7 @@ public: static PRBool ReadIndex( nsIFileSpec *pFile, PRUint32 **ppIndex, PRUint32 *pSize); - static nsresult ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination); + static nsresult ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec *inFile, nsIFileSpec *pDestination, PRInt32 *pCount); private: typedef struct { diff --git a/mailnews/import/oexpress/nsOEImport.cpp b/mailnews/import/oexpress/nsOEImport.cpp index 98b776a8737..ba08c13d4db 100644 --- a/mailnews/import/oexpress/nsOEImport.cpp +++ b/mailnews/import/oexpress/nsOEImport.cpp @@ -43,6 +43,8 @@ #include "nsOE5File.h" #include "nsIAddrDatabase.h" #include "nsOESettings.h" +#include "nsTextFormater.h" +#include "nsOEStringBundle.h" #include "OEDebugLog.h" @@ -73,15 +75,16 @@ public: /* void ImportMailbox (in nsIImportMailboxDescriptor source, in nsIFileSpec destination, out boolean fatalError); */ NS_IMETHOD ImportMailbox(nsIImportMailboxDescriptor *source, nsIFileSpec *destination, - nsIOutputStream *pErrorLog, nsIOutputStream *pSuccessLog, PRBool *fatalError); + PRUnichar **pErrorLog, PRUnichar **pSuccessLog, PRBool *fatalError); /* unsigned long GetImportProgress (); */ NS_IMETHOD GetImportProgress(PRUint32 *_retval); - /* wstring GetErrorString (); */ - NS_IMETHOD GetErrorString(PRUnichar **_retval); - private: + static void ReportSuccess( nsString& name, PRInt32 count, nsString *pStream); + static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream); + static void AddLinebreak( nsString *pStream); + static void SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess); }; class ImportAddressImpl : public nsIImportAddressBooks @@ -121,8 +124,8 @@ public: NS_IMETHOD ImportAddressBook( nsIImportABDescriptor *source, nsIAddrDatabase * destination, nsISupports * fieldMap, - nsIOutputStream * errorLog, - nsIOutputStream * successLog, + PRUnichar ** errorLog, + PRUnichar ** successLog, PRBool * fatalError); /* unsigned long GetImportProgress (); */ @@ -178,8 +181,9 @@ NS_IMETHODIMP nsOEImport::GetName( PRUnichar **name) if (! name) return NS_ERROR_NULL_POINTER; - nsString title = "Outlook Express"; - *name = title.ToNewUnicode(); + // nsString title = "Outlook Express"; + // *name = title.ToNewUnicode(); + *name = nsOEStringBundle::GetStringByID( OEIMPORT_NAME); return NS_OK; } @@ -190,8 +194,9 @@ NS_IMETHODIMP nsOEImport::GetDescription( PRUnichar **name) if (! name) return NS_ERROR_NULL_POINTER; - nsString desc = "Outlook Express mail and address books"; - *name = desc.ToNewUnicode(); + // nsString desc = "Outlook Express mail and address books"; + // *name = desc.ToNewUnicode(); + *name = nsOEStringBundle::GetStringByID( OEIMPORT_DESCRIPTION); return NS_OK; } @@ -228,6 +233,9 @@ NS_IMETHODIMP nsOEImport::GetImportInterface( const char *pImportType, nsISuppor rv = impSvc->CreateNewGenericMail( &pGeneric); if (NS_SUCCEEDED( rv)) { pGeneric->SetData( "mailInterface", pMail); + nsString name; + nsOEStringBundle::GetStringByID( OEIMPORT_NAME, name); + pGeneric->SetData( "name", (nsISupports *) name.GetUnicode()); rv = pGeneric->QueryInterface( kISupportsIID, (void **)ppInterface); } } @@ -342,18 +350,66 @@ NS_IMETHODIMP ImportMailImpl::FindMailboxes( nsIFileSpec *pLoc, nsISupportsArray return( NS_OK); } +void ImportMailImpl::AddLinebreak( nsString *pStream) +{ + if (pStream) + pStream->Append( NS_LINEBREAK); +} + +void ImportMailImpl::ReportSuccess( nsString& name, PRInt32 count, nsString *pStream) +{ + if (!pStream) + return; + // load the success string + PRUnichar *pFmt = nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_SUCCESS); + PRUnichar *pText = nsTextFormater::smprintf( pFmt, name.GetUnicode(), count); + pStream->Append( pText); + nsTextFormater::smprintf_free( pText); + nsOEStringBundle::FreeString( pFmt); + AddLinebreak( pStream); +} + +void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream) +{ + if (!pStream) + return; + // load the error string + PRUnichar *pFmt = nsOEStringBundle::GetStringByID( errorNum); + PRUnichar *pText = nsTextFormater::smprintf( pFmt, name.GetUnicode()); + pStream->Append( pText); + nsTextFormater::smprintf_free( pText); + nsOEStringBundle::FreeString( pFmt); + AddLinebreak( pStream); +} + + +void ImportMailImpl::SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess) +{ + if (pError) + *pError = error.ToNewUnicode(); + if (pSuccess) + *pSuccess = success.ToNewUnicode(); +} NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource, nsIFileSpec *pDestination, - nsIOutputStream *pErrorLog, - nsIOutputStream *pSuccessLog, + PRUnichar **pErrorLog, + PRUnichar **pSuccessLog, PRBool *fatalError) { NS_PRECONDITION(pSource != nsnull, "null ptr"); NS_PRECONDITION(pDestination != nsnull, "null ptr"); NS_PRECONDITION(fatalError != nsnull, "null ptr"); - if (!pSource || !pDestination || !fatalError) - return NS_ERROR_NULL_POINTER; + + nsString success; + nsString error; + if (!pSource || !pDestination || !fatalError) { + nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_BADPARAM, error); + if (fatalError) + *fatalError = PR_TRUE; + SetLogs( success, error, pErrorLog, pSuccessLog); + return NS_ERROR_NULL_POINTER; + } PRBool abort = PR_FALSE; nsString name; @@ -366,11 +422,15 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource PRUint32 mailSize = 0; pSource->GetSize( &mailSize); if (mailSize == 0) { + ReportSuccess( name, 0, &success); + SetLogs( success, error, pErrorLog, pSuccessLog); return( NS_OK); } nsIFileSpec * inFile; if (NS_FAILED( pSource->GetFileSpec( &inFile))) { + ReportError( OEIMPORT_MAILBOX_BADSOURCEFILE, name, &error); + SetLogs( success, error, pErrorLog, pSuccessLog); return( NS_ERROR_FAILURE); } @@ -381,13 +441,14 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource nsCRT::free( pPath); #endif + PRInt32 msgCount = 0; nsresult rv; if (nsOE5File::IsLocalMailFile( inFile)) { IMPORT_LOG1( "Importing OE5 mailbox: %S!\n", name.GetUnicode()); - rv = nsOE5File::ImportMailbox( &abort, name, inFile, pDestination); + rv = nsOE5File::ImportMailbox( &abort, name, inFile, pDestination, &msgCount); } else { - if (CImportMailbox::ImportMailbox( &abort, name, inFile, pDestination)) { + if (CImportMailbox::ImportMailbox( &abort, name, inFile, pDestination, &msgCount)) { rv = NS_OK; } else { @@ -397,6 +458,15 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource inFile->Release(); + if (NS_SUCCEEDED( rv)) { + ReportSuccess( name, msgCount, &success); + } + else { + ReportError( OEIMPORT_MAILBOX_CONVERTERROR, name, &error); + } + + SetLogs( success, error, pErrorLog, pSuccessLog); + return( rv); } @@ -413,16 +483,6 @@ NS_IMETHODIMP ImportMailImpl::GetImportProgress( PRUint32 *pDoneSoFar) return( NS_OK); } -NS_IMETHODIMP ImportMailImpl::GetErrorString( PRUnichar **pDisplayError) -{ - NS_PRECONDITION(pDisplayError != nsnull, "null ptr"); - if (! pDisplayError) - return NS_ERROR_NULL_POINTER; - - *pDisplayError = nsnull; - return( NS_ERROR_FAILURE); -} - nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport) @@ -527,8 +587,8 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupp NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source, nsIAddrDatabase * destination, nsISupports * fieldMap, - nsIOutputStream * errorLog, - nsIOutputStream * successLog, + PRUnichar ** errorLog, + PRUnichar ** successLog, PRBool * fatalError) { NS_PRECONDITION(source != nsnull, "null ptr"); diff --git a/mailnews/import/oexpress/nsOEMailbox.cpp b/mailnews/import/oexpress/nsOEMailbox.cpp index 40ddd14215f..341fe70487f 100644 --- a/mailnews/import/oexpress/nsOEMailbox.cpp +++ b/mailnews/import/oexpress/nsOEMailbox.cpp @@ -42,6 +42,8 @@ private: PRBool CopyMbxFileBytes( PRUint32 numBytes); PRBool IsFromLineKey( PRUint8 *pBuf, PRUint32 max); +public: + PRInt32 m_msgCount; protected: nsString m_name; @@ -84,7 +86,7 @@ private: }; -PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile) +PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRInt32 *pCount) { PRBool done = PR_FALSE; nsIFileSpec *idxFile; @@ -100,8 +102,11 @@ PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpe CIndexScanner *pIdxScanner = new CIndexScanner( name, idxFile, inFile, outFile); if (pIdxScanner->Initialize()) { - if (pIdxScanner->DoWork( pAbort)) + if (pIdxScanner->DoWork( pAbort)) { done = PR_TRUE; + if (pCount) + *pCount = pIdxScanner->m_msgCount; + } else { IMPORT_LOG0( "CIndexScanner::DoWork() failed\n"); } @@ -117,15 +122,18 @@ PRBool CImportMailbox::ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpe if (done) return( done); - + /* something went wrong with the index file, just scan the mailbox file itself. */ CMbxScanner *pMbx = new CMbxScanner( name, inFile, outFile); if (pMbx->Initialize()) { - if (pMbx->DoWork( pAbort)) + if (pMbx->DoWork( pAbort)) { done = PR_TRUE; + if (pCount) + *pCount = pMbx->m_msgCount; + } else { IMPORT_LOG0( "CMbxScanner::DoWork() failed\n"); } @@ -170,164 +178,6 @@ PRBool CImportMailbox::GetIndexFile( nsIFileSpec* file) return( PR_FALSE); } -/* Find out if there is a matching index file. - -BOOL CImportMail::GetIndexFile( UFileLocation& mbxToIdx) -{ - CString ext; - ext.LoadString( IDS_OUTLOOK_IDX_EXTENSION); - mbxToIdx.ReplaceExtension( ext); - return( mbxToIdx.FileExists()); -} -*/ - - -/* - How to drive the scanners, special note that - if the idx scanner fails, we can try the mbx scanner - to see if it works. - -BOOL CImportMail::DoIdleWork( BOOL *pDone) -{ - BOOL result; - - *pDone = FALSE; - switch( m_state) { - case kStartState: - CalculateSizes(); - m_state = kDoMailbox; - break; - - case kDoMailbox: - if (!PrepMailboxImport( TRUE)) { - m_state = kMbxErrorState; - } - break; - - case kScanIdx: - if (m_pIdxScanner) { - if (!m_pIdxScanner->DoWork( pDone)) { - // if the error was fatal then abort - *pDone = FALSE; - if (m_pIdxScanner->WasErrorFatal()) - m_state = kMbxErrorState; - else - m_state = kPrepScanMbx; - delete m_pIdxScanner; - m_pIdxScanner = NULL; - } - else - m_bytesDone += m_pIdxScanner->BytesProcessed(); - if (*pDone) { - delete m_pIdxScanner; - m_pIdxScanner = NULL; - m_state = kNextMailbox; - *pDone = FALSE; - } - } - else // should never get here - m_state = kAllDone; - break; - - case kPrepScanMbx: - if (!PrepMailboxImport( FALSE)) - m_state = kMbxErrorState; - break; - - case kScanMbx: - if (m_pMbxScanner) { - result = m_pMbxScanner->DoWork( pDone); - m_bytesDone += m_pMbxScanner->BytesProcessed(); - if (!result || *pDone) { - *pDone = FALSE; - delete m_pMbxScanner; - m_pMbxScanner = NULL; - if (!result) - m_state = kMbxErrorState; - else - m_state = kNextMailbox; - } - } - else // should never get here - m_state = kAllDone; - break; - - case kNextMailbox: - m_bytesDone += kProgressBytesPerFile; - m_curFileIndex++; - if (m_curFileIndex >= m_pDst->GetSize()) { - // successful completion... - m_bDeleteWork = FALSE; - m_bytesDone = m_totalBytes; - m_state = kAllDone; - } - else - m_state = kDoMailbox; - break; - - case kMbxErrorState: - if (ReportMbxError()) - m_state = kNextMailbox; - else - return( FALSE); - break; - - default: - *pDone = TRUE; - } - - return( TRUE); -} -*/ - - -/* - The basic scheme is to prep, the either do the idxscanner or mbxscanner - depending upon which was available. All fo this can be moved into a routine - that just does it sequentially since our new concept is threads! - -BOOL CImportMail::PrepMailboxImport( BOOL prepIdx) -{ - // given the current source index - // set up to scan either the idx file or the mbx file... - UFileLocation src; - UFileLocation srcIdx; - UFileLocation dst; - CString name; - - m_pSrc->GetAt( m_curFileIndex, src); - m_pDst->GetAt( m_curFileIndex, dst); - name = m_pNames->GetAt( m_curFileIndex); - - srcIdx = src; - BOOL doIdx = FALSE; - if (prepIdx && GetIndexFile( srcIdx)) { - m_pIdxScanner = new CIndexScanner( name, srcIdx, src, dst); - if (m_pIdxScanner->Initialize()) { - doIdx = TRUE; - m_state = kScanIdx; - } - else { - delete m_pIdxScanner; - m_pIdxScanner = NULL; - } - } - if (!doIdx) { - // blow off the index and go straight to the mbx file... - m_pMbxScanner = new CMbxScanner( name, src, dst); - if (m_pMbxScanner->Initialize()) { - m_state = kScanMbx; - } - else { - delete m_pMbxScanner; - m_pMbxScanner = NULL; - m_state = kMbxErrorState; - } - } - - return( TRUE); -} -*/ const char *CMbxScanner::m_pFromLine = "From ????@???? 1 Jan 1965 00:00:00\x0D\x0A"; // let's try a 16K buffer and see how well that works? @@ -336,6 +186,7 @@ const char *CMbxScanner::m_pFromLine = "From ????@???? 1 Jan 1965 00:00:00\x0D\x CMbxScanner::CMbxScanner( nsString& name, nsIFileSpec* mbxFile, nsIFileSpec* dstFile) { + m_msgCount = 0; m_name = name; m_mbxFile = mbxFile; m_mbxFile->AddRef(); @@ -362,23 +213,11 @@ CMbxScanner::~CMbxScanner() void CMbxScanner::ReportWriteError( nsIFileSpec * file, PRBool fatal) { m_fatalError = fatal; - /* - CString path; - file.GetTextPath( path); - UDialogs::ErrMessage1( IDS_FILE_WRITE_ERROR, path); - */ - // FIXME: We should log errors of this kind? } void CMbxScanner::ReportReadError( nsIFileSpec * file, PRBool fatal) { m_fatalError = fatal; - /* - CString path; - file.GetTextPath( path); - UDialogs::ErrMessage1( IDS_FILE_READ_ERROR, path); - */ - // FIXME: We should log errors of this kind? } PRBool CMbxScanner::Initialize( void) @@ -387,21 +226,17 @@ PRBool CMbxScanner::Initialize( void) m_pInBuffer = new PRUint8[m_bufSz]; m_pOutBuffer = new PRUint8[m_bufSz]; if (!m_pInBuffer || !m_pOutBuffer) { - // UDialogs::ErrMessage0( IDS_NO_MEMORY); - // FIXME: Log the error message? return( PR_FALSE); } m_mbxFile->GetFileSize( &m_mbxFileSize); // open the mailbox file... if (NS_FAILED( m_mbxFile->OpenStreamForReading())) { - // FIXME: Log the error? CleanUp(); return( PR_FALSE); } if (NS_FAILED( m_dstFile->OpenStreamForWriting())) { - // FIXME: Log the error? CleanUp(); return( PR_FALSE); } @@ -427,6 +262,7 @@ PRBool CMbxScanner::DoWork( PRBool *pAbort) } m_mbxOffset += msgSz; m_didBytes += msgSz; + m_msgCount++; } CleanUp(); @@ -467,24 +303,20 @@ PRBool CMbxScanner::WriteMailItem( PRUint32 flags, PRUint32 offset, PRUint32 siz m_mbxFile->Failed( &failed); if (NS_FAILED( rv) || failed) { - // FIXME: Log errors? - // TRACE1( "Mbx seek error: 0x%lx\n", offset); + IMPORT_LOG1( "Mbx seek error: 0x%lx\n", offset); return( PR_FALSE); } rv = m_mbxFile->Read( (char **) &pChar, cnt, &cntRead); if (NS_FAILED( rv) || (cntRead != cnt)) { - // FIXME: Log errors? - // TRACE1( "Mbx read error at: 0x%lx\n", offset); + IMPORT_LOG1( "Mbx read error at: 0x%lx\n", offset); return( PR_FALSE); } if (values[0] != 0x7F007F00) { - // FIXME: Log errors? - // TRACE2( "Mbx tag field doesn't match: 0x%lx, at offset: 0x%lx\n", values[0], offset); + IMPORT_LOG2( "Mbx tag field doesn't match: 0x%lx, at offset: 0x%lx\n", values[0], offset); return( PR_FALSE); } if (size && (values[2] != size)) { - // FIXME: Log errors? - // TRACE3( "Mbx size doesn't match idx, mbx: %ld, idx: %ld, at offset: 0x%lx\n", values[2], size, offset); + IMPORT_LOG3( "Mbx size doesn't match idx, mbx: %ld, idx: %ld, at offset: 0x%lx\n", values[2], size, offset); return( PR_FALSE); } @@ -665,7 +497,6 @@ PRBool CIndexScanner::Initialize( void) nsresult rv = m_idxFile->OpenStreamForReading(); if (NS_FAILED( rv)) { - // FIXME: Log the error? CleanUp(); return( PR_FALSE); } @@ -694,7 +525,7 @@ PRBool CIndexScanner::ValidateIdxFile( void) if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); if (subId != 0x00010004) { - // TRACE1( "Idx file subid doesn't match: 0x%lx\n", subId); + IMPORT_LOG1( "Idx file subid doesn't match: 0x%lx\n", subId); return( PR_FALSE); } @@ -703,7 +534,7 @@ PRBool CIndexScanner::ValidateIdxFile( void) if (NS_FAILED( rv) || (cntRead != cnt)) return( PR_FALSE); - // TRACE1( "Idx file num messages: %ld\n", m_numMessages); + IMPORT_LOG1( "Idx file num messages: %ld\n", m_numMessages); m_didBytes += 80; m_idxOffset = 80; @@ -745,7 +576,7 @@ PRBool CIndexScanner::GetMailItem( PRUint32 *pFlags, PRUint32 *pOffset, PRUint32 return( PR_FALSE); if (values[3] != m_idxOffset) { - // TRACE2( "Self pointer invalid: m_idxOffset=0x%lx, self=0x%lx\n", m_idxOffset, values[3]); + IMPORT_LOG2( "Self pointer invalid: m_idxOffset=0x%lx, self=0x%lx\n", m_idxOffset, values[3]); return( PR_FALSE); } @@ -792,12 +623,14 @@ PRBool CIndexScanner::DoWork( PRBool *pAbort) return( PR_FALSE); } m_curItemIndex++; - if (!(flags & kOEDeletedFlag)) + if (!(flags & kOEDeletedFlag)) { if (!WriteMailItem( flags, offset, size)) failed = PR_TRUE; - else { - m_didBytes += size; + else { + m_msgCount++; + } } + m_didBytes += size; } CleanUp(); diff --git a/mailnews/import/oexpress/nsOEMailbox.h b/mailnews/import/oexpress/nsOEMailbox.h index dea287b5280..3261ecc9a38 100644 --- a/mailnews/import/oexpress/nsOEMailbox.h +++ b/mailnews/import/oexpress/nsOEMailbox.h @@ -26,7 +26,7 @@ class CImportMailbox { public: - static PRBool ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile); + static PRBool ImportMailbox( PRBool *pAbort, nsString& name, nsIFileSpec * inFile, nsIFileSpec * outFile, PRInt32 *pCount); private: static PRBool GetIndexFile( nsIFileSpec* mbxFile); diff --git a/mailnews/import/oexpress/nsOESettings.cpp b/mailnews/import/oexpress/nsOESettings.cpp index 228de9912b1..928c5ae6eab 100644 --- a/mailnews/import/oexpress/nsOESettings.cpp +++ b/mailnews/import/oexpress/nsOESettings.cpp @@ -38,7 +38,7 @@ #include "nsMsgCompCID.h" #include "nsISmtpService.h" #include "nsISmtpServer.h" - +#include "nsOEStringBundle.h" #include "OEDebugLog.h" static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); @@ -99,8 +99,7 @@ NS_IMETHODIMP nsOESettings::AutoLocate(PRUnichar **description, nsIFileSpec **lo if (!description || !_retval) return( NS_ERROR_NULL_POINTER); - nsString desc = "Outlook Express"; - *description = nsCRT::strdup( desc.GetUnicode()); + *description = nsOEStringBundle::GetStringByID( OEIMPORT_NAME); *_retval = PR_FALSE; if (location) @@ -326,8 +325,12 @@ PRBool OESettings::DoIMAPServer( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS // Create the incoming server and an account for it? rv = pMgr->CreateIncomingServer( "imap", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { + rv = in->SetType( "imap"); rv = in->SetHostName( pServerName); rv = in->SetUsername( (char *)pBytes); + + IMPORT_LOG2( "Created IMAP server named: %s, userName: %s\n", pServerName, (char *)pBytes); + BYTE *pAccName = nsOERegUtil::GetValueBytes( hKey, "Account Name"); nsString prettyName; if (pAccName) { @@ -338,6 +341,9 @@ PRBool OESettings::DoIMAPServer( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS prettyName = (const char *)pServerName; PRUnichar *pretty = prettyName.ToNewUnicode(); + + IMPORT_LOG1( "\tSet pretty name to: %S\n", pretty); + rv = in->SetPrettyName( pretty); nsCRT::free( pretty); @@ -346,6 +352,9 @@ PRBool OESettings::DoIMAPServer( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS rv = pMgr->CreateAccount( getter_AddRefs( account)); if (NS_SUCCEEDED( rv) && account) { rv = account->SetIncomingServer( in); + + IMPORT_LOG0( "Created an account and set the IMAP server as the incoming server\n"); + // Fiddle with the identities SetIdentities( pMgr, account, hKey); result = PR_TRUE; @@ -381,8 +390,12 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS // Create the incoming server and an account for it? rv = pMgr->CreateIncomingServer( "pop3", getter_AddRefs( in)); if (NS_SUCCEEDED( rv) && in) { + rv = in->SetType( "pop3"); rv = in->SetHostName( pServerName); rv = in->SetUsername( (char *)pBytes); + + IMPORT_LOG2( "Created POP3 server named: %s, userName: %s\n", pServerName, (char *)pBytes); + BYTE *pAccName = nsOERegUtil::GetValueBytes( hKey, "Account Name"); nsString prettyName; if (pAccName) { @@ -393,6 +406,9 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS prettyName = (const char *)pServerName; PRUnichar *pretty = prettyName.ToNewUnicode(); + + IMPORT_LOG1( "\tSet pretty name to: %S\n", pretty); + rv = in->SetPrettyName( pretty); nsCRT::free( pretty); @@ -400,7 +416,10 @@ PRBool OESettings::DoPOP3Server( nsIMsgAccountManager *pMgr, HKEY hKey, char *pS nsCOMPtr account; rv = pMgr->CreateAccount( getter_AddRefs( account)); if (NS_SUCCEEDED( rv) && account) { - rv = account->SetIncomingServer( in); + rv = account->SetIncomingServer( in); + + IMPORT_LOG0( "Created a new account and set the incoming server to the POP3 server.\n"); + // Fiddle with the identities SetIdentities( pMgr, account, hKey); result = PR_TRUE; @@ -479,6 +498,10 @@ void OESettings::SetIdentities( nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, if (pReply) id->SetReplyTo( pReply); pAcc->AddIdentity( id); + + IMPORT_LOG0( "Created identity and added to the account\n"); + IMPORT_LOG1( "\tname: %s\n", pName); + IMPORT_LOG1( "\temail: %s\n", pEmail); } } @@ -495,18 +518,28 @@ void OESettings::SetSmtpServer( nsIMsgAccountManager *pMgr, nsIMsgAccount *pAcc, { nsresult rv; -/* + NS_WITH_SERVICE(nsISmtpService, smtpService, kSmtpServiceCID, &rv); if (NS_SUCCEEDED(rv) && smtpService) { - nsCOMPtr smtpServer; + nsCOMPtr foundServer; + rv = smtpService->FindServer( pServer, getter_AddRefs( foundServer)); + if (NS_SUCCEEDED( rv) && foundServer) { + IMPORT_LOG1( "SMTP server already exists: %s\n", pServer); + return; + } + nsCOMPtr smtpServer; + rv = smtpService->CreateSmtpServer( getter_AddRefs( smtpServer)); if (NS_SUCCEEDED( rv) && smtpServer) { smtpServer->SetHostname( pServer); - smtpServer->SetUsername( pUser); + if (pUser) + smtpServer->SetUsername( pUser); + + IMPORT_LOG1( "Created new SMTP server: %s\n", pServer); } } -*/ + /* nsXPIDLCString hostName; nsXPIDLCString senderName; diff --git a/mailnews/import/oexpress/nsOEStringBundle.cpp b/mailnews/import/oexpress/nsOEStringBundle.cpp new file mode 100644 index 00000000000..fa027930f08 --- /dev/null +++ b/mailnews/import/oexpress/nsOEStringBundle.cpp @@ -0,0 +1,81 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- + * + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1999 Netscape Communications Corporation. All Rights + * Reserved. + */ +#include "prprf.h" +#include "prmem.h" +#include "nsCOMPtr.h" +#include "nsIStringBundle.h" +#include "nsOEStringBundle.h" +#include "nsIServiceManager.h" +#include "nsIURI.h" + +/* This is the next generation string retrieval call */ +static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); + +#define OE_MSGS_URL "chrome://messenger/locale/oeImportMsgs.properties" + +nsIStringBundle *nsOEStringBundle::GetStringBundle( void) +{ + nsresult rv; + char* propertyURL = OE_MSGS_URL; + nsIStringBundle* sBundle = nsnull; + + + NS_WITH_SERVICE(nsIStringBundleService, sBundleService, kStringBundleServiceCID, &rv); + if (NS_SUCCEEDED(rv) && (nsnull != sBundleService)) { + nsILocale * locale = nsnull; + rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle); + } + + return( sBundle); +} + +void nsOEStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle) +{ + + PRUnichar *ptrv = GetStringByID( stringID, pBundle); + result = ptrv; + FreeString( ptrv); +} + +PRUnichar *nsOEStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle *pBundle) +{ + PRBool mine = PR_FALSE; + if (!pBundle) { + mine = PR_TRUE; + pBundle = GetStringBundle(); + } + + if (pBundle) { + PRUnichar *ptrv = nsnull; + nsresult rv = pBundle->GetStringFromID(stringID, &ptrv); + + if (mine) { + NS_RELEASE(pBundle); + } + + if (NS_SUCCEEDED( rv) && ptrv) + return( ptrv); + } + + nsString resultString( "[StringID "); + resultString.Append(stringID, 10); + resultString += "?]"; + + return( resultString.ToNewUnicode()); +} + diff --git a/mailnews/import/oexpress/nsOEStringBundle.h b/mailnews/import/oexpress/nsOEStringBundle.h new file mode 100644 index 00000000000..7ab10eb1264 --- /dev/null +++ b/mailnews/import/oexpress/nsOEStringBundle.h @@ -0,0 +1,46 @@ +/* + * The contents of this file are subject to the Netscape Public License + * Version 1.0 (the "NPL"); you may not use this file except in + * compliance with the NPL. You may obtain a copy of the NPL at + * http://www.mozilla.org/NPL/ + * + * Software distributed under the NPL is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL + * for the specific language governing rights and limitations under the + * NPL. + * + * The Initial Developer of this code under the NPL is Netscape + * Communications Corporation. Portions created by Netscape are + * Copyright (C) 1998 Netscape Communications Corporation. All Rights + * Reserved. + */ + +#ifndef _nsOEStringBundle_H__ +#define _nsOEStringBundle_H__ + +#include "nsCRT.h" +#include "nsString.h" + +class nsIStringBundle; + +class nsOEStringBundle { +public: + static PRUnichar * GetStringByID(PRInt32 stringID, nsIStringBundle *pBundle = nsnull); + static void GetStringByID(PRInt32 stringID, nsString& result, nsIStringBundle *pBundle = nsnull); + // GetStringBundle creates a new one every time! + static nsIStringBundle * GetStringBundle( void); + static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);} +}; + + + +#define OEIMPORT_NAME 2000 +#define OEIMPORT_DESCRIPTION 2001 +#define OEIMPORT_MAILBOX_SUCCESS 2002 +#define OEIMPORT_MAILBOX_BADPARAM 2003 +#define OEIMPORT_MAILBOX_BADSOURCEFILE 2004 +#define OEIMPORT_MAILBOX_CONVERTERROR 2005 + + + +#endif /* _nsOEStringBundle_H__ */ diff --git a/mailnews/import/oexpress/resources/locale/en-us/makefile.win b/mailnews/import/oexpress/resources/locale/en-us/makefile.win new file mode 100644 index 00000000000..ca277fc1ed3 --- /dev/null +++ b/mailnews/import/oexpress/resources/locale/en-us/makefile.win @@ -0,0 +1,27 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1999 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\..\..\..\.. + +include <$(DEPTH)\config\rules.mak> + +install:: + $(MAKE_INSTALL) oeImportMsgs.properties $(DIST)\bin\chrome\messenger\locale\en-US + +clobber:: + rm -f $(DIST)bin\chrome\messenger\locale\en-US\oeImportMsgs.properties + diff --git a/mailnews/import/oexpress/resources/locale/en-us/oeImportMsgs.properties b/mailnews/import/oexpress/resources/locale/en-us/oeImportMsgs.properties new file mode 100644 index 00000000000..5449722d080 --- /dev/null +++ b/mailnews/import/oexpress/resources/locale/en-us/oeImportMsgs.properties @@ -0,0 +1,56 @@ +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1998 Netscape Communications Corporation. All Rights +# Reserved. +# + +# +# The following are used by the outlook express import code to display status/error +# and informational messages +# + +# Short name of import module +## @name OEIMPORT_NAME +## @loc None +2000=Outlook Express + +# Description of import module +## @name OEIMPORT_DESCRIPTION +## @loc None +2001=Outlook Express mail and address books + +# Success message +## @name OEIMPORT_MAILBOX_SUCCESS +## @loc None +2002=Mailbox %S, imported %d messages + +# Error message +## @name OEIMPORT_MAILBOX_BADPARAM +## @loc None +2003=Bad parameter passed to import mailbox. + +# Error message +## @name OEIMPORT_MAILBOX_BADSOURCEFILE +## @loc None +2004=Error accessing file for mailbox %S. + +# Error message +## @name OEIMPORT_MAILBOX_CONVERTERROR +## @loc None +2005=Error importing mailbox %S, all messages may not be imported from this mailbox. + + + + + + diff --git a/mailnews/import/oexpress/resources/locale/makefile.win b/mailnews/import/oexpress/resources/locale/makefile.win new file mode 100644 index 00000000000..21880dd6baf --- /dev/null +++ b/mailnews/import/oexpress/resources/locale/makefile.win @@ -0,0 +1,22 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1999 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\..\..\.. + +DIRS= en-US + +include <$(DEPTH)\config\rules.mak> diff --git a/mailnews/import/oexpress/resources/makefile.win b/mailnews/import/oexpress/resources/makefile.win new file mode 100644 index 00000000000..b5f4ba32ca9 --- /dev/null +++ b/mailnews/import/oexpress/resources/makefile.win @@ -0,0 +1,22 @@ +#!nmake +# +# The contents of this file are subject to the Netscape Public License +# Version 1.0 (the "NPL"); you may not use this file except in +# compliance with the NPL. You may obtain a copy of the NPL at +# http://www.mozilla.org/NPL/ +# +# Software distributed under the NPL is distributed on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL +# for the specific language governing rights and limitations under the +# NPL. +# +# The Initial Developer of this code under the NPL is Netscape +# Communications Corporation. Portions created by Netscape are +# Copyright (C) 1999 Netscape Communications Corporation. All Rights +# Reserved. + +DEPTH=..\..\..\.. + +DIRS= locale + +include <$(DEPTH)\config\rules.mak> diff --git a/mailnews/import/public/nsIImportAddressBooks.idl b/mailnews/import/public/nsIImportAddressBooks.idl index d2db46b29fc..314167ba658 100644 --- a/mailnews/import/public/nsIImportAddressBooks.idl +++ b/mailnews/import/public/nsIImportAddressBooks.idl @@ -121,8 +121,8 @@ interface nsIImportAddressBooks : nsISupports void ImportAddressBook( in nsIImportABDescriptor source, in nsIAddrDatabase destination, in nsISupports fieldMap, - in nsIOutputStream errorLog, - in nsIOutputStream successLog, + out wstring errorLog, + out wstring successLog, out boolean fatalError); /* diff --git a/mailnews/import/public/nsIImportGeneric.idl b/mailnews/import/public/nsIImportGeneric.idl index 92f843756c8..cf60f16dca8 100644 --- a/mailnews/import/public/nsIImportGeneric.idl +++ b/mailnews/import/public/nsIImportGeneric.idl @@ -26,7 +26,7 @@ interface nsIImportDriver; interface nsIDOMWindow; -interface nsIOutputStream; +interface nsISupportsWString; [scriptable, uuid(9b5c20c0-2348-11d3-a206-00a0cc26da63)] interface nsIImportGeneric : nsISupports @@ -83,7 +83,7 @@ interface nsIImportGeneric : nsISupports failure of the import. Failure can be reported even if WantsProgress returned TRUE. */ - boolean BeginImport( in nsIOutputStream successLog, in nsIOutputStream errorLog); + boolean BeginImport( in nsISupportsWString successLog, in nsISupportsWString errorLog); /* If WantsProgress returned TRUE then this will indicate if the import should continue. If this returns FALSE then no other methods should be called diff --git a/mailnews/import/public/nsIImportMail.idl b/mailnews/import/public/nsIImportMail.idl index b1983131d56..47cd23737ad 100644 --- a/mailnews/import/public/nsIImportMail.idl +++ b/mailnews/import/public/nsIImportMail.idl @@ -80,8 +80,8 @@ interface nsIImportMail : nsISupports */ void ImportMailbox( in nsIImportMailboxDescriptor source, in nsIFileSpec destination, - in nsIOutputStream errorLog, - in nsIOutputStream successLog, + out wstring errorLog, + out wstring successLog, out boolean fatalError); /* diff --git a/mailnews/import/resources/content/import-test.html b/mailnews/import/resources/content/import-test.html index 953e1e70a25..2aa0216de5b 100644 --- a/mailnews/import/resources/content/import-test.html +++ b/mailnews/import/resources/content/import-test.html @@ -2,7 +2,30 @@