Fix for bug 31242 and a bunch of thread safety issues

This commit is contained in:
tonyr%fbdesigns.com 2000-03-11 21:30:17 +00:00
Родитель 7394bea2b7
Коммит f95f358af0
33 изменённых файлов: 1129 добавлений и 230 удалений

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsIIOService.h"
#include "nsIURI.h"
#include "nsProxyObjectManager.h"
#include "nsProxiedService.h"
#include "nsMsgBaseCID.h"
#include "nsMsgCompCID.h"
@ -191,7 +192,7 @@ nsresult nsEudoraCompose::CreateIdentity( void)
return( NS_OK);
nsresult rv;
NS_WITH_SERVICE(nsIMsgAccountManager, accMgr, kMsgAccountMgrCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIMsgAccountManager, accMgr, kMsgAccountMgrCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_FAILED(rv)) return( rv);
rv = accMgr->CreateIdentity( &m_pIdentity);
nsString name = "Import Identity";
@ -211,7 +212,7 @@ nsresult nsEudoraCompose::CreateComponents( void)
if (!m_pIOService) {
IMPORT_LOG0( "Creating nsIOService\n");
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIIOService, service, kIOServiceCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_FAILED(rv))
return( rv);
m_pIOService = service;

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsCRT.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsEudoraStringBundle.h"
#include "EudoraDebugLog.h"
static NS_DEFINE_CID(kEudoraImportCID, NS_EUDORAIMPORT_CID);
@ -71,5 +72,12 @@ static nsModuleComponentInfo components[] = {
}
};
NS_IMPL_NSGETMODULE("nsEudoraImportModule", components)
PR_STATIC_CALLBACK(void)
eudoraModuleDtor(nsIModule* self)
{
nsEudoraStringBundle::Cleanup();
}
NS_IMPL_NSGETMODULE_WITH_DTOR("nsEudoraImportModule", components, eudoraModuleDtor)

Просмотреть файл

@ -45,6 +45,7 @@
#include "nsIAddrDatabase.h"
#include "nsTextFormatter.h"
#include "nsEudoraStringBundle.h"
#include "nsIStringBundle.h"
#include "nsEudoraSettings.h"
@ -181,6 +182,7 @@ nsEudoraImport::nsEudoraImport()
IMPORT_LOG0( "nsEudoraImport Module Created\n");
nsEudoraStringBundle::GetStringBundle();
}
@ -337,7 +339,7 @@ ImportMailImpl::~ImportMailImpl()
NS_IMPL_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMETHODIMP ImportMailImpl::GetDefaultLocation( nsIFileSpec **ppLoc, PRBool *found, PRBool *userVerify)
{
@ -401,12 +403,14 @@ void ImportMailImpl::ReportSuccess( nsString& name, PRInt32 count, nsString *pSt
if (!pStream)
return;
// load the success string
PRUnichar *pFmt = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_MAILBOX_SUCCESS);
nsIStringBundle *pBundle = nsEudoraStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_MAILBOX_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode(), count);
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsEudoraStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream)
@ -414,12 +418,14 @@ void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pS
if (!pStream)
return;
// load the error string
nsIStringBundle *pBundle = nsEudoraStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsEudoraStringBundle::GetStringByID( errorNum);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsEudoraStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
@ -441,11 +447,14 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsEudoraStringBundle::GetStringBundleProxy()));
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
IMPORT_LOG0( "*** Bad param passed to eudora mailbox import\n");
nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_MAILBOX_BADPARAM, error);
nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_MAILBOX_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
SetLogs( success, error, pErrorLog, pSuccessLog);
@ -548,7 +557,7 @@ ImportAddressImpl::~ImportAddressImpl()
NS_IMPL_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **description, PRBool *_retval)
@ -623,12 +632,14 @@ void ImportAddressImpl::ReportSuccess( nsString& name, nsString *pStream)
if (!pStream)
return;
// load the success string
PRUnichar *pFmt = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_ADDRESS_SUCCESS);
nsIStringBundle *pBundle = nsEudoraStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_ADDRESS_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsEudoraStringBundle::FreeString( pFmt);
ImportMailImpl::AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
@ -642,12 +653,14 @@ NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSour
NS_PRECONDITION(pSource != nsnull, "null ptr");
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsEudoraStringBundle::GetStringBundleProxy()));
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
IMPORT_LOG0( "*** Bad param passed to eudora address import\n");
nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_ADDRESS_BADPARAM, error);
nsEudoraStringBundle::GetStringByID( EUDORAIMPORT_ADDRESS_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
ImportMailImpl::SetLogs( success, error, pErrorLog, pSuccessLog);

Просмотреть файл

@ -22,15 +22,22 @@
#include "nsIStringBundle.h"
#include "nsEudoraStringBundle.h"
#include "nsIServiceManager.h"
#include "nsProxyObjectManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
#define EUDORA_MSGS_URL "chrome://messenger/locale/eudoraImportMsgs.properties"
nsIStringBundle * nsEudoraStringBundle::m_pBundle = nsnull;
nsIStringBundle *nsEudoraStringBundle::GetStringBundle( void)
{
if (m_pBundle)
return( m_pBundle);
nsresult rv;
char* propertyURL = EUDORA_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
@ -41,10 +48,28 @@ nsIStringBundle *nsEudoraStringBundle::GetStringBundle( void)
nsILocale * locale = nsnull;
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
m_pBundle = sBundle;
return( sBundle);
}
nsIStringBundle *nsEudoraStringBundle::GetStringBundleProxy( void)
{
if (!m_pBundle)
return( nsnull);
nsIStringBundle *strProxy = nsnull;
nsresult rv;
// create a proxy object if we aren't on the same thread?
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
}
return( strProxy);
}
void nsEudoraStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
@ -55,20 +80,14 @@ void nsEudoraStringBundle::GetStringByID( PRInt32 stringID, nsString& result, ns
PRUnichar *nsEudoraStringBundle::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);
}
@ -80,3 +99,9 @@ PRUnichar *nsEudoraStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle
return( resultString.ToNewUnicode());
}
void nsEudoraStringBundle::Cleanup( void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nsnull;
}

Просмотреть файл

@ -27,9 +27,13 @@ class nsEudoraStringBundle {
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 nsIStringBundle * GetStringBundle( void); // don't release
static nsIStringBundle * GetStringBundleProxy( void); // release
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
static void Cleanup( void);
private:
static nsIStringBundle * m_pBundle;
};

Просмотреть файл

@ -436,19 +436,41 @@ LPSPropValue CWAB::GetUserProperty( LPMAILUSER pUser, ULONG tag)
if (!pUser)
return( NULL);
ULONG uTag = tag;
/*
Getting Unicode does not help with getting the right
international charset. Windoze bloze.
*/
/*
if (PROP_TYPE( uTag) == PT_STRING8) {
uTag = CHANGE_PROP_TYPE( tag, PT_UNICODE);
}
*/
int sz = CbNewSPropTagArray( 1);
SPropTagArray *pTag = (SPropTagArray *) new char[sz];
pTag->cValues = 1;
pTag->aulPropTag[0] = tag;
pTag->aulPropTag[0] = uTag;
LPSPropValue lpProp = NULL;
ULONG cValues = 0;
HRESULT hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
delete pTag;
if (HR_FAILED( hr) || (cValues != 1)) {
if (lpProp)
m_lpWABObject->FreeBuffer( lpProp);
return( NULL);
lpProp = NULL;
if (uTag != tag) {
pTag->cValues = 1;
pTag->aulPropTag[0] = tag;
cValues = 0;
hr = pUser->GetProps( pTag, 0, &cValues, &lpProp);
if (HR_FAILED( hr) || (cValues != 1)) {
if (lpProp)
m_lpWABObject->FreeBuffer( lpProp);
lpProp = NULL;
}
}
}
delete pTag;
return( lpProp);
}
@ -461,26 +483,36 @@ void CWAB::GetValueString( LPSPropValue pVal, nsString& val)
return;
switch( PROP_TYPE( pVal->ulPropTag)) {
case PT_TSTRING:
val = (LPCTSTR) (pVal->Value.LPSZ);
case PT_STRING8:
// Do we need to call OS routines like MultiByteToWideChar?
val = (char *) (pVal->Value.lpszA);
break;
case PT_MV_TSTRING: {
case PT_UNICODE:
val = (PRUnichar *) (pVal->Value.lpszW);
break;
case PT_MV_STRING8: {
ULONG j;
for(j = 0; j < pVal->Value.MVSZ.cValues; j++) {
val += (LPCTSTR) (pVal->Value.MVSZ.LPPSZ[j]);
for(j = 0; j < pVal->Value.MVszA.cValues; j++) {
val += (char *) (pVal->Value.MVszA.lppszA[j]);
val += TR_OUTPUT_EOL;
}
}
break;
case PT_MV_UNICODE: {
ULONG j;
for(j = 0; j < pVal->Value.MVszW.cValues; j++) {
val += (PRUnichar *) (pVal->Value.MVszW.lppszW[j]);
val += TR_OUTPUT_EOL;
}
}
break;
case PT_I2:
case PT_LONG:
case PT_R4:
case PT_DOUBLE:
case PT_BOOLEAN: {
/*
case PT_BOOLEAN: {
/*
TCHAR sz[256];
wsprintf(sz,"%d", pVal->Value.l);
val = sz;

Просмотреть файл

@ -33,6 +33,7 @@
#include "nsCRT.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsOEStringBundle.h"
#include "OEDebugLog.h"
static NS_DEFINE_CID(kOEImportCID, NS_OEIMPORT_CID);
@ -74,7 +75,13 @@ static nsModuleComponentInfo components[] = {
}
};
NS_IMPL_NSGETMODULE("nsOEImport", components)
PR_STATIC_CALLBACK(void)
oeModuleDtor(nsIModule* self)
{
nsOEStringBundle::Cleanup();
}
NS_IMPL_NSGETMODULE_WITH_DTOR("nsOEImport", components, oeModuleDtor)

Просмотреть файл

@ -51,6 +51,7 @@
#include "nsOESettings.h"
#include "nsTextFormatter.h"
#include "nsOEStringBundle.h"
#include "nsIStringBundle.h"
#include "OEDebugLog.h"
@ -162,6 +163,7 @@ nsOEImport::nsOEImport()
IMPORT_LOG0( "nsOEImport Module Created\n");
nsOEStringBundle::GetStringBundle();
}
@ -318,7 +320,7 @@ ImportMailImpl::~ImportMailImpl()
NS_IMPL_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMETHODIMP ImportMailImpl::GetDefaultLocation( nsIFileSpec **ppLoc, PRBool *found, PRBool *userVerify)
{
@ -379,12 +381,14 @@ void ImportMailImpl::ReportSuccess( nsString& name, PRInt32 count, nsString *pSt
if (!pStream)
return;
// load the success string
PRUnichar *pFmt = nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_SUCCESS);
nsIStringBundle *pBundle = nsOEStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode(), count);
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsOEStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream)
@ -392,12 +396,14 @@ void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pS
if (!pStream)
return;
// load the error string
PRUnichar *pFmt = nsOEStringBundle::GetStringByID( errorNum);
nsIStringBundle *pBundle = nsOEStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsOEStringBundle::GetStringByID( errorNum, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsOEStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
@ -419,10 +425,12 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsOEStringBundle::GetStringBundleProxy()));
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_BADPARAM, error);
nsOEStringBundle::GetStringByID( OEIMPORT_MAILBOX_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
SetLogs( success, error, pErrorLog, pSuccessLog);
@ -496,8 +504,6 @@ NS_IMETHODIMP ImportMailImpl::GetImportProgress( PRUint32 *pDoneSoFar)
if (! pDoneSoFar)
return NS_ERROR_NULL_POINTER;
// TLR: FIXME: Figure our how to update this from the import
// of the current mailbox.
*pDoneSoFar = m_bytesDone;
return( NS_OK);
}
@ -533,7 +539,7 @@ ImportAddressImpl::~ImportAddressImpl()
NS_IMPL_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **description, PRBool *_retval)

Просмотреть файл

@ -25,15 +25,22 @@
#include "nsIStringBundle.h"
#include "nsOEStringBundle.h"
#include "nsIServiceManager.h"
#include "nsProxyObjectManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
#define OE_MSGS_URL "chrome://messenger/locale/oeImportMsgs.properties"
nsIStringBundle * nsOEStringBundle::m_pBundle = nsnull;
nsIStringBundle *nsOEStringBundle::GetStringBundle( void)
{
if (m_pBundle)
return( m_pBundle);
nsresult rv;
char* propertyURL = OE_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
@ -45,9 +52,28 @@ nsIStringBundle *nsOEStringBundle::GetStringBundle( void)
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
m_pBundle = sBundle;
return( sBundle);
}
nsIStringBundle *nsOEStringBundle::GetStringBundleProxy( void)
{
if (!m_pBundle)
return( nsnull);
nsIStringBundle *strProxy = nsnull;
nsresult rv;
// create a proxy object if we aren't on the same thread?
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
}
return( strProxy);
}
void nsOEStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
@ -58,20 +84,14 @@ void nsOEStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStr
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);
}
@ -83,3 +103,9 @@ PRUnichar *nsOEStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle *pB
return( resultString.ToNewUnicode());
}
void nsOEStringBundle::Cleanup( void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nsnull;
}

Просмотреть файл

@ -31,9 +31,13 @@ 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 nsIStringBundle * GetStringBundle( void); // dont release
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
static void Cleanup( void);
static nsIStringBundle * GetStringBundleProxy( void); // release
private:
static nsIStringBundle * m_pBundle;
};

Просмотреть файл

@ -48,6 +48,30 @@
## @loc None
2004=Error importing mailbox %S, all messages may not be imported from this mailbox.
# Address book name
## @name OUTLOOKIMPORT_ADDRNAME
## @loc None
2005=Outlook address books
# Description
## @name OUTLOOKIMPORT_ADDRESS_SUCCESS
## @loc None
2006=Imported address book %S
# Error message
## @name OUTLOOKIMPORT_ADDRESS_BADPARAM
## @loc None
2007=Bad parameter passed to import address book.
# Error message
## @name OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE
## @loc None
2008=Error accessing file for address book %S.
# Error message
## @name OUTLOOKIMPORT_ADDRESS_CONVERTERROR
## @loc None
2009=Error importing address book %S, all addresses may not have been imported.

Просмотреть файл

@ -27,6 +27,13 @@
#include "prprf.h"
int CMapiApi::m_clients = 0;
BOOL CMapiApi::m_initialized = PR_FALSE;
nsVoidArray *CMapiApi::m_pStores = NULL;
LPMAPISESSION CMapiApi::m_lpSession = NULL;
LPMDB CMapiApi::m_lpMdb = NULL;
HRESULT CMapiApi::m_lastError;
/*
Type: 1, name: Calendar, class: IPF.Appointment
Type: 1, name: Contacts, class: IPF.Contact
@ -146,28 +153,40 @@ void CMapiApi::UnloadMapi( void)
CMapiApi::CMapiApi()
{
m_initialized = FALSE;
m_lpSession = NULL;
m_lpMdb = NULL;
m_clients++;
LoadMapi();
if (!m_pStores)
m_pStores = new nsVoidArray();
}
CMapiApi::~CMapiApi()
{
HRESULT hr;
m_clients--;
if (!m_clients) {
HRESULT hr;
ClearMessageStores();
m_lpMdb = NULL;
ClearMessageStores();
delete m_pStores;
m_pStores = NULL;
if (m_lpSession) {
hr = m_lpSession->Logoff( NULL, 0, 0);
if (FAILED(hr)) {
MAPI_TRACE2( "Logoff failed: 0x%lx, %d\n", (long)hr, (int)hr);
m_lpMdb = NULL;
if (m_lpSession) {
hr = m_lpSession->Logoff( NULL, 0, 0);
if (FAILED(hr)) {
MAPI_TRACE2( "Logoff failed: 0x%lx, %d\n", (long)hr, (int)hr);
}
m_lpSession->Release();
m_lpSession = NULL;
}
m_lpSession->Release();
}
if (m_initialized)
MAPIUninitialize();
if (m_initialized) {
MAPIUninitialize();
m_initialized = FALSE;
}
UnloadMapi();
}
}
BOOL CMapiApi::Initialize( void)
@ -225,40 +244,50 @@ BOOL CMapiApi::LogOn( void)
class CGetStoreFoldersIter : public CMapiHierarchyIter {
public:
CGetStoreFoldersIter( CMapiApi *pApi, CMapiFolderList& folders, int depth);
CGetStoreFoldersIter( CMapiApi *pApi, CMapiFolderList& folders, int depth, BOOL isMail = TRUE);
virtual BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry);
protected:
BOOL ExcludeFolderClass( const char *pName);
BOOL m_isMail;
CMapiApi * m_pApi;
CMapiFolderList * m_pList;
int m_depth;
};
CGetStoreFoldersIter::CGetStoreFoldersIter( CMapiApi *pApi, CMapiFolderList& folders, int depth)
CGetStoreFoldersIter::CGetStoreFoldersIter( CMapiApi *pApi, CMapiFolderList& folders, int depth, BOOL isMail)
{
m_pApi = pApi;
m_pList = &folders;
m_depth = depth;
m_isMail = isMail;
}
BOOL CGetStoreFoldersIter::ExcludeFolderClass( const char *pName)
{
BOOL bResult = FALSE;
if (!nsCRT::strcasecmp( pName, "IPF.Appointment"))
BOOL bResult;
if (m_isMail) {
bResult = FALSE;
if (!nsCRT::strcasecmp( pName, "IPF.Appointment"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Contact"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Journal"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.StickyNote"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Task"))
bResult = TRUE;
// else if (!stricmp( pName, "IPF.Note"))
// bResult = TRUE;
}
else {
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Contact"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Journal"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.StickyNote"))
bResult = TRUE;
else if (!nsCRT::strcasecmp( pName, "IPF.Task"))
bResult = TRUE;
// else if (!stricmp( pName, "IPF.Note"))
// bResult = TRUE;
if (!nsCRT::strcasecmp( pName, "IPF.Contact"))
bResult = FALSE;
}
return( bResult);
}
@ -277,7 +306,7 @@ BOOL CGetStoreFoldersIter::HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID
else
name.Truncate();
if (name.IsEmpty() || (!ExcludeFolderClass( name))) {
if ((name.IsEmpty() && m_isMail) || (!ExcludeFolderClass( name))) {
pVal = m_pApi->GetMapiProperty( pFolder, PR_DISPLAY_NAME);
m_pApi->GetStringFromProp( pVal, name);
CMapiFolder *pNewFolder = new CMapiFolder( name, cb, pEntry, m_depth);
@ -287,7 +316,7 @@ BOOL CGetStoreFoldersIter::HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID
MAPI_TRACE2( "Type: %d, name: %s\n", m_pApi->GetLongFromProp( pVal), (const char *)name);
// m_pApi->ListProperties( pFolder);
CGetStoreFoldersIter nextIter( m_pApi, *m_pList, m_depth + 1);
CGetStoreFoldersIter nextIter( m_pApi, *m_pList, m_depth + 1, m_isMail);
m_pApi->IterateHierarchy( &nextIter, pFolder);
}
pFolder->Release();
@ -356,6 +385,58 @@ BOOL CMapiApi::GetStoreFolders( ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& f
return( bResult);
}
BOOL CMapiApi::GetStoreAddressFolders( ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& folders)
{
// Fill in the array with the folders in the given store
if (!m_initialized || !m_lpSession) {
MAPI_TRACE0( "MAPI not initialized for GetStoreAddressFolders\n");
return( FALSE);
}
m_lpMdb = NULL;
CMsgStore * pStore = FindMessageStore( cbEid, lpEid);
BOOL bResult = FALSE;
LPSPropValue pVal;
if (pStore && pStore->Open( m_lpSession, &m_lpMdb)) {
// Successful open, do the iteration of the store
pVal = GetMapiProperty( m_lpMdb, PR_IPM_SUBTREE_ENTRYID);
if (pVal) {
ULONG cbEntry;
LPENTRYID pEntry;
LPMAPIFOLDER lpSubTree = NULL;
if (GetEntryIdFromProp( pVal, cbEntry, pEntry)) {
// Open up the folder!
bResult = OpenEntry( cbEntry, pEntry, (LPUNKNOWN *)&lpSubTree);
MAPIFreeBuffer( pEntry);
if (bResult && lpSubTree) {
// Iterate the subtree with the results going into the folder list
CGetStoreFoldersIter iterHandler( this, folders, 1, FALSE);
bResult = IterateHierarchy( &iterHandler, lpSubTree);
lpSubTree->Release();
}
else {
MAPI_TRACE0( "GetStoreAddressFolders: Error opening sub tree.\n");
}
}
else {
MAPI_TRACE0( "GetStoreAddressFolders: Error getting entryID from sub tree property val.\n");
}
}
else {
MAPI_TRACE0( "GetStoreAddressFolders: Error getting sub tree property.\n");
}
}
else {
MAPI_TRACE0( "GetStoreAddressFolders: Error opening message store.\n");
}
return( bResult);
}
BOOL CMapiApi::OpenStore( ULONG cbEid, LPENTRYID lpEid, LPMDB *ppMdb)
{
if (!m_lpSession) {
@ -868,17 +949,20 @@ void CMapiApi::GetStoreInfo( CMapiFolder *pFolder, long *pSzContents)
void CMapiApi::ClearMessageStores( void)
{
CMsgStore * pStore;
for (int i = 0; i < m_stores.Count(); i++) {
pStore = (CMsgStore *) m_stores.ElementAt( i);
delete pStore;
if (m_pStores) {
CMsgStore * pStore;
for (int i = 0; i < m_pStores->Count(); i++) {
pStore = (CMsgStore *) m_pStores->ElementAt( i);
delete pStore;
}
m_pStores->Clear();
}
m_stores.Clear();
}
void CMapiApi::AddMessageStore( CMsgStore *pStore)
{
m_stores.AppendElement( pStore);
if (m_pStores)
m_pStores->AppendElement( pStore);
}
CMsgStore * CMapiApi::FindMessageStore( ULONG cbEid, LPENTRYID lpEid)
@ -892,8 +976,8 @@ CMsgStore * CMapiApi::FindMessageStore( ULONG cbEid, LPENTRYID lpEid)
ULONG result;
HRESULT hr;
CMsgStore * pStore;
for (int i = 0; i < m_stores.Count(); i++) {
pStore = (CMsgStore *) m_stores.ElementAt( i);
for (int i = 0; i < m_pStores->Count(); i++) {
pStore = (CMsgStore *) m_pStores->ElementAt( i);
hr = m_lpSession->CompareEntryIDs( cbEid, lpEid, pStore->GetCBEntryID(), pStore->GetLPEntryID(),
0, &result);
if (HR_FAILED( hr)) {
@ -1020,8 +1104,11 @@ BOOL CMapiApi::GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYI
BOOL CMapiApi::GetStringFromProp( LPSPropValue pVal, nsCString& val, BOOL delVal)
{
BOOL bResult = TRUE;
if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_TSTRING)) {
val = (LPCTSTR) (pVal->Value.LPSZ);
if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_STRING8)) {
val = pVal->Value.lpszA;
}
else if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_UNICODE)) {
val = (PRUnichar *) pVal->Value.lpszW;
}
else if (pVal && (PROP_TYPE( pVal->ulPropTag) == PT_NULL)) {
val.Truncate();
@ -1046,6 +1133,40 @@ BOOL CMapiApi::GetStringFromProp( LPSPropValue pVal, nsCString& val, BOOL delVal
return( bResult);
}
BOOL CMapiApi::GetStringFromProp( LPSPropValue pVal, nsString& val, BOOL delVal)
{
BOOL bResult = TRUE;
if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_STRING8)) {
val = pVal->Value.lpszA;
// Convert this str to a wide char!
}
else if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_UNICODE)) {
val = (PRUnichar *) pVal->Value.lpszW;
}
else if (pVal && (PROP_TYPE( pVal->ulPropTag) == PT_NULL)) {
val.Truncate();
}
else if (pVal && (PROP_TYPE( pVal->ulPropTag) == PT_ERROR)) {
val.Truncate();
bResult = FALSE;
}
else {
if (pVal) {
MAPI_TRACE1( "GetStringFromProp: invalid value, expecting string - %d\n", (int) PROP_TYPE( pVal->ulPropTag));
}
else {
MAPI_TRACE0( "GetStringFromProp: invalid value, expecting string, got null pointer\n");
}
val.Truncate();
bResult = FALSE;
}
if (pVal && delVal)
MAPIFreeBuffer( pVal);
return( bResult);
}
LONG CMapiApi::GetLongFromProp( LPSPropValue pVal, BOOL delVal)
{
LONG val = 0;

Просмотреть файл

@ -162,6 +162,7 @@ public:
// Fill in the folders list with the heirarchy from the given
// message store.
BOOL GetStoreFolders( ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& folders, int startDepth);
BOOL GetStoreAddressFolders( ULONG cbEid, LPENTRYID lpEid, CMapiFolderList& folders);
BOOL OpenStore( ULONG cbEid, LPENTRYID lpEid, LPMDB *ppMdb);
// Iteration
@ -173,6 +174,7 @@ public:
static LPSPropValue GetMapiProperty( LPMAPIPROP pProp, ULONG tag);
static BOOL GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal = TRUE);
static BOOL GetStringFromProp( LPSPropValue pVal, nsCString& val, BOOL delVal = TRUE);
static BOOL GetStringFromProp( LPSPropValue pVal, nsString& val, BOOL delVal = TRUE);
static LONG GetLongFromProp( LPSPropValue pVal, BOOL delVal = TRUE);
static BOOL GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsCString& val);
static BOOL IsLargeProperty( LPSPropValue pVal);
@ -200,11 +202,12 @@ protected:
private:
nsVoidArray m_stores;
BOOL m_initialized;
LPMAPISESSION m_lpSession;
LPMDB m_lpMdb;
HRESULT m_lastError;
static int m_clients;
static BOOL m_initialized;
static nsVoidArray * m_pStores;
static LPMAPISESSION m_lpSession;
static LPMDB m_lpMdb;
static HRESULT m_lastError;
};

Просмотреть файл

@ -27,6 +27,7 @@
#include "nsIIOService.h"
#include "nsIURI.h"
#include "nsProxyObjectManager.h"
#include "nsProxiedService.h"
#include "nsMsgBaseCID.h"
#include "nsMsgCompCID.h"
@ -191,7 +192,7 @@ nsresult nsOutlookCompose::CreateIdentity( void)
return( NS_OK);
nsresult rv;
NS_WITH_SERVICE(nsIMsgAccountManager, accMgr, kMsgAccountMgrCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIMsgAccountManager, accMgr, kMsgAccountMgrCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_FAILED(rv)) return( rv);
rv = accMgr->CreateIdentity( &m_pIdentity);
nsString name = "Import Identity";
@ -211,7 +212,7 @@ nsresult nsOutlookCompose::CreateComponents( void)
if (!m_pIOService) {
IMPORT_LOG0( "Creating nsIOService\n");
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIIOService, service, kIOServiceCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_FAILED(rv))
return( rv);
m_pIOService = service;

Просмотреть файл

@ -33,7 +33,7 @@
#include "nsCRT.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsOutlookStringBundle.h"
#include "OutlookDebugLog.h"
static NS_DEFINE_CID(kOutlookImportCID, NS_OUTLOOKIMPORT_CID);
@ -76,5 +76,12 @@ static nsModuleComponentInfo components[] = {
}
};
NS_IMPL_NSGETMODULE("nsOutlookImport", components)
PR_STATIC_CALLBACK(void)
outlookModuleDtor(nsIModule* self)
{
nsOutlookStringBundle::Cleanup();
}
NS_IMPL_NSGETMODULE_WITH_DTOR("nsOutlookImport", components, outlookModuleDtor)

Просмотреть файл

@ -47,7 +47,7 @@
#include "nsOutlookSettings.h"
#include "nsTextFormatter.h"
#include "nsOutlookStringBundle.h"
#include "nsIStringBundle.h"
#include "OutlookDebugLog.h"
#include "nsOutlookMail.h"
@ -85,7 +85,7 @@ public:
/* unsigned long GetImportProgress (); */
NS_IMETHOD GetImportProgress(PRUint32 *_retval);
private:
public:
static void ReportSuccess( nsString& name, PRInt32 count, nsString *pStream);
static void ReportError( PRInt32 errorNum, nsString& name, nsString *pStream);
static void AddLinebreak( nsString *pStream);
@ -111,7 +111,7 @@ public:
// nsIImportAddressBooks interface
/* PRBool GetSupportsMultiple (); */
NS_IMETHOD GetSupportsMultiple(PRBool *_retval) { *_retval = PR_FALSE; return( NS_OK);}
NS_IMETHOD GetSupportsMultiple(PRBool *_retval) { *_retval = PR_TRUE; return( NS_OK);}
/* PRBool GetAutoFind (out wstring description); */
NS_IMETHOD GetAutoFind(PRUnichar **description, PRBool *_retval);
@ -147,11 +147,12 @@ public:
NS_IMETHOD SetSampleLocation( nsIFileSpec *) { return( NS_OK); }
private:
void GetOEInterface( void);
void ReportSuccess( nsString& name, nsString *pStream);
private:
nsIImportAddressBooks * m_pWabImport;
PRUint32 m_msgCount;
PRUint32 m_msgTotal;
nsOutlookMail m_address;
};
////////////////////////////////////////////////////////////////////////
@ -165,6 +166,7 @@ nsOutlookImport::nsOutlookImport()
IMPORT_LOG0( "nsOutlookImport Module Created\n");
nsOutlookStringBundle::GetStringBundle();
}
@ -320,7 +322,7 @@ ImportMailImpl::~ImportMailImpl()
NS_IMPL_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportMailImpl, NS_GET_IID(nsIImportMail));
NS_IMETHODIMP ImportMailImpl::GetDefaultLocation( nsIFileSpec **ppLoc, PRBool *found, PRBool *userVerify)
{
@ -384,12 +386,14 @@ void ImportMailImpl::ReportSuccess( nsString& name, PRInt32 count, nsString *pSt
if (!pStream)
return;
// load the success string
PRUnichar *pFmt = nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_MAILBOX_SUCCESS);
nsIStringBundle *pBundle = nsOutlookStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_MAILBOX_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode(), count);
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsOutlookStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream)
@ -397,12 +401,14 @@ void ImportMailImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pS
if (!pStream)
return;
// load the error string
nsIStringBundle *pBundle = nsOutlookStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsOutlookStringBundle::GetStringByID( errorNum);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsOutlookStringBundle::FreeString( pFmt);
AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}
@ -423,11 +429,13 @@ NS_IMETHODIMP ImportMailImpl::ImportMailbox( nsIImportMailboxDescriptor *pSource
NS_PRECONDITION(pSource != nsnull, "null ptr");
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsOutlookStringBundle::GetStringBundleProxy()));
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_MAILBOX_BADPARAM, error);
nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_MAILBOX_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
SetLogs( success, error, pErrorLog, pSuccessLog);
@ -501,19 +509,18 @@ nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport)
ImportAddressImpl::ImportAddressImpl()
{
NS_INIT_REFCNT();
m_pWabImport = nsnull;
m_msgCount = 0;
m_msgTotal = 0;
}
ImportAddressImpl::~ImportAddressImpl()
{
if (m_pWabImport)
m_pWabImport->Release();
}
NS_IMPL_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **description, PRBool *_retval)
@ -524,29 +531,13 @@ NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **description, PRBool *_r
return NS_ERROR_NULL_POINTER;
*_retval = PR_TRUE;
nsString str = "Outlook address book (windows address book)";
*description = str.ToNewUnicode();
nsString str;
nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_ADDRNAME, str);
*description = str.ToNewUnicode();
return( NS_OK);
}
void ImportAddressImpl::GetOEInterface( void)
{
if (m_pWabImport)
return;
nsIImportModule * oeModule = nsnull;
nsresult rv = nsComponentManager::CreateInstance( "component://mozilla/import/import-oe", nsnull, NS_GET_IID(nsIImportModule), (void **) &oeModule);
if (NS_SUCCEEDED( rv) && oeModule) {
nsIImportGeneric * generic = nsnull;
rv = oeModule->GetImportInterface( "addressbook", (nsISupports **) &generic);
if (NS_SUCCEEDED( rv) && generic) {
rv = generic->GetData( "addressInterface", (nsISupports **) &m_pWabImport);
generic->Release();
}
oeModule->Release();
}
}
NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupportsArray **_retval)
@ -555,13 +546,7 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupp
if (!_retval)
return NS_ERROR_NULL_POINTER;
GetOEInterface();
if (!m_pWabImport) {
IMPORT_LOG0( "Outlook address book import failed, cannot load outlook express import module\n");
return( NS_ERROR_FAILURE);
}
return( m_pWabImport->FindAddressBooks( location, _retval));
return( m_address.GetAddressBooks( _retval));
}
@ -569,28 +554,99 @@ NS_IMETHODIMP ImportAddressImpl::FindAddressBooks(nsIFileSpec *location, nsISupp
NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *source,
nsIAddrDatabase * destination,
nsIImportFieldMap * fieldMap,
PRUnichar ** errorLog,
PRUnichar ** successLog,
PRUnichar ** pErrorLog,
PRUnichar ** pSuccessLog,
PRBool * fatalError)
{
GetOEInterface();
if (!m_pWabImport) {
IMPORT_LOG0( "Outlook address book import failed, cannot load outlook express import module\n");
return( NS_ERROR_FAILURE);
m_msgCount = 0;
m_msgTotal = 0;
NS_PRECONDITION(source != nsnull, "null ptr");
NS_PRECONDITION(destination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsOutlookStringBundle::GetStringBundleProxy()));
nsString success;
nsString error;
if (!source || !destination || !fatalError) {
IMPORT_LOG0( "*** Bad param passed to outlook address import\n");
nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_ADDRESS_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
ImportMailImpl::SetLogs( success, error, pErrorLog, pSuccessLog);
return NS_ERROR_NULL_POINTER;
}
nsString name;
PRUnichar * pName;
if (NS_SUCCEEDED( source->GetPreferredName( &pName))) {
name = pName;
nsCRT::free( pName);
}
PRUint32 id;
if (NS_FAILED( source->GetIdentifier( &id))) {
ImportMailImpl::ReportError( OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE, name, &error);
ImportMailImpl::SetLogs( success, error, pErrorLog, pSuccessLog);
return( NS_ERROR_FAILURE);
}
nsresult rv = NS_OK;
rv = m_address.ImportAddresses( &m_msgCount, &m_msgTotal, name.GetUnicode(), id, destination, error);
if (NS_SUCCEEDED( rv) && error.IsEmpty()) {
ReportSuccess( name, &success);
}
else {
ImportMailImpl::ReportError( OUTLOOKIMPORT_ADDRESS_CONVERTERROR, name, &error);
}
return( m_pWabImport->ImportAddressBook( source, destination, fieldMap, errorLog, successLog, fatalError));
ImportMailImpl::SetLogs( success, error, pErrorLog, pSuccessLog);
IMPORT_LOG0( "*** Returning from outlook address import\n");
return( rv);
}
NS_IMETHODIMP ImportAddressImpl::GetImportProgress(PRUint32 *_retval)
{
GetOEInterface();
if (!m_pWabImport) {
IMPORT_LOG0( "Outlook address book import failed, cannot load outlook express import module\n");
return( NS_ERROR_FAILURE);
}
NS_PRECONDITION(_retval != nsnull, "null ptr");
if (!_retval)
return NS_ERROR_NULL_POINTER;
return( m_pWabImport->GetImportProgress( _retval));
PRUint32 result = m_msgCount;
if (m_msgTotal) {
result *= 100;
result /= m_msgTotal;
}
else
result = 0;
if (result > 100)
result = 100;
*_retval = result;
return( NS_OK);
}
void ImportAddressImpl::ReportSuccess( nsString& name, nsString *pStream)
{
if (!pStream)
return;
// load the success string
nsIStringBundle *pBundle = nsOutlookStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsOutlookStringBundle::GetStringByID( OUTLOOKIMPORT_ADDRESS_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsOutlookStringBundle::FreeString( pFmt);
ImportMailImpl::AddLinebreak( pStream);
NS_IF_RELEASE( pBundle);
}

Просмотреть файл

@ -29,10 +29,15 @@
#include "nscore.h"
#include "nsIServiceManager.h"
#include "nsIImportService.h"
#include "nsIImportFieldMap.h"
#include "nsIImportMailboxDescriptor.h"
#include "nsIImportABDescriptor.h"
#include "nsIImportMimeEncode.h"
#include "nsXPIDLString.h"
#include "nsOutlookStringBundle.h"
#include "nsABBaseCID.h"
#include "nsIAbCard.h"
#include "nsIAddrDatabase.h"
#include "OutlookDebugLog.h"
#include "nsOutlookMail.h"
@ -40,12 +45,60 @@ static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
static NS_DEFINE_CID(kImportMimeEncodeCID, NS_IMPORTMIMEENCODE_CID);
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
/* ------------ Address book stuff ----------------- */
typedef struct {
PRInt32 mozField;
PRInt32 multiLine;
ULONG mapiTag;
} MAPIFields;
/*
Fields in MAPI, not in Mozilla
PR_OFFICE_LOCATION
FIX - PR_BIRTHDAY - stored as PT_SYSTIME - FIX to extract for moz address book birthday
PR_DISPLAY_NAME_PREFIX - Mr., Mrs. Dr., etc.
PR_SPOUSE_NAME
PR_GENDER - integer, not text
FIX - PR_CONTACT_EMAIL_ADDRESSES - multiuline strings for email addresses, needs
parsing to get secondary email address for mozilla
*/
#define kIsMultiLine -2
#define kNoMultiLine -1
MAPIFields gMapiFields[] = {
{ 35, kIsMultiLine, PR_COMMENT},
{ 6, kNoMultiLine, PR_BUSINESS_TELEPHONE_NUMBER},
{ 7, kNoMultiLine, PR_HOME_TELEPHONE_NUMBER},
{ 25, kNoMultiLine, PR_COMPANY_NAME},
{ 23, kNoMultiLine, PR_TITLE},
{ 10, kNoMultiLine, PR_CELLULAR_TELEPHONE_NUMBER},
{ 9, kNoMultiLine, PR_PAGER_TELEPHONE_NUMBER},
{ 8, kNoMultiLine, PR_BUSINESS_FAX_NUMBER},
{ 8, kNoMultiLine, PR_HOME_FAX_NUMBER},
{ 22, kNoMultiLine, PR_COUNTRY},
{ 19, kNoMultiLine, PR_LOCALITY},
{ 20, kNoMultiLine, PR_STATE_OR_PROVINCE},
{ 17, 18, PR_STREET_ADDRESS},
{ 21, kNoMultiLine, PR_POSTAL_CODE},
{ 26, kNoMultiLine, PR_PERSONAL_HOME_PAGE},
{ 27, kNoMultiLine, PR_BUSINESS_HOME_PAGE},
{ 13, kNoMultiLine, PR_HOME_ADDRESS_CITY},
{ 16, kNoMultiLine, PR_HOME_ADDRESS_COUNTRY},
{ 15, kNoMultiLine, PR_HOME_ADDRESS_POSTAL_CODE},
{ 14, kNoMultiLine, PR_HOME_ADDRESS_STATE_OR_PROVINCE},
{ 11, 12, PR_HOME_ADDRESS_STREET},
{ 24, kNoMultiLine, PR_DEPARTMENT_NAME}
};
/* ---------------------------------------------------- */
#define kCopyBufferSize (16 * 1024)
nsOutlookMail::nsOutlookMail()
{
m_gotAddresses = PR_FALSE;
m_gotFolders = PR_FALSE;
m_haveMapi = CMapiApi::LoadMapi();
m_lpMdb = NULL;
@ -53,7 +106,6 @@ nsOutlookMail::nsOutlookMail()
nsOutlookMail::~nsOutlookMail()
{
CMapiApi::UnloadMapi();
EmptyAttachments();
}
@ -76,13 +128,13 @@ nsresult nsOutlookMail::GetMailFolders( nsISupportsArray **pArray)
m_gotFolders = PR_TRUE;
m_storeList.ClearAll();
m_folderList.ClearAll();
m_mapi.Initialize();
m_mapi.LogOn();
m_mapi.IterateStores( m_storeList);
if (m_storeList.GetSize() == 0)
m_mapi.IterateStores( m_storeList);
int i = 0;
CMapiFolder *pFolder;
@ -132,6 +184,111 @@ nsresult nsOutlookMail::GetMailFolders( nsISupportsArray **pArray)
return( NS_OK);
}
PRBool nsOutlookMail::IsAddressBookNameUnique( nsCString& name, nsCString& list)
{
nsCString usedName = "[";
usedName.Append( name);
usedName.Append( "],");
return( list.Find( usedName) == -1);
}
void nsOutlookMail::MakeAddressBookNameUnique( nsCString& name, nsCString& list)
{
nsCString newName;
int idx = 1;
newName = name;
while (!IsAddressBookNameUnique( newName, list)) {
newName = name;
newName.Append( ' ');
newName.Append( (PRInt32) idx);
idx++;
}
name = newName;
list.Append( "[");
list.Append( name);
list.Append( "],");
}
nsresult nsOutlookMail::GetAddressBooks( nsISupportsArray **pArray)
{
if (!m_haveMapi) {
IMPORT_LOG0( "GetAddressBooks called before Mapi is initialized\n");
return( NS_ERROR_FAILURE);
}
nsresult rv = NS_NewISupportsArray( pArray);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "FAILED to allocate the nsISupportsArray for the address book list\n");
return( rv);
}
NS_WITH_SERVICE( nsIImportService, impSvc, kImportServiceCID, &rv);
if (NS_FAILED( rv))
return( rv);
m_gotAddresses = PR_TRUE;
m_addressList.ClearAll();
m_mapi.Initialize();
m_mapi.LogOn();
if (m_storeList.GetSize() == 0)
m_mapi.IterateStores( m_storeList);
int i = 0;
CMapiFolder *pFolder;
if (m_storeList.GetSize() > 1) {
while ((pFolder = m_storeList.GetItem( i))) {
CMapiFolder *pItem = new CMapiFolder( pFolder);
pItem->SetDepth( 1);
m_addressList.AddItem( pItem);
if (!m_mapi.GetStoreAddressFolders( pItem->GetCBEntryID(), pItem->GetEntryID(), m_addressList)) {
IMPORT_LOG1( "GetStoreAddressFolders for index %d failed.\n", i);
}
i++;
}
}
else {
if ((pFolder = m_storeList.GetItem( i))) {
if (!m_mapi.GetStoreAddressFolders( pFolder->GetCBEntryID(), pFolder->GetEntryID(), m_addressList)) {
IMPORT_LOG1( "GetStoreFolders for index %d failed.\n", i);
}
}
}
// Create the mailbox descriptors for the list of folders
nsIImportABDescriptor * pID;
nsISupports * pInterface;
nsCString name;
PRUnichar * pChar;
nsCString list;
for (i = 0; i < m_addressList.GetSize(); i++) {
pFolder = m_addressList.GetItem( i);
if (!pFolder->IsStore()) {
rv = impSvc->CreateNewABDescriptor( &pID);
if (NS_SUCCEEDED( rv)) {
pID->SetIdentifier( i);
pFolder->GetDisplayName( name);
MakeAddressBookNameUnique( name, list);
pChar = name.ToNewUnicode();
pID->SetPreferredName( pChar);
nsCRT::free( pChar);
pID->SetSize( 100);
rv = pID->QueryInterface( kISupportsIID, (void **) &pInterface);
(*pArray)->AppendElement( pInterface);
pInterface->Release();
pID->Release();
}
}
}
return( NS_OK);
}
void nsOutlookMail::OpenMessageStore( CMapiFolder *pNextFolder)
{
@ -691,4 +848,270 @@ void nsOutlookMail::DumpAttachments( void)
#endif
}
nsresult nsOutlookMail::ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, const PRUnichar *pName, PRUint32 id, nsIAddrDatabase *pDb, nsString& errors)
{
if (id >= (PRUint32)(m_addressList.GetSize())) {
IMPORT_LOG0( "*** Bad address identifier, unable to import\n");
return( NS_ERROR_FAILURE);
}
PRUint32 dummyCount = 0;
if (pCount)
*pCount = 0;
else
pCount = &dummyCount;
CMapiFolder *pFolder;
if (id > 0) {
PRInt32 idx = (PRInt32) id;
idx--;
while (idx >= 0) {
pFolder = m_addressList.GetItem( idx);
if (pFolder->IsStore()) {
OpenMessageStore( pFolder);
break;
}
idx--;
}
}
pFolder = m_addressList.GetItem( id);
OpenMessageStore( pFolder);
if (!m_lpMdb) {
IMPORT_LOG1( "*** Unable to obtain mapi message store for address book: %S\n", pName);
return( NS_ERROR_FAILURE);
}
if (pFolder->IsStore())
return( NS_OK);
nsresult rv;
nsCOMPtr<nsIImportFieldMap> pFieldMap;
NS_WITH_SERVICE( nsIImportService, impSvc, kImportServiceCID, &rv);
if (NS_SUCCEEDED( rv)) {
rv = impSvc->CreateNewFieldMap( getter_AddRefs( pFieldMap));
}
CMapiFolderContents contents( m_lpMdb, pFolder->GetCBEntryID(), pFolder->GetEntryID());
BOOL done = FALSE;
ULONG cbEid;
LPENTRYID lpEid;
ULONG oType;
LPMESSAGE lpMsg;
nsCString type;
LPSPropValue pVal;
nsCString subject;
while (!done) {
(*pCount)++;
if (!contents.GetNext( &cbEid, &lpEid, &oType, &done)) {
IMPORT_LOG1( "*** Error iterating address book: %S\n", pName);
return( NS_ERROR_FAILURE);
}
if (pTotal && (*pTotal == 0))
*pTotal = contents.GetCount();
if (!done && (oType == MAPI_MESSAGE)) {
if (!m_mapi.OpenMdbEntry( m_lpMdb, cbEid, lpEid, (LPUNKNOWN *) &lpMsg)) {
IMPORT_LOG1( "*** Error opening messages in mailbox: %S\n", pName);
return( NS_ERROR_FAILURE);
}
// Get the PR_MESSAGE_CLASS attribute,
// ensure that it is IPM.Contact
pVal = m_mapi.GetMapiProperty( lpMsg, PR_MESSAGE_CLASS);
if (pVal) {
type.Truncate( 0);
m_mapi.GetStringFromProp( pVal, type);
if (!type.Compare( "IPM.Contact")) {
// This is a contact, add it to the address book!
subject.Truncate( 0);
pVal = m_mapi.GetMapiProperty( lpMsg, PR_SUBJECT);
if (pVal)
m_mapi.GetStringFromProp( pVal, subject);
nsIMdbRow* newRow = nsnull;
pDb->GetNewRow( &newRow);
// FIXME: Check with Candice about releasing the newRow if it
// isn't added to the database. Candice's code in nsAddressBook
// never releases it but that doesn't seem right to me!
if (newRow) {
if (BuildCard( subject, pDb, newRow, lpMsg, pFieldMap)) {
pDb->AddCardRowToDB( newRow);
}
}
}
}
lpMsg->Release();
}
}
return( NS_OK);
}
void nsOutlookMail::SanitizeValue( nsString& val)
{
val.ReplaceSubstring( "\x0D\x0A", ", ");
val.ReplaceChar( 13, ',');
val.ReplaceChar( 10, ',');
}
void nsOutlookMail::SplitString( nsString& val1, nsString& val2)
{
nsString temp;
// Find the last line if there is more than one!
PRInt32 idx = val1.RFind( "\x0D\x0A");
PRInt32 cnt = 2;
if (idx == -1) {
cnt = 1;
idx = val1.RFindChar( 13);
}
if (idx == -1)
idx= val1.RFindChar( 10);
if (idx != -1) {
val1.Right( val2, val1.Length() - idx - cnt);
val1.Left( temp, idx);
val1 = temp;
SanitizeValue( val1);
}
}
PRBool nsOutlookMail::BuildCard( const char *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap)
{
nsString lastName;
nsString firstName;
nsString eMail;
nsString nickName;
nsString middleName;
LPSPropValue pProp = m_mapi.GetMapiProperty( pUser, PR_EMAIL_ADDRESS);
if (pProp) {
m_mapi.GetStringFromProp( pProp, eMail);
SanitizeValue( eMail);
}
pProp = m_mapi.GetMapiProperty( pUser, PR_GIVEN_NAME);
if (pProp) {
m_mapi.GetStringFromProp( pProp, firstName);
SanitizeValue( firstName);
}
pProp = m_mapi.GetMapiProperty( pUser, PR_SURNAME);
if (pProp) {
m_mapi.GetStringFromProp( pProp, lastName);
SanitizeValue( lastName);
}
pProp = m_mapi.GetMapiProperty( pUser, PR_MIDDLE_NAME);
if (pProp) {
m_mapi.GetStringFromProp( pProp, middleName);
SanitizeValue( middleName);
}
pProp = m_mapi.GetMapiProperty( pUser, PR_NICKNAME);
if (pProp) {
m_mapi.GetStringFromProp( pProp, nickName);
SanitizeValue( nickName);
}
if (firstName.IsEmpty() && lastName.IsEmpty()) {
firstName = pName;
middleName.Truncate();
lastName.Truncate();
}
if (lastName.IsEmpty()) {
lastName = middleName;
middleName.Truncate();
}
if (eMail.IsEmpty())
eMail = pName;
nsString displayName;
pProp = m_mapi.GetMapiProperty( pUser, PR_DISPLAY_NAME);
if (pProp) {
m_mapi.GetStringFromProp( pProp, displayName);
SanitizeValue( displayName);
}
if (displayName.IsEmpty()) {
if (firstName.IsEmpty())
displayName = pName;
else {
displayName = firstName;
if (!middleName.IsEmpty()) {
displayName.Append( ' ');
displayName.Append( middleName);
}
if (!lastName.IsEmpty()) {
displayName.Append( ' ');
displayName.Append( lastName);
}
}
}
char *pCStr;
// We now have the required fields
// write them out followed by any optional fields!
if (!displayName.IsEmpty()) {
pDb->AddDisplayName( newRow, pCStr = displayName.ToNewUTF8String());
nsCRT::free( pCStr);
}
if (!firstName.IsEmpty()) {
pDb->AddFirstName( newRow, pCStr = firstName.ToNewUTF8String());
nsCRT::free( pCStr);
}
if (!lastName.IsEmpty()) {
pDb->AddLastName( newRow, pCStr = lastName.ToNewUTF8String());
nsCRT::free( pCStr);
}
if (!nickName.IsEmpty()) {
pDb->AddNickName( newRow, pCStr = nickName.ToNewUTF8String());
nsCRT::free( pCStr);
}
if (!eMail.IsEmpty()) {
pDb->AddPrimaryEmail( newRow, pCStr = eMail.ToNewUTF8String());
nsCRT::free( pCStr);
}
// Do all of the extra fields!
nsString value;
nsString line2;
if (pFieldMap) {
int max = sizeof( gMapiFields) / sizeof( MAPIFields);
for (int i = 0; i < max; i++) {
pProp = m_mapi.GetMapiProperty( pUser, gMapiFields[i].mapiTag);
if (pProp) {
m_mapi.GetStringFromProp( pProp, value);
if (!value.IsEmpty()) {
if (gMapiFields[i].multiLine == kNoMultiLine) {
SanitizeValue( value);
pFieldMap->SetFieldValue( pDb, newRow, gMapiFields[i].mozField, value.GetUnicode());
}
else if (gMapiFields[i].multiLine == kIsMultiLine) {
pFieldMap->SetFieldValue( pDb, newRow, gMapiFields[i].mozField, value.GetUnicode());
}
else {
line2.Truncate();
SplitString( value, line2);
if (!value.IsEmpty())
pFieldMap->SetFieldValue( pDb, newRow, gMapiFields[i].mozField, value.GetUnicode());
if (!line2.IsEmpty())
pFieldMap->SetFieldValue( pDb, newRow, gMapiFields[i].multiLine, line2.GetUnicode());
}
}
}
}
}
return( PR_TRUE);
}

Просмотреть файл

@ -31,13 +31,18 @@
#include "MapiApi.h"
#include "MapiMessage.h"
class nsIAddrDatabase;
class nsIImportFieldMap;
class nsOutlookMail {
public:
nsOutlookMail();
~nsOutlookMail();
nsresult GetMailFolders( nsISupportsArray **pArray);
nsresult GetAddressBooks( nsISupportsArray **pArray);
nsresult ImportMailbox( PRUint32 *pDoneSoFar, PRBool *pAbort, PRInt32 index, const PRUnichar *pName, nsIFileSpec *pDest, PRInt32 *pMsgCount);
nsresult ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, const PRUnichar *pName, PRUint32 id, nsIAddrDatabase *pDb, nsString& errors);
private:
@ -54,11 +59,19 @@ private:
void BuildAttachments( CMapiMessage& msg, int count);
void DumpAttachments( void);
PRBool IsAddressBookNameUnique( nsCString& name, nsCString& list);
void MakeAddressBookNameUnique( nsCString& name, nsCString& list);
void SanitizeValue( nsString& val);
void SplitString( nsString& val1, nsString& val2);
PRBool BuildCard( const char *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
private:
PRBool m_gotFolders;
PRBool m_gotAddresses;
PRBool m_haveMapi;
CMapiApi m_mapi;
CMapiFolderList m_folderList;
CMapiFolderList m_addressList;
CMapiFolderList m_storeList;
LPMDB m_lpMdb;
nsVoidArray m_attachments;

Просмотреть файл

@ -25,15 +25,22 @@
#include "nsIStringBundle.h"
#include "nsOutlookStringBundle.h"
#include "nsIServiceManager.h"
#include "nsProxyObjectManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
#define OUTLOOK_MSGS_URL "chrome://messenger/locale/outlookImportMsgs.properties"
nsIStringBundle * nsOutlookStringBundle::m_pBundle = nsnull;
nsIStringBundle *nsOutlookStringBundle::GetStringBundle( void)
{
if (m_pBundle)
return( m_pBundle);
nsresult rv;
char* propertyURL = OUTLOOK_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
@ -44,10 +51,29 @@ nsIStringBundle *nsOutlookStringBundle::GetStringBundle( void)
nsILocale * locale = nsnull;
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
m_pBundle = sBundle;
return( sBundle);
}
nsIStringBundle *nsOutlookStringBundle::GetStringBundleProxy( void)
{
if (!m_pBundle)
return( nsnull);
nsIStringBundle *strProxy = nsnull;
nsresult rv;
// create a proxy object if we aren't on the same thread?
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
}
return( strProxy);
}
void nsOutlookStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
@ -58,20 +84,14 @@ void nsOutlookStringBundle::GetStringByID( PRInt32 stringID, nsString& result, n
PRUnichar *nsOutlookStringBundle::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);
}
@ -83,3 +103,9 @@ PRUnichar *nsOutlookStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundl
return( resultString.ToNewUnicode());
}
void nsOutlookStringBundle::Cleanup( void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nsnull;
}

Просмотреть файл

@ -31,9 +31,12 @@ class nsOutlookStringBundle {
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 nsIStringBundle * GetStringBundle( void); // don't release
static nsIStringBundle * GetStringBundleProxy( void); // release
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
static void Cleanup( void);
private:
static nsIStringBundle * m_pBundle;
};
@ -43,7 +46,11 @@ public:
#define OUTLOOKIMPORT_MAILBOX_SUCCESS 2002
#define OUTLOOKIMPORT_MAILBOX_BADPARAM 2003
#define OUTLOOKIMPORT_MAILBOX_CONVERTERROR 2004
#define OUTLOOKIMPORT_ADDRNAME 2005
#define OUTLOOKIMPORT_ADDRESS_SUCCESS 2006
#define OUTLOOKIMPORT_ADDRESS_BADPARAM 2007
#define OUTLOOKIMPORT_ADDRESS_BADSOURCEFILE 2008
#define OUTLOOKIMPORT_ADDRESS_CONVERTERROR 2009
#endif /* _nsOutlookStringBundle_H__ */

Просмотреть файл

@ -44,7 +44,7 @@ NS_METHOD nsImportABDescriptor::Create( nsISupports *aOuter, REFNSIID aIID, void
return rv;
}
NS_IMPL_ISUPPORTS(nsImportABDescriptor, NS_GET_IID(nsIImportABDescriptor));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportABDescriptor, NS_GET_IID(nsIImportABDescriptor));
nsImportABDescriptor::nsImportABDescriptor()
{

Просмотреть файл

@ -48,6 +48,9 @@
#include "nsIAbDirectory.h"
#include "nsImportStringBundle.h"
#include "nsTextFormatter.h"
#include "nsProxyObjectManager.h"
#include "nsProxiedService.h"
#include "ImportDebug.h"
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
@ -61,6 +64,7 @@ static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
static NS_DEFINE_IID(kIImportFieldMapIID, NS_IIMPORTFIELDMAP_IID);
static NS_DEFINE_CID(kSupportsWStringCID, NS_SUPPORTS_WSTRING_CID);
static NS_DEFINE_IID(kISupportsWStringIID, NS_ISUPPORTSWSTRING_IID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
static const char *kDirectoryDataSourceRoot = "abdirectory://";
@ -217,7 +221,7 @@ nsImportGenericAddressBooks::~nsImportGenericAddressBooks()
NS_IMPL_ISUPPORTS(nsImportGenericAddressBooks, NS_GET_IID(nsIImportGeneric));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportGenericAddressBooks, NS_GET_IID(nsIImportGeneric));
NS_IMETHODIMP nsImportGenericAddressBooks::GetData(const char *dataId, nsISupports **_retval)
@ -761,12 +765,20 @@ nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew)
IMPORT_LOG0( "In GetAddressBook\n");
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_FAILED( rv)) {
IMPORT_LOG0( "*** Error: Unable to get proxy manager\n");
return( nsnull);
}
nsIAddrDatabase * pDatabase = nsnull;
/* Get the profile directory */
// Note to Candice: This should return an nsIFileSpec, not a nsFileSpec
nsFileSpec * dbPath = nsnull;
NS_WITH_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, &rv);
nsFileSpec * dbPath = nsnull;
NS_WITH_PROXIED_SERVICE(nsIAddrBookSession, abSession, kAddrBookSessionCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_SUCCEEDED(rv))
abSession->GetUserProfileDirectory(&dbPath);
if (dbPath) {
@ -777,11 +789,10 @@ nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew)
IMPORT_LOG0( "Getting the address database factory\n");
NS_WITH_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIAddrDatabase, addrDBFactory, kAddressBookDBCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_SUCCEEDED(rv) && addrDBFactory) {
IMPORT_LOG0( "Opening the new address book\n");
rv = addrDBFactory->Open( dbPath, PR_TRUE, &pDatabase, PR_TRUE);
}
}
@ -795,12 +806,14 @@ nsIAddrDatabase *GetAddressBook( const PRUnichar *name, PRBool makeNew)
// This is major bogosity again! Why doesn't the address book
// just handle this properly for me? Uggggg...
NS_WITH_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, &rv);
NS_WITH_PROXIED_SERVICE(nsIRDFService, rdfService, kRDFServiceCID, NS_UI_THREAD_EVENTQ, &rv);
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIRDFResource> parentResource;
nsCOMPtr<nsIRDFResource> parentResource;
char *parentUri = PR_smprintf( "%s", kDirectoryDataSourceRoot);
rv = rdfService->GetResource( parentUri, getter_AddRefs(parentResource));
nsCOMPtr<nsIAbDirectory> parentDir = do_QueryInterface(parentResource);
nsCOMPtr<nsIAbDirectory> parentDir;
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID( nsIAbDirectory),
parentResource, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( parentDir));
if (parentUri)
PR_smprintf_free(parentUri);
if (parentDir) {

Просмотреть файл

@ -25,6 +25,7 @@
#include "nsIImportService.h"
#include "nsImportMimeEncode.h"
#include "nsCRT.h"
#include "nsImportStringBundle.h"
#include "ImportDebug.h"
@ -46,7 +47,12 @@ static nsModuleComponentInfo components[] = {
};
PR_STATIC_CALLBACK(void)
importModuleDtor(nsIModule* self)
{
nsImportStringBundle::Cleanup();
}
NS_IMPL_NSGETMODULE( "nsImportServiceModule", components)
NS_IMPL_NSGETMODULE_WITH_DTOR( "nsImportServiceModule", components, importModuleDtor)

Просмотреть файл

@ -29,6 +29,8 @@
#include "ImportDebug.h"
////////////////////////////////////////////////////////////////////////
@ -48,7 +50,7 @@ NS_METHOD nsImportFieldMap::Create( nsISupports *aOuter, REFNSIID aIID, void **a
return rv;
}
NS_IMPL_ISUPPORTS(nsImportFieldMap, NS_GET_IID(nsIImportFieldMap));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportFieldMap, NS_GET_IID(nsIImportFieldMap));
nsImportFieldMap::nsImportFieldMap()
{
@ -59,14 +61,19 @@ nsImportFieldMap::nsImportFieldMap()
m_allocated = 0;
// need to init the description array
m_mozFieldCount = 0;
nsIStringBundle *pBundle = nsImportStringBundle::GetStringBundle();
nsIStringBundle *pBundle = nsImportStringBundle::GetStringBundleProxy();
nsString *pStr;
for (PRInt32 i = IMPORT_FIELD_DESC_START; i <= IMPORT_FIELD_DESC_END; i++, m_mozFieldCount++) {
pStr = new nsString();
nsImportStringBundle::GetStringByID( i, *pStr, pBundle);
if (pBundle) {
nsImportStringBundle::GetStringByID( i, *pStr, pBundle);
}
else
pStr->Append( i);
m_descriptions.AppendElement( (void *)pStr);
}
NS_IF_RELEASE( pBundle);
}

Просмотреть файл

@ -22,26 +22,6 @@
*/
/*
TODO:
* Fix the the name of the imported folder to reflect the module
name rather than just "Imported Mail"
* Fix the imported folder name to only call GenerateUnique if
necessary (that way the first import won't have a zero after the
name!).
* Test Cancel to make sure it works!
* Figure out how to clean-up when an import is cancelled and
we do NOT own the destination folder.
* Do the right thing when creating a folder that already exists. Should
we create a new folder or append to the one that we found already existing?
* Fix the default destination to create an account if it cannot find
a suitable account to import into.
* Determine if I need to "lock" mailboxes for import?
*/
@ -68,6 +48,7 @@
#include "nsIProfile.h"
#include "nsIMsgFolder.h"
#include "nsImportStringBundle.h"
#include "nsIStringBundle.h"
#include "nsTextFormatter.h"
#include "ImportDebug.h"
@ -236,7 +217,7 @@ nsImportGenericMail::~nsImportGenericMail()
NS_IMPL_ISUPPORTS(nsImportGenericMail, NS_GET_IID(nsIImportGeneric));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportGenericMail, NS_GET_IID(nsIImportGeneric));
NS_IMETHODIMP nsImportGenericMail::GetData(const char *dataId, nsISupports **_retval)
@ -649,12 +630,14 @@ void nsImportGenericMail::ReportError( PRInt32 id, const PRUnichar *pName, nsStr
if (!pStream)
return;
// load the error string
PRUnichar *pFmt = nsImportStringBundle::GetStringByID( id);
nsIStringBundle *pBundle = nsImportStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsImportStringBundle::GetStringByID( id, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, pName);
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsImportStringBundle::FreeString( pFmt);
pStream->Append( NS_LINEBREAK);
NS_IF_RELEASE( pBundle);
}
@ -795,17 +778,19 @@ ImportMailThread( void *stuff)
nsString success;
nsString error;
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsImportStringBundle::GetStringBundleProxy()));
// Initialize the curFolder proxy object
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder),
curFolder, PROXY_SYNC, getter_AddRefs( curProxy));
curFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy));
IMPORT_LOG1( "Proxy result for curFolder: 0x%lx\n", (long) rv);
}
else {
IMPORT_LOG0( "Unable to obtain proxy service to do import\n");
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error);
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle);
pData->abort = PR_TRUE;
}
@ -837,9 +822,9 @@ ImportMailThread( void *stuff)
}
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder),
subFolder, PROXY_SYNC, getter_AddRefs( curProxy));
subFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy));
if (NS_FAILED( rv)) {
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error);
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle);
pData->fatalError = PR_TRUE;
break;
}
@ -852,11 +837,11 @@ ImportMailThread( void *stuff)
nsCOMPtr<nsIFolder> parFolder;
curProxy->GetParent( getter_AddRefs( parFolder));
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder),
parFolder, PROXY_SYNC, getter_AddRefs( curProxy));
parFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy));
depth--;
}
if (NS_FAILED( rv)) {
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error);
nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle);
pData->fatalError = PR_TRUE;
break;
}

Просмотреть файл

@ -44,7 +44,7 @@ NS_METHOD nsImportMailboxDescriptor::Create( nsISupports *aOuter, REFNSIID aIID,
return rv;
}
NS_IMPL_ISUPPORTS(nsImportMailboxDescriptor, NS_GET_IID(nsIImportMailboxDescriptor));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportMailboxDescriptor, NS_GET_IID(nsIImportMailboxDescriptor));
nsImportMailboxDescriptor::nsImportMailboxDescriptor()
{

Просмотреть файл

@ -38,6 +38,7 @@
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsISupportsPrimitives.h"
#include "nsImportStringBundle.h"
#include "plstr.h"
#include "prmem.h"
#include "ImportDebug.h"
@ -186,6 +187,8 @@ NS_IMETHODIMP NS_NewImportService( nsISupports* aOuter, REFNSIID aIID, void **aR
*aResult = nsnull;
}
NS_RELEASE( gImportService);
nsImportStringBundle::GetStringBundle();
return( rv);
}
@ -217,7 +220,7 @@ nsImportService::~nsImportService()
NS_IMPL_ISUPPORTS(nsImportService, NS_GET_IID(nsIImportService));
NS_IMPL_THREADSAFE_ISUPPORTS(nsImportService, NS_GET_IID(nsIImportService));
NS_IMETHODIMP nsImportService::DiscoverModules( void)

Просмотреть файл

@ -25,15 +25,22 @@
#include "nsIStringBundle.h"
#include "nsImportStringBundle.h"
#include "nsIServiceManager.h"
#include "nsProxyObjectManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
#define IMPORT_MSGS_URL "chrome://messenger/locale/importMsgs.properties"
nsIStringBundle * nsImportStringBundle::m_pBundle = nsnull;
nsIStringBundle *nsImportStringBundle::GetStringBundle( void)
{
if (m_pBundle)
return( m_pBundle);
nsresult rv;
char* propertyURL = IMPORT_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
@ -44,10 +51,28 @@ nsIStringBundle *nsImportStringBundle::GetStringBundle( void)
nsILocale * locale = nsnull;
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
m_pBundle = sBundle;
return( sBundle);
}
nsIStringBundle *nsImportStringBundle::GetStringBundleProxy( void)
{
if (!m_pBundle)
return( nsnull);
nsIStringBundle *strProxy = nsnull;
nsresult rv;
// create a proxy object if we aren't on the same thread?
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
}
return( strProxy);
}
void nsImportStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
@ -58,20 +83,14 @@ void nsImportStringBundle::GetStringByID( PRInt32 stringID, nsString& result, ns
PRUnichar *nsImportStringBundle::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);
}
@ -83,3 +102,9 @@ PRUnichar *nsImportStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle
return( resultString.ToNewUnicode());
}
void nsImportStringBundle::Cleanup( void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nsnull;
}

Просмотреть файл

@ -31,9 +31,13 @@ class nsImportStringBundle {
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 nsIStringBundle * GetStringBundle( void); // dont release
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
static void Cleanup( void);
static nsIStringBundle * GetStringBundleProxy( void); // release
private:
static nsIStringBundle * m_pBundle;
};

Просмотреть файл

@ -29,6 +29,7 @@
#include "nsCRT.h"
#include "nsICategoryManager.h"
#include "nsXPIDLString.h"
#include "nsTextStringBundle.h"
#include "TextDebugLog.h"
@ -71,6 +72,13 @@ static nsModuleComponentInfo components[] = {
}
};
NS_IMPL_NSGETMODULE("nsTextImportModule", components)
PR_STATIC_CALLBACK(void)
textModuleDtor(nsIModule* self)
{
nsTextStringBundle::Cleanup();
}
NS_IMPL_NSGETMODULE_WITH_DTOR("nsTextImportModule", components, textModuleDtor)

Просмотреть файл

@ -41,10 +41,11 @@
#include "nsIAddrDatabase.h"
#include "nsTextFormatter.h"
#include "nsTextStringBundle.h"
#include "nsIStringBundle.h"
#include "nsTextAddress.h"
#include "nsIPref.h"
#include "nsXPIDLString.h"
#include "nsProxiedService.h"
#include "TextDebugLog.h"
@ -128,6 +129,7 @@ nsTextImport::nsTextImport()
IMPORT_LOG0( "nsTextImport Module Created\n");
nsTextStringBundle::GetStringBundle();
}
@ -236,6 +238,7 @@ nsresult ImportAddressImpl::Create(nsIImportAddressBooks** aImport)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aImport);
return NS_OK;
}
@ -261,7 +264,7 @@ ImportAddressImpl::~ImportAddressImpl()
NS_IMPL_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMPL_THREADSAFE_ISUPPORTS(ImportAddressImpl, NS_GET_IID(nsIImportAddressBooks));
NS_IMETHODIMP ImportAddressImpl::GetAutoFind(PRUnichar **addrDescription, PRBool *_retval)
@ -393,12 +396,14 @@ void ImportAddressImpl::ReportSuccess( nsString& name, nsString *pStream)
if (!pStream)
return;
// load the success string
PRUnichar *pFmt = nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_SUCCESS);
nsIStringBundle *pBundle = nsTextStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_SUCCESS, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsTextStringBundle::FreeString( pFmt);
pStream->Append( NS_LINEBREAK);
NS_IF_RELEASE( pBundle);
}
void ImportAddressImpl::ReportError( PRInt32 errorNum, nsString& name, nsString *pStream)
@ -406,12 +411,14 @@ void ImportAddressImpl::ReportError( PRInt32 errorNum, nsString& name, nsString
if (!pStream)
return;
// load the error string
PRUnichar *pFmt = nsTextStringBundle::GetStringByID( errorNum);
nsIStringBundle *pBundle = nsTextStringBundle::GetStringBundleProxy();
PRUnichar *pFmt = nsTextStringBundle::GetStringByID( errorNum, pBundle);
PRUnichar *pText = nsTextFormatter::smprintf( pFmt, name.GetUnicode());
pStream->Append( pText);
nsTextFormatter::smprintf_free( pText);
nsTextStringBundle::FreeString( pFmt);
pStream->Append( NS_LINEBREAK);
NS_IF_RELEASE( pBundle);
}
void ImportAddressImpl::SetLogs( nsString& success, nsString& error, PRUnichar **pError, PRUnichar **pSuccess)
@ -433,14 +440,15 @@ NS_IMETHODIMP ImportAddressImpl::ImportAddressBook( nsIImportABDescriptor *pSour
NS_PRECONDITION(pSource != nsnull, "null ptr");
NS_PRECONDITION(pDestination != nsnull, "null ptr");
NS_PRECONDITION(fatalError != nsnull, "null ptr");
nsCOMPtr<nsIStringBundle> bundle( dont_AddRef( nsTextStringBundle::GetStringBundleProxy()));
m_bytesImported = 0;
nsString success;
nsString error;
if (!pSource || !pDestination || !fatalError) {
IMPORT_LOG0( "*** Bad param passed to text address import\n");
nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_BADPARAM, error);
nsTextStringBundle::GetStringByID( TEXTIMPORT_ADDRESS_BADPARAM, error, bundle);
if (fatalError)
*fatalError = PR_TRUE;
SetLogs( success, error, pErrorLog, pSuccessLog);
@ -756,7 +764,9 @@ void ImportAddressImpl::SaveFieldMap( nsIImportFieldMap *pMap)
PRBool done = PR_FALSE;
nsresult rv;
// NS_WITH_PROXIED_SERVICE( nsIPref, prefs, kPrefServiceCID, NS_UI_THREAD_EVENTQ, &rv);
NS_WITH_SERVICE( nsIPref, prefs, kPrefServiceCID, &rv);
if (NS_SUCCEEDED( rv)) {
nsXPIDLCString prefStr;
rv = prefs->CopyCharPref( "mailnews.import.text.fieldmap", getter_Copies(prefStr));

Просмотреть файл

@ -22,15 +22,22 @@
#include "nsIStringBundle.h"
#include "nsTextStringBundle.h"
#include "nsIServiceManager.h"
#include "nsProxyObjectManager.h"
#include "nsIURI.h"
/* This is the next generation string retrieval call */
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
static NS_DEFINE_IID(kProxyObjectManagerCID, NS_PROXYEVENT_MANAGER_CID);
nsIStringBundle * nsTextStringBundle::m_pBundle = nsnull;
#define TEXT_MSGS_URL "chrome://messenger/locale/textImportMsgs.properties"
nsIStringBundle *nsTextStringBundle::GetStringBundle( void)
{
if (m_pBundle)
return( m_pBundle);
nsresult rv;
char* propertyURL = TEXT_MSGS_URL;
nsIStringBundle* sBundle = nsnull;
@ -42,9 +49,28 @@ nsIStringBundle *nsTextStringBundle::GetStringBundle( void)
rv = sBundleService->CreateBundle(propertyURL, locale, &sBundle);
}
m_pBundle = sBundle;
return( sBundle);
}
nsIStringBundle *nsTextStringBundle::GetStringBundleProxy( void)
{
if (!m_pBundle)
return( nsnull);
nsIStringBundle *strProxy = nsnull;
nsresult rv;
// create a proxy object if we aren't on the same thread?
NS_WITH_SERVICE( nsIProxyObjectManager, proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_SUCCEEDED(rv)) {
rv = proxyMgr->GetProxyObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIStringBundle),
m_pBundle, PROXY_SYNC | PROXY_ALWAYS, (void **) &strProxy);
}
return( strProxy);
}
void nsTextStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIStringBundle *pBundle)
{
@ -55,20 +81,14 @@ void nsTextStringBundle::GetStringByID( PRInt32 stringID, nsString& result, nsIS
PRUnichar *nsTextStringBundle::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);
}
@ -80,3 +100,9 @@ PRUnichar *nsTextStringBundle::GetStringByID(PRInt32 stringID, nsIStringBundle *
return( resultString.ToNewUnicode());
}
void nsTextStringBundle::Cleanup( void)
{
if (m_pBundle)
m_pBundle->Release();
m_pBundle = nsnull;
}

Просмотреть файл

@ -29,7 +29,12 @@ public:
static void GetStringByID(PRInt32 stringID, nsString& result, nsIStringBundle *pBundle = nsnull);
// GetStringBundle creates a new one every time!
static nsIStringBundle * GetStringBundle( void);
static nsIStringBundle * GetStringBundleProxy( void);
static void FreeString( PRUnichar *pStr) { nsCRT::free( pStr);}
static void Cleanup( void);
private:
static nsIStringBundle * m_pBundle;
};