1999-09-06 22:24:10 +04:00
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
1999-11-06 06:43:54 +03:00
* The contents of this file are subject to the Netscape Public
* License Version 1.1 ( the " License " ) ; you may not use this file
* except in compliance with the License . You may obtain a copy of
* the License at http : //www.mozilla.org/NPL/
1999-09-06 22:24:10 +04:00
*
1999-11-06 06:43:54 +03:00
* Software distributed under the License is distributed on an " AS
* IS " basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied . See the License for the specific language governing
* rights and limitations under the License .
1999-09-06 22:24:10 +04:00
*
1999-11-06 06:43:54 +03:00
* The Original Code is mozilla . org code .
*
* The Initial Developer of the Original Code is Netscape
1999-09-06 22:24:10 +04:00
* Communications Corporation . Portions created by Netscape are
1999-11-06 06:43:54 +03:00
* Copyright ( C ) 1998 Netscape Communications Corporation . All
* Rights Reserved .
*
* Contributor ( s ) :
2000-02-06 06:18:27 +03:00
* Pierre Phaneuf < pp @ ludusdesign . com >
1999-09-06 22:24:10 +04:00
*/
/*
1999-09-10 07:29:46 +04:00
Outlook Express ( Win32 ) import mail and addressbook interfaces
1999-09-06 22:24:10 +04:00
*/
# include "nscore.h"
# include "nsCRT.h"
# include "nsString.h"
# include "nsIServiceManager.h"
# include "nsIImportService.h"
# include "nsOEImport.h"
2000-06-03 13:46:12 +04:00
# include "nsIMemory.h"
1999-09-06 22:24:10 +04:00
# include "nsOEScanBoxes.h"
# include "nsIImportService.h"
# include "nsIImportMail.h"
# include "nsIImportMailboxDescriptor.h"
# include "nsIImportGeneric.h"
# include "nsOEMailbox.h"
# include "nsIImportAddressBooks.h"
# include "nsIImportABDescriptor.h"
1999-12-28 00:24:00 +03:00
# include "nsIImportFieldMap.h"
1999-09-06 22:24:10 +04:00
# include "WabObject.h"
# include "nsOEAddressIterator.h"
# include "nsIOutputStream.h"
# include "nsOE5File.h"
# include "nsIAddrDatabase.h"
1999-09-10 07:29:46 +04:00
# include "nsOESettings.h"
2000-01-18 01:32:13 +03:00
# include "nsTextFormatter.h"
1999-10-18 23:58:07 +04:00
# include "nsOEStringBundle.h"
2000-03-12 00:30:17 +03:00
# include "nsIStringBundle.h"
1999-09-06 22:24:10 +04:00
# include "OEDebugLog.h"
static NS_DEFINE_CID ( kImportServiceCID , NS_IMPORTSERVICE_CID ) ;
static NS_DEFINE_IID ( kISupportsIID , NS_ISUPPORTS_IID ) ;
2001-06-21 00:21:49 +04:00
class ImportOEMailImpl : public nsIImportMail
1999-09-06 22:24:10 +04:00
{
public :
2001-06-21 00:21:49 +04:00
ImportOEMailImpl ( ) ;
virtual ~ ImportOEMailImpl ( ) ;
1999-09-06 22:24:10 +04:00
static nsresult Create ( nsIImportMail * * aImport ) ;
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIImportmail interface
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation ( nsIFileSpec * * location , PRBool * found , PRBool * userVerify ) ;
/* nsISupportsArray FindMailboxes (in nsIFileSpec location); */
NS_IMETHOD FindMailboxes ( nsIFileSpec * location , nsISupportsArray * * _retval ) ;
/* void ImportMailbox (in nsIImportMailboxDescriptor source, in nsIFileSpec destination, out boolean fatalError); */
NS_IMETHOD ImportMailbox ( nsIImportMailboxDescriptor * source , nsIFileSpec * destination ,
1999-10-18 23:58:07 +04:00
PRUnichar * * pErrorLog , PRUnichar * * pSuccessLog , PRBool * fatalError ) ;
1999-09-06 22:24:10 +04:00
/* unsigned long GetImportProgress (); */
NS_IMETHOD GetImportProgress ( PRUint32 * _retval ) ;
private :
1999-10-18 23:58:07 +04:00
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 ) ;
2000-02-03 03:48:49 +03:00
private :
PRUint32 m_bytesDone ;
1999-09-06 22:24:10 +04:00
} ;
2000-02-03 03:48:49 +03:00
2001-06-21 00:21:49 +04:00
class ImportOEAddressImpl : public nsIImportAddressBooks
1999-09-06 22:24:10 +04:00
{
public :
2001-06-21 00:21:49 +04:00
ImportOEAddressImpl ( ) ;
virtual ~ ImportOEAddressImpl ( ) ;
1999-09-06 22:24:10 +04:00
static nsresult Create ( nsIImportAddressBooks * * aImport ) ;
// nsISupports interface
NS_DECL_ISUPPORTS
// nsIImportAddressBooks interface
/* PRBool GetSupportsMultiple (); */
NS_IMETHOD GetSupportsMultiple ( PRBool * _retval ) { * _retval = PR_FALSE ; return ( NS_OK ) ; }
/* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind ( PRUnichar * * description , PRBool * _retval ) ;
1999-12-28 00:24:00 +03:00
/* PRBool GetNeedsFieldMap ( nsIFileSpec *location); */
NS_IMETHOD GetNeedsFieldMap ( nsIFileSpec * pLoc , PRBool * _retval ) { * _retval = PR_FALSE ; return ( NS_OK ) ; }
1999-09-06 22:24:10 +04:00
/* void GetDefaultLocation (out nsIFileSpec location, out boolean found, out boolean userVerify); */
NS_IMETHOD GetDefaultLocation ( nsIFileSpec * * location , PRBool * found , PRBool * userVerify )
{ return ( NS_ERROR_FAILURE ) ; }
/* nsISupportsArray FindAddressBooks (in nsIFileSpec location); */
NS_IMETHOD FindAddressBooks ( nsIFileSpec * location , nsISupportsArray * * _retval ) ;
1999-12-28 00:24:00 +03:00
/* nsISupports InitFieldMap(nsIFileSpec *location, nsIImportFieldMap *fieldMap); */
NS_IMETHOD InitFieldMap ( nsIFileSpec * location , nsIImportFieldMap * fieldMap )
1999-09-06 22:24:10 +04:00
{ return ( NS_ERROR_FAILURE ) ; }
2001-07-19 05:01:21 +04:00
/* void ImportAddressBook (in nsIImportABDescriptor source, in nsIAddrDatabase destination, in nsIImportFieldMap fieldMap, in boolean isAddrLocHome, out wstring errorLog, out wstring successLog, out boolean fatalError); */
1999-09-06 22:24:10 +04:00
NS_IMETHOD ImportAddressBook ( nsIImportABDescriptor * source ,
nsIAddrDatabase * destination ,
1999-12-28 00:24:00 +03:00
nsIImportFieldMap * fieldMap ,
2001-07-19 05:01:21 +04:00
PRBool isAddrLocHome ,
1999-10-18 23:58:07 +04:00
PRUnichar * * errorLog ,
PRUnichar * * successLog ,
1999-09-06 22:24:10 +04:00
PRBool * fatalError ) ;
/* unsigned long GetImportProgress (); */
NS_IMETHOD GetImportProgress ( PRUint32 * _retval ) ;
2000-01-14 04:41:56 +03:00
NS_IMETHOD GetSampleData ( PRInt32 index , PRBool * pFound , PRUnichar * * pStr )
{ return ( NS_ERROR_FAILURE ) ; }
NS_IMETHOD SetSampleLocation ( nsIFileSpec * ) { return ( NS_OK ) ; }
1999-09-06 22:24:10 +04:00
private :
CWAB * m_pWab ;
2000-02-03 03:48:49 +03:00
int m_doneSoFar ;
1999-09-06 22:24:10 +04:00
} ;
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
nsOEImport : : nsOEImport ( )
{
NS_INIT_REFCNT ( ) ;
IMPORT_LOG0 ( " nsOEImport Module Created \n " ) ;
2000-03-12 00:30:17 +03:00
nsOEStringBundle : : GetStringBundle ( ) ;
1999-09-06 22:24:10 +04:00
}
nsOEImport : : ~ nsOEImport ( )
{
IMPORT_LOG0 ( " nsOEImport Module Deleted \n " ) ;
}
2000-12-07 01:24:41 +03:00
NS_IMPL_ISUPPORTS1 ( nsOEImport , nsIImportModule )
1999-09-06 22:24:10 +04:00
NS_IMETHODIMP nsOEImport : : GetName ( PRUnichar * * name )
{
NS_PRECONDITION ( name ! = nsnull , " null ptr " ) ;
if ( ! name )
return NS_ERROR_NULL_POINTER ;
1999-10-18 23:58:07 +04:00
// nsString title = "Outlook Express";
// *name = title.ToNewUnicode();
* name = nsOEStringBundle : : GetStringByID ( OEIMPORT_NAME ) ;
1999-09-06 22:24:10 +04:00
return NS_OK ;
}
NS_IMETHODIMP nsOEImport : : GetDescription ( PRUnichar * * name )
{
NS_PRECONDITION ( name ! = nsnull , " null ptr " ) ;
if ( ! name )
return NS_ERROR_NULL_POINTER ;
1999-10-18 23:58:07 +04:00
// nsString desc = "Outlook Express mail and address books";
// *name = desc.ToNewUnicode();
* name = nsOEStringBundle : : GetStringByID ( OEIMPORT_DESCRIPTION ) ;
1999-09-06 22:24:10 +04:00
return NS_OK ;
}
NS_IMETHODIMP nsOEImport : : GetSupports ( char * * supports )
{
NS_PRECONDITION ( supports ! = nsnull , " null ptr " ) ;
if ( ! supports )
return NS_ERROR_NULL_POINTER ;
* supports = nsCRT : : strdup ( kOESupportsString ) ;
return ( NS_OK ) ;
}
1999-12-03 02:53:30 +03:00
NS_IMETHODIMP nsOEImport : : GetSupportsUpgrade ( PRBool * pUpgrade )
{
NS_PRECONDITION ( pUpgrade ! = nsnull , " null ptr " ) ;
if ( ! pUpgrade )
return NS_ERROR_NULL_POINTER ;
* pUpgrade = PR_TRUE ;
return ( NS_OK ) ;
}
1999-09-06 22:24:10 +04:00
NS_IMETHODIMP nsOEImport : : GetImportInterface ( const char * pImportType , nsISupports * * ppInterface )
{
NS_PRECONDITION ( pImportType ! = nsnull , " null ptr " ) ;
if ( ! pImportType )
return NS_ERROR_NULL_POINTER ;
NS_PRECONDITION ( ppInterface ! = nsnull , " null ptr " ) ;
if ( ! ppInterface )
return NS_ERROR_NULL_POINTER ;
* ppInterface = nsnull ;
nsresult rv ;
if ( ! nsCRT : : strcmp ( pImportType , " mail " ) ) {
// create the nsIImportMail interface and return it!
nsIImportMail * pMail = nsnull ;
nsIImportGeneric * pGeneric = nsnull ;
2001-06-21 00:21:49 +04:00
rv = ImportOEMailImpl : : Create ( & pMail ) ;
1999-09-06 22:24:10 +04:00
if ( NS_SUCCEEDED ( rv ) ) {
NS_WITH_SERVICE ( nsIImportService , impSvc , kImportServiceCID , & rv ) ;
if ( NS_SUCCEEDED ( rv ) ) {
rv = impSvc - > CreateNewGenericMail ( & pGeneric ) ;
if ( NS_SUCCEEDED ( rv ) ) {
pGeneric - > SetData ( " mailInterface " , pMail ) ;
1999-10-18 23:58:07 +04:00
nsString name ;
nsOEStringBundle : : GetStringByID ( OEIMPORT_NAME , name ) ;
2001-06-30 15:02:25 +04:00
pGeneric - > SetData ( " name " , ( nsISupports * ) name . get ( ) ) ;
1999-09-06 22:24:10 +04:00
rv = pGeneric - > QueryInterface ( kISupportsIID , ( void * * ) ppInterface ) ;
}
}
}
NS_IF_RELEASE ( pMail ) ;
NS_IF_RELEASE ( pGeneric ) ;
return ( rv ) ;
}
if ( ! nsCRT : : strcmp ( pImportType , " addressbook " ) ) {
// create the nsIImportMail interface and return it!
nsIImportAddressBooks * pAddress = nsnull ;
nsIImportGeneric * pGeneric = nsnull ;
2001-06-21 00:21:49 +04:00
rv = ImportOEAddressImpl : : Create ( & pAddress ) ;
1999-09-06 22:24:10 +04:00
if ( NS_SUCCEEDED ( rv ) ) {
NS_WITH_SERVICE ( nsIImportService , impSvc , kImportServiceCID , & rv ) ;
if ( NS_SUCCEEDED ( rv ) ) {
rv = impSvc - > CreateNewGenericAddressBooks ( & pGeneric ) ;
if ( NS_SUCCEEDED ( rv ) ) {
pGeneric - > SetData ( " addressInterface " , pAddress ) ;
rv = pGeneric - > QueryInterface ( kISupportsIID , ( void * * ) ppInterface ) ;
}
}
}
NS_IF_RELEASE ( pAddress ) ;
NS_IF_RELEASE ( pGeneric ) ;
return ( rv ) ;
}
1999-09-10 07:29:46 +04:00
if ( ! nsCRT : : strcmp ( pImportType , " settings " ) ) {
nsIImportSettings * pSettings = nsnull ;
rv = nsOESettings : : Create ( & pSettings ) ;
if ( NS_SUCCEEDED ( rv ) ) {
pSettings - > QueryInterface ( kISupportsIID , ( void * * ) ppInterface ) ;
}
NS_IF_RELEASE ( pSettings ) ;
return ( rv ) ;
}
1999-09-06 22:24:10 +04:00
return ( NS_ERROR_NOT_AVAILABLE ) ;
}
/////////////////////////////////////////////////////////////////////////////////
2001-06-21 00:21:49 +04:00
nsresult ImportOEMailImpl : : Create ( nsIImportMail * * aImport )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( aImport ! = nsnull , " null ptr " ) ;
if ( ! aImport )
return NS_ERROR_NULL_POINTER ;
2001-06-21 00:21:49 +04:00
* aImport = new ImportOEMailImpl ( ) ;
1999-09-06 22:24:10 +04:00
if ( ! * aImport )
return NS_ERROR_OUT_OF_MEMORY ;
NS_ADDREF ( * aImport ) ;
return NS_OK ;
}
2001-06-21 00:21:49 +04:00
ImportOEMailImpl : : ImportOEMailImpl ( )
1999-09-06 22:24:10 +04:00
{
NS_INIT_REFCNT ( ) ;
}
2001-06-21 00:21:49 +04:00
ImportOEMailImpl : : ~ ImportOEMailImpl ( )
1999-09-06 22:24:10 +04:00
{
}
2001-06-21 00:21:49 +04:00
NS_IMPL_THREADSAFE_ISUPPORTS1 ( ImportOEMailImpl , nsIImportMail )
1999-09-06 22:24:10 +04:00
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEMailImpl : : GetDefaultLocation ( nsIFileSpec * * ppLoc , PRBool * found , PRBool * userVerify )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( ppLoc ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( found ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( userVerify ! = nsnull , " null ptr " ) ;
if ( ! ppLoc | | ! found | | ! userVerify )
return NS_ERROR_NULL_POINTER ;
// use scanboxes to find the location.
nsresult rv ;
nsIFileSpec * spec ;
if ( NS_FAILED ( rv = NS_NewFileSpec ( & spec ) ) )
return ( rv ) ;
if ( nsOEScanBoxes : : FindMail ( spec ) ) {
* found = PR_TRUE ;
* ppLoc = spec ;
}
else {
* found = PR_FALSE ;
* ppLoc = nsnull ;
spec - > Release ( ) ;
}
* userVerify = PR_TRUE ;
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEMailImpl : : FindMailboxes ( nsIFileSpec * pLoc , nsISupportsArray * * ppArray )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( pLoc ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( ppArray ! = nsnull , " null ptr " ) ;
if ( ! pLoc | | ! ppArray )
return NS_ERROR_NULL_POINTER ;
1999-12-08 01:22:34 +03:00
PRBool exists = PR_FALSE ;
nsresult rv = pLoc - > Exists ( & exists ) ;
if ( NS_FAILED ( rv ) | | ! exists )
return ( NS_ERROR_FAILURE ) ;
1999-09-06 22:24:10 +04:00
nsOEScanBoxes scan ;
if ( ! scan . GetMailboxes ( pLoc , ppArray ) )
* ppArray = nsnull ;
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
void ImportOEMailImpl : : AddLinebreak ( nsString * pStream )
1999-10-18 23:58:07 +04:00
{
if ( pStream )
2001-04-18 09:59:43 +04:00
pStream - > AppendWithConversion ( char ( nsCRT : : LF ) ) ;
1999-10-18 23:58:07 +04:00
}
2001-06-21 00:21:49 +04:00
void ImportOEMailImpl : : ReportSuccess ( nsString & name , PRInt32 count , nsString * pStream )
1999-10-18 23:58:07 +04:00
{
if ( ! pStream )
return ;
// load the success string
2000-03-12 00:30:17 +03:00
nsIStringBundle * pBundle = nsOEStringBundle : : GetStringBundleProxy ( ) ;
PRUnichar * pFmt = nsOEStringBundle : : GetStringByID ( OEIMPORT_MAILBOX_SUCCESS , pBundle ) ;
2001-06-30 15:02:25 +04:00
PRUnichar * pText = nsTextFormatter : : smprintf ( pFmt , name . get ( ) , count ) ;
1999-10-18 23:58:07 +04:00
pStream - > Append ( pText ) ;
2000-01-18 01:32:13 +03:00
nsTextFormatter : : smprintf_free ( pText ) ;
1999-10-18 23:58:07 +04:00
nsOEStringBundle : : FreeString ( pFmt ) ;
AddLinebreak ( pStream ) ;
2000-03-12 00:30:17 +03:00
NS_IF_RELEASE ( pBundle ) ;
1999-10-18 23:58:07 +04:00
}
2001-06-21 00:21:49 +04:00
void ImportOEMailImpl : : ReportError ( PRInt32 errorNum , nsString & name , nsString * pStream )
1999-10-18 23:58:07 +04:00
{
if ( ! pStream )
return ;
// load the error string
2000-03-12 00:30:17 +03:00
nsIStringBundle * pBundle = nsOEStringBundle : : GetStringBundleProxy ( ) ;
PRUnichar * pFmt = nsOEStringBundle : : GetStringByID ( errorNum , pBundle ) ;
2001-06-30 15:02:25 +04:00
PRUnichar * pText = nsTextFormatter : : smprintf ( pFmt , name . get ( ) ) ;
1999-10-18 23:58:07 +04:00
pStream - > Append ( pText ) ;
2000-01-18 01:32:13 +03:00
nsTextFormatter : : smprintf_free ( pText ) ;
1999-10-18 23:58:07 +04:00
nsOEStringBundle : : FreeString ( pFmt ) ;
AddLinebreak ( pStream ) ;
2000-03-12 00:30:17 +03:00
NS_IF_RELEASE ( pBundle ) ;
1999-10-18 23:58:07 +04:00
}
2001-06-21 00:21:49 +04:00
void ImportOEMailImpl : : SetLogs ( nsString & success , nsString & error , PRUnichar * * pError , PRUnichar * * pSuccess )
1999-10-18 23:58:07 +04:00
{
if ( pError )
* pError = error . ToNewUnicode ( ) ;
if ( pSuccess )
* pSuccess = success . ToNewUnicode ( ) ;
}
1999-09-06 22:24:10 +04:00
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEMailImpl : : ImportMailbox ( nsIImportMailboxDescriptor * pSource ,
1999-09-06 22:24:10 +04:00
nsIFileSpec * pDestination ,
1999-10-18 23:58:07 +04:00
PRUnichar * * pErrorLog ,
PRUnichar * * pSuccessLog ,
1999-09-06 22:24:10 +04:00
PRBool * fatalError )
{
NS_PRECONDITION ( pSource ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( pDestination ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( fatalError ! = nsnull , " null ptr " ) ;
1999-10-18 23:58:07 +04:00
2000-03-12 00:30:17 +03:00
nsCOMPtr < nsIStringBundle > bundle ( dont_AddRef ( nsOEStringBundle : : GetStringBundleProxy ( ) ) ) ;
1999-10-18 23:58:07 +04:00
nsString success ;
nsString error ;
if ( ! pSource | | ! pDestination | | ! fatalError ) {
2000-03-12 00:30:17 +03:00
nsOEStringBundle : : GetStringByID ( OEIMPORT_MAILBOX_BADPARAM , error , bundle ) ;
1999-10-18 23:58:07 +04:00
if ( fatalError )
* fatalError = PR_TRUE ;
SetLogs ( success , error , pErrorLog , pSuccessLog ) ;
return NS_ERROR_NULL_POINTER ;
}
1999-09-06 22:24:10 +04:00
PRBool abort = PR_FALSE ;
nsString name ;
PRUnichar * pName ;
if ( NS_SUCCEEDED ( pSource - > GetDisplayName ( & pName ) ) ) {
name = pName ;
nsCRT : : free ( pName ) ;
}
PRUint32 mailSize = 0 ;
pSource - > GetSize ( & mailSize ) ;
if ( mailSize = = 0 ) {
1999-10-18 23:58:07 +04:00
ReportSuccess ( name , 0 , & success ) ;
SetLogs ( success , error , pErrorLog , pSuccessLog ) ;
1999-09-06 22:24:10 +04:00
return ( NS_OK ) ;
}
nsIFileSpec * inFile ;
if ( NS_FAILED ( pSource - > GetFileSpec ( & inFile ) ) ) {
1999-10-18 23:58:07 +04:00
ReportError ( OEIMPORT_MAILBOX_BADSOURCEFILE , name , & error ) ;
SetLogs ( success , error , pErrorLog , pSuccessLog ) ;
1999-09-06 22:24:10 +04:00
return ( NS_ERROR_FAILURE ) ;
}
# ifdef IMPORT_DEBUG
char * pPath ;
inFile - > GetNativePath ( & pPath ) ;
IMPORT_LOG1 ( " Impot mailbox: %s \n " , pPath ) ;
nsCRT : : free ( pPath ) ;
# endif
2000-02-03 03:48:49 +03:00
m_bytesDone = 0 ;
PRUint32 msgCount = 0 ;
1999-09-06 22:24:10 +04:00
nsresult rv ;
if ( nsOE5File : : IsLocalMailFile ( inFile ) ) {
2001-06-30 15:02:25 +04:00
IMPORT_LOG1 ( " Importing OE5 mailbox: %S! \n " , name . get ( ) ) ;
2000-02-03 03:48:49 +03:00
rv = nsOE5File : : ImportMailbox ( & m_bytesDone , & abort , name , inFile , pDestination , & msgCount ) ;
1999-09-06 22:24:10 +04:00
}
else {
2000-02-03 03:48:49 +03:00
if ( CImportMailbox : : ImportMailbox ( & m_bytesDone , & abort , name , inFile , pDestination , & msgCount ) ) {
1999-09-06 22:24:10 +04:00
rv = NS_OK ;
}
else {
rv = NS_ERROR_FAILURE ;
}
}
inFile - > Release ( ) ;
1999-10-18 23:58:07 +04:00
if ( NS_SUCCEEDED ( rv ) ) {
ReportSuccess ( name , msgCount , & success ) ;
}
else {
ReportError ( OEIMPORT_MAILBOX_CONVERTERROR , name , & error ) ;
}
SetLogs ( success , error , pErrorLog , pSuccessLog ) ;
1999-09-06 22:24:10 +04:00
return ( rv ) ;
}
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEMailImpl : : GetImportProgress ( PRUint32 * pDoneSoFar )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( pDoneSoFar ! = nsnull , " null ptr " ) ;
if ( ! pDoneSoFar )
return NS_ERROR_NULL_POINTER ;
2000-02-03 03:48:49 +03:00
* pDoneSoFar = m_bytesDone ;
1999-09-06 22:24:10 +04:00
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
nsresult ImportOEAddressImpl : : Create ( nsIImportAddressBooks * * aImport )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( aImport ! = nsnull , " null ptr " ) ;
if ( ! aImport )
return NS_ERROR_NULL_POINTER ;
2001-06-21 00:21:49 +04:00
* aImport = new ImportOEAddressImpl ( ) ;
1999-09-06 22:24:10 +04:00
if ( ! * aImport )
return NS_ERROR_OUT_OF_MEMORY ;
NS_ADDREF ( * aImport ) ;
return NS_OK ;
}
2001-06-21 00:21:49 +04:00
ImportOEAddressImpl : : ImportOEAddressImpl ( )
1999-09-06 22:24:10 +04:00
{
NS_INIT_REFCNT ( ) ;
m_pWab = nsnull ;
}
2001-06-21 00:21:49 +04:00
ImportOEAddressImpl : : ~ ImportOEAddressImpl ( )
1999-09-06 22:24:10 +04:00
{
if ( m_pWab )
delete m_pWab ;
}
2001-06-21 00:21:49 +04:00
NS_IMPL_THREADSAFE_ISUPPORTS1 ( ImportOEAddressImpl , nsIImportAddressBooks )
1999-09-06 22:24:10 +04:00
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEAddressImpl : : GetAutoFind ( PRUnichar * * description , PRBool * _retval )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( description ! = nsnull , " null ptr " ) ;
NS_PRECONDITION ( _retval ! = nsnull , " null ptr " ) ;
if ( ! description | | ! _retval )
return NS_ERROR_NULL_POINTER ;
* _retval = PR_TRUE ;
2001-06-20 07:37:18 +04:00
nsString str ; str . Append ( nsOEStringBundle : : GetStringByID ( OEIMPORT_AUTOFIND ) ) ;
1999-09-06 22:24:10 +04:00
* description = str . ToNewUnicode ( ) ;
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEAddressImpl : : FindAddressBooks ( nsIFileSpec * location , nsISupportsArray * * _retval )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( _retval ! = nsnull , " null ptr " ) ;
if ( ! _retval )
return NS_ERROR_NULL_POINTER ;
nsresult rv = NS_NewISupportsArray ( _retval ) ;
if ( NS_FAILED ( rv ) ) {
return ( rv ) ;
}
// Make sure we can load up the windows address book...
rv = NS_ERROR_FAILURE ;
if ( m_pWab )
delete m_pWab ;
m_pWab = new CWAB ( nsnull ) ;
nsIImportABDescriptor * pID ;
nsISupports * pInterface ;
2001-06-20 07:37:18 +04:00
nsString str ; str . Append ( nsOEStringBundle : : GetStringByID ( OEIMPORT_DEFAULT_NAME ) ) ;
1999-09-06 22:24:10 +04:00
if ( m_pWab - > Loaded ( ) ) {
// create a new nsIImportABDescriptor and add it to the array
NS_WITH_SERVICE ( nsIImportService , impSvc , kImportServiceCID , & rv ) ;
if ( NS_SUCCEEDED ( rv ) ) {
rv = impSvc - > CreateNewABDescriptor ( & pID ) ;
if ( NS_SUCCEEDED ( rv ) ) {
pID - > SetIdentifier ( 0x4F453334 ) ;
pID - > SetRef ( 1 ) ;
pID - > SetSize ( 100 ) ;
2001-06-30 15:02:25 +04:00
pID - > SetPreferredName ( str . get ( ) ) ;
1999-09-06 22:24:10 +04:00
rv = pID - > QueryInterface ( kISupportsIID , ( void * * ) & pInterface ) ;
( * _retval ) - > AppendElement ( pInterface ) ;
pInterface - > Release ( ) ;
pID - > Release ( ) ;
}
}
}
if ( NS_FAILED ( rv ) ) {
delete m_pWab ;
m_pWab = nsnull ;
}
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEAddressImpl : : ImportAddressBook ( nsIImportABDescriptor * source ,
1999-09-06 22:24:10 +04:00
nsIAddrDatabase * destination ,
1999-12-28 00:24:00 +03:00
nsIImportFieldMap * fieldMap ,
2001-07-19 05:01:21 +04:00
PRBool isAddrLocHome ,
1999-10-18 23:58:07 +04:00
PRUnichar * * errorLog ,
PRUnichar * * successLog ,
1999-09-06 22:24:10 +04:00
PRBool * fatalError )
{
NS_PRECONDITION ( source ! = nsnull , " null ptr " ) ;
// NS_PRECONDITION(destination != nsnull, "null ptr");
// NS_PRECONDITION(fieldMap != nsnull, "null ptr");
NS_PRECONDITION ( fatalError ! = nsnull , " null ptr " ) ;
if ( ! source | | ! fatalError )
return NS_ERROR_NULL_POINTER ;
// we assume it is our one and only address book.
if ( ! m_pWab ) {
IMPORT_LOG0 ( " Wab not loaded in ImportAddressBook call \n " ) ;
return ( NS_ERROR_FAILURE ) ;
}
IMPORT_LOG0 ( " IMPORTING OUTLOOK EXPRESS ADDRESS BOOK \n " ) ;
2000-02-03 03:48:49 +03:00
m_doneSoFar = 0 ;
1999-09-06 22:24:10 +04:00
nsOEAddressIterator * pIter = new nsOEAddressIterator ( m_pWab , destination ) ;
2000-02-03 03:48:49 +03:00
m_pWab - > IterateWABContents ( pIter , & m_doneSoFar ) ;
1999-09-06 22:24:10 +04:00
delete pIter ;
return ( NS_OK ) ;
}
2001-06-21 00:21:49 +04:00
NS_IMETHODIMP ImportOEAddressImpl : : GetImportProgress ( PRUint32 * _retval )
1999-09-06 22:24:10 +04:00
{
NS_PRECONDITION ( _retval ! = nsnull , " null ptr " ) ;
if ( ! _retval )
return NS_ERROR_NULL_POINTER ;
2000-02-03 03:48:49 +03:00
* _retval = ( PRUint32 ) m_doneSoFar ;
1999-09-06 22:24:10 +04:00
return ( NS_OK ) ;
}