mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-30 08:12:05 +00:00
Lots of i18N fixes for address book importing.
This commit is contained in:
parent
1b6abd549c
commit
e55e8d91c0
@ -22,9 +22,11 @@
|
||||
#include "nsIAddrDatabase.h"
|
||||
#include "nsABBaseCID.h"
|
||||
#include "nsIAbCard.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
static NS_DEFINE_CID(kAbCardCID, NS_ABCARD_CID);
|
||||
static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
|
||||
#include "EudoraDebugLog.h"
|
||||
|
||||
@ -694,6 +696,18 @@ void nsEudoraAddress::SplitString( nsCString& val1, nsCString& val2)
|
||||
}
|
||||
}
|
||||
|
||||
void nsEudoraAddress::ConvertToUnicode( const char *pStr, nsString& uniStr)
|
||||
{
|
||||
if (!m_pService) {
|
||||
m_pService = do_GetService( kImportServiceCID);
|
||||
}
|
||||
if (m_pService) {
|
||||
m_pService->SystemStringToUnicode( pStr, uniStr);
|
||||
}
|
||||
else
|
||||
uniStr.Assign( pStr);
|
||||
}
|
||||
|
||||
void nsEudoraAddress::BuildSingleCard( CAliasEntry *pEntry, CAliasData *pData, nsIAddrDatabase *pDb)
|
||||
{
|
||||
// we have a nickname always
|
||||
@ -738,44 +752,45 @@ void nsEudoraAddress::BuildSingleCard( CAliasEntry *pEntry, CAliasData *pData, n
|
||||
nsString uniStr;
|
||||
|
||||
if (newRow) {
|
||||
uniStr = displayName;
|
||||
ConvertToUnicode( displayName, uniStr);
|
||||
pDb->AddDisplayName( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
|
||||
uniStr = pEntry->m_name;
|
||||
ConvertToUnicode( pEntry->m_name, uniStr);
|
||||
pDb->AddNickName( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
|
||||
uniStr = pData->m_email;
|
||||
|
||||
ConvertToUnicode( pData->m_email, uniStr);
|
||||
pDb->AddPrimaryEmail( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
|
||||
if (!fax.IsEmpty()) {
|
||||
uniStr = fax;
|
||||
ConvertToUnicode( fax, uniStr);
|
||||
pDb->AddFaxNumber( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
}
|
||||
|
||||
if (!phone.IsEmpty()) {
|
||||
uniStr = phone;
|
||||
ConvertToUnicode( phone, uniStr);
|
||||
pDb->AddHomePhone( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
}
|
||||
|
||||
if (!address.IsEmpty()) {
|
||||
uniStr = address;
|
||||
ConvertToUnicode( address, uniStr);
|
||||
pDb->AddHomeAddress( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
}
|
||||
|
||||
if (!address2.IsEmpty()) {
|
||||
uniStr = address2;
|
||||
ConvertToUnicode( address2, uniStr);
|
||||
pDb->AddHomeAddress2( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
}
|
||||
|
||||
if (!note.IsEmpty()) {
|
||||
uniStr = note;
|
||||
ConvertToUnicode( note, uniStr);
|
||||
pDb->AddNotes( newRow, pCStr = uniStr.ToNewUTF8String());
|
||||
nsCRT::free( pCStr);
|
||||
}
|
||||
|
@ -24,7 +24,8 @@
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsISupportsArray.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIImportService.h"
|
||||
|
||||
|
||||
class nsIAddrDatabase;
|
||||
@ -67,6 +68,7 @@ private:
|
||||
void ExtractNoteField( nsCString& note, nsCString& field, const char *pFieldName);
|
||||
void SanitizeValue( nsCString& val);
|
||||
void SplitString( nsCString& val1, nsCString& val2);
|
||||
void ConvertToUnicode( const char *pStr, nsString& uniStr);
|
||||
|
||||
public:
|
||||
static PRInt32 CountQuote( const char *pLine, PRInt32 len);
|
||||
@ -75,6 +77,7 @@ public:
|
||||
|
||||
private:
|
||||
nsVoidArray m_alias;
|
||||
nsCOMPtr<nsIImportService> m_pService;
|
||||
};
|
||||
|
||||
|
||||
|
@ -100,7 +100,10 @@ AddrImportField extraUserFields[kExtraUserFields] = {
|
||||
CWAB::CWAB(nsIFileSpec *file)
|
||||
{
|
||||
// Here we load the WAB Object and initialize it
|
||||
m_bInitialized = PR_FALSE;
|
||||
m_pUniBuff = NULL;
|
||||
m_uniBuffLen = 0;
|
||||
|
||||
m_bInitialized = PR_FALSE;
|
||||
m_lpAdrBook = NULL;
|
||||
m_lpWABObject = NULL;
|
||||
m_hinstWAB = NULL;
|
||||
@ -168,6 +171,9 @@ CWAB::CWAB(nsIFileSpec *file)
|
||||
//
|
||||
CWAB::~CWAB()
|
||||
{
|
||||
if (m_pUniBuff)
|
||||
delete [] m_pUniBuff;
|
||||
|
||||
if(m_bInitialized)
|
||||
{
|
||||
if(m_lpAdrBook)
|
||||
@ -202,6 +208,8 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone)
|
||||
ULONG rowCount = 0;
|
||||
ULONG curCount = 0;
|
||||
|
||||
nsString uniStr;
|
||||
|
||||
// Get the entryid of the root PAB container
|
||||
//
|
||||
hr = m_lpAdrBook->GetPAB( &lpcbEID, &lpEID);
|
||||
@ -293,7 +301,8 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone)
|
||||
// on the listview item representing that object. This enables
|
||||
// us to uniquely identify the object later if we need to
|
||||
//
|
||||
keepGoing = pIter->EnumUser( lpsz, lpEID, cbEID);
|
||||
CStrToUnicode( lpsz, uniStr);
|
||||
keepGoing = pIter->EnumUser( uniStr.GetUnicode(), lpEID, cbEID);
|
||||
curCount++;
|
||||
if (pDone) {
|
||||
*pDone = (curCount * 100) / rowCount;
|
||||
@ -344,7 +353,8 @@ HRESULT CWAB::IterateWABContents(CWabIterator *pIter, int *pDone)
|
||||
// on the listview item representing that object. This enables
|
||||
// us to uniquely identify the object later if we need to
|
||||
//
|
||||
keepGoing = pIter->EnumList( lpsz, lpEID, cbEID);
|
||||
CStrToUnicode( lpsz, uniStr);
|
||||
keepGoing = pIter->EnumList( uniStr.GetUnicode(), lpEID, cbEID);
|
||||
curCount++;
|
||||
if (pDone) {
|
||||
*pDone = (curCount * 100) / rowCount;
|
||||
@ -474,6 +484,22 @@ LPSPropValue CWAB::GetUserProperty( LPMAILUSER pUser, ULONG tag)
|
||||
return( lpProp);
|
||||
}
|
||||
|
||||
void CWAB::CStrToUnicode( const char *pStr, nsString& result)
|
||||
{
|
||||
result.Truncate( 0);
|
||||
int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
|
||||
if (wLen >= m_uniBuffLen) {
|
||||
if (m_pUniBuff)
|
||||
delete [] m_pUniBuff;
|
||||
m_pUniBuff = new PRUnichar[wLen + 64];
|
||||
m_uniBuffLen = wLen + 64;
|
||||
}
|
||||
if (wLen) {
|
||||
MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
|
||||
result = m_pUniBuff;
|
||||
}
|
||||
}
|
||||
|
||||
// If the value is a string, get it...
|
||||
void CWAB::GetValueString( LPSPropValue pVal, nsString& val)
|
||||
{
|
||||
@ -483,17 +509,19 @@ void CWAB::GetValueString( LPSPropValue pVal, nsString& val)
|
||||
return;
|
||||
|
||||
switch( PROP_TYPE( pVal->ulPropTag)) {
|
||||
case PT_STRING8:
|
||||
// Do we need to call OS routines like MultiByteToWideChar?
|
||||
val = (char *) (pVal->Value.lpszA);
|
||||
case PT_STRING8: {
|
||||
CStrToUnicode( (const char *) (pVal->Value.lpszA), val);
|
||||
}
|
||||
break;
|
||||
case PT_UNICODE:
|
||||
val = (PRUnichar *) (pVal->Value.lpszW);
|
||||
break;
|
||||
case PT_MV_STRING8: {
|
||||
nsString tmp;
|
||||
ULONG j;
|
||||
for(j = 0; j < pVal->Value.MVszA.cValues; j++) {
|
||||
val += (char *) (pVal->Value.MVszA.lppszA[j]);
|
||||
CStrToUnicode( (const char *) (pVal->Value.MVszA.lppszA[j]), tmp);
|
||||
val += tmp;
|
||||
val += TR_OUTPUT_EOL;
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@
|
||||
|
||||
class CWabIterator {
|
||||
public:
|
||||
virtual PRBool EnumUser( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid) = 0;
|
||||
virtual PRBool EnumList( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid) = 0;
|
||||
virtual PRBool EnumUser( const PRUnichar *pName, LPENTRYID pEid, ULONG cbEid) = 0;
|
||||
virtual PRBool EnumList( const PRUnichar *pName, LPENTRYID pEid, ULONG cbEid) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -59,12 +59,15 @@ public:
|
||||
void FreeProperty( LPSPropValue pVal) { if (pVal) m_lpWABObject->FreeBuffer( pVal);}
|
||||
void GetValueString( LPSPropValue pVal, nsString& val);
|
||||
|
||||
void CStrToUnicode( const char *pStr, nsString& result);
|
||||
|
||||
// Utility stuff used by iterate
|
||||
void FreeProws(LPSRowSet prows);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
PRUnichar * m_pUniBuff;
|
||||
int m_uniBuffLen;
|
||||
PRBool m_bInitialized;
|
||||
HINSTANCE m_hinstWAB;
|
||||
LPWABOPEN m_lpfnWABOpen;
|
||||
|
@ -103,9 +103,9 @@ nsOEAddressIterator::~nsOEAddressIterator()
|
||||
NS_IF_RELEASE( m_database);
|
||||
}
|
||||
|
||||
PRBool nsOEAddressIterator::EnumUser( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid)
|
||||
PRBool nsOEAddressIterator::EnumUser( const PRUnichar * pName, LPENTRYID pEid, ULONG cbEid)
|
||||
{
|
||||
IMPORT_LOG1( "User: %s\n", pName);
|
||||
IMPORT_LOG1( "User: %S\n", pName);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
@ -131,9 +131,9 @@ PRBool nsOEAddressIterator::EnumUser( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid
|
||||
return( PR_TRUE);
|
||||
}
|
||||
|
||||
PRBool nsOEAddressIterator::EnumList( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid)
|
||||
PRBool nsOEAddressIterator::EnumList( const PRUnichar * pName, LPENTRYID pEid, ULONG cbEid)
|
||||
{
|
||||
IMPORT_LOG1( "List: %s\n", pName);
|
||||
IMPORT_LOG1( "List: %S\n", pName);
|
||||
return( PR_TRUE);
|
||||
}
|
||||
|
||||
@ -165,7 +165,7 @@ void nsOEAddressIterator::SplitString( nsString& val1, nsString& val2)
|
||||
}
|
||||
}
|
||||
|
||||
PRBool nsOEAddressIterator::BuildCard( LPCTSTR pName, nsIMdbRow *newRow, LPMAILUSER pUser)
|
||||
PRBool nsOEAddressIterator::BuildCard( const PRUnichar * pName, nsIMdbRow *newRow, LPMAILUSER pUser)
|
||||
{
|
||||
|
||||
nsString lastName;
|
||||
@ -204,18 +204,10 @@ PRBool nsOEAddressIterator::BuildCard( LPCTSTR pName, nsIMdbRow *newRow, LPMAILU
|
||||
SanitizeValue( nickName);
|
||||
m_pWab->FreeProperty( pProp);
|
||||
}
|
||||
if (nickName.IsEmpty())
|
||||
nickName = pName;
|
||||
if (firstName.IsEmpty()) {
|
||||
firstName = nickName;
|
||||
middleName.Truncate();
|
||||
lastName.Truncate();
|
||||
}
|
||||
if (lastName.IsEmpty())
|
||||
middleName.Truncate();
|
||||
|
||||
if (eMail.IsEmpty())
|
||||
eMail = nickName;
|
||||
|
||||
// The idea here is that firstName and lastName cannot both be empty!
|
||||
if (firstName.IsEmpty() && lastName.IsEmpty())
|
||||
firstName = pName;
|
||||
|
||||
nsString displayName;
|
||||
pProp = m_pWab->GetUserProperty( pUser, PR_DISPLAY_NAME);
|
||||
@ -226,7 +218,7 @@ PRBool nsOEAddressIterator::BuildCard( LPCTSTR pName, nsIMdbRow *newRow, LPMAILU
|
||||
}
|
||||
if (displayName.IsEmpty()) {
|
||||
if (firstName.IsEmpty())
|
||||
displayName = nickName;
|
||||
displayName = pName;
|
||||
else {
|
||||
displayName = firstName;
|
||||
if (!middleName.IsEmpty()) {
|
||||
|
@ -32,11 +32,11 @@ public:
|
||||
nsOEAddressIterator( CWAB *pWab, nsIAddrDatabase *database);
|
||||
~nsOEAddressIterator();
|
||||
|
||||
virtual PRBool EnumUser( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid);
|
||||
virtual PRBool EnumList( LPCTSTR pName, LPENTRYID pEid, ULONG cbEid);
|
||||
virtual PRBool EnumUser( const PRUnichar * pName, LPENTRYID pEid, ULONG cbEid);
|
||||
virtual PRBool EnumList( const PRUnichar * pName, LPENTRYID pEid, ULONG cbEid);
|
||||
|
||||
private:
|
||||
PRBool BuildCard( LPCTSTR pName, nsIMdbRow *card, LPMAILUSER pUser);
|
||||
PRBool BuildCard( const PRUnichar * pName, nsIMdbRow *card, LPMAILUSER pUser);
|
||||
void SanitizeValue( nsString& val);
|
||||
void SplitString( nsString& val1, nsString& val2);
|
||||
|
||||
|
@ -33,7 +33,8 @@ nsVoidArray *CMapiApi::m_pStores = NULL;
|
||||
LPMAPISESSION CMapiApi::m_lpSession = NULL;
|
||||
LPMDB CMapiApi::m_lpMdb = NULL;
|
||||
HRESULT CMapiApi::m_lastError;
|
||||
|
||||
PRUnichar * CMapiApi::m_pUniBuff = NULL;
|
||||
int CMapiApi::m_uniBuffLen = 0;
|
||||
/*
|
||||
Type: 1, name: Calendar, class: IPF.Appointment
|
||||
Type: 1, name: Contacts, class: IPF.Contact
|
||||
@ -164,7 +165,7 @@ CMapiApi::~CMapiApi()
|
||||
m_clients--;
|
||||
if (!m_clients) {
|
||||
HRESULT hr;
|
||||
|
||||
|
||||
ClearMessageStores();
|
||||
delete m_pStores;
|
||||
m_pStores = NULL;
|
||||
@ -186,6 +187,27 @@ CMapiApi::~CMapiApi()
|
||||
}
|
||||
|
||||
UnloadMapi();
|
||||
|
||||
if (m_pUniBuff)
|
||||
delete [] m_pUniBuff;
|
||||
m_pUniBuff = NULL;
|
||||
m_uniBuffLen = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CMapiApi::CStrToUnicode( const char *pStr, nsString& result)
|
||||
{
|
||||
result.Truncate( 0);
|
||||
int wLen = MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, 0);
|
||||
if (wLen >= m_uniBuffLen) {
|
||||
if (m_pUniBuff)
|
||||
delete [] m_pUniBuff;
|
||||
m_pUniBuff = new PRUnichar[wLen + 64];
|
||||
m_uniBuffLen = wLen + 64;
|
||||
}
|
||||
if (wLen) {
|
||||
MultiByteToWideChar( CP_ACP, 0, pStr, -1, m_pUniBuff, m_uniBuffLen);
|
||||
result = m_pUniBuff;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1075,6 +1097,16 @@ BOOL CMapiApi::GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsCString& v
|
||||
return( bResult);
|
||||
}
|
||||
|
||||
BOOL CMapiApi::GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsString& val)
|
||||
{
|
||||
nsCString result;
|
||||
if (GetLargeStringProperty( pProp, tag, result)) {
|
||||
CStrToUnicode( result, val);
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
return( FALSE);
|
||||
}
|
||||
// If the value is a string, get it...
|
||||
BOOL CMapiApi::GetEntryIdFromProp( LPSPropValue pVal, ULONG& cbEntryId, LPENTRYID& lpEntryId, BOOL delVal)
|
||||
{
|
||||
@ -1137,8 +1169,7 @@ 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!
|
||||
CStrToUnicode( (const char *)pVal->Value.lpszA, val);
|
||||
}
|
||||
else if ( pVal && (PROP_TYPE( pVal->ulPropTag) == PT_UNICODE)) {
|
||||
val = (PRUnichar *) pVal->Value.lpszW;
|
||||
|
@ -39,6 +39,106 @@
|
||||
// defines _MAPIUTIL_H_
|
||||
#define _MAPIUTIL_H
|
||||
|
||||
class CMapiFolderList;
|
||||
class CMsgStore;
|
||||
class CMapiFolder;
|
||||
|
||||
class CMapiContentIter {
|
||||
public:
|
||||
virtual BOOL HandleContentItem( ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiHierarchyIter {
|
||||
public:
|
||||
virtual BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiApi {
|
||||
public:
|
||||
CMapiApi();
|
||||
~CMapiApi();
|
||||
|
||||
static BOOL LoadMapi( void);
|
||||
static BOOL LoadMapiEntryPoints( void);
|
||||
static void UnloadMapi( void);
|
||||
|
||||
static HINSTANCE m_hMapi32;
|
||||
|
||||
static void MAPIUninitialize( void);
|
||||
static HRESULT MAPIInitialize( LPVOID lpInit);
|
||||
static SCODE MAPIAllocateBuffer( ULONG cbSize, LPVOID FAR * lppBuffer);
|
||||
static ULONG MAPIFreeBuffer( LPVOID lpBuff);
|
||||
static HRESULT MAPILogonEx( ULONG ulUIParam, LPTSTR lpszProfileName, LPTSTR lpszPassword, FLAGS flFlags, LPMAPISESSION FAR * lppSession);
|
||||
static HRESULT OpenStreamOnFile( LPALLOCATEBUFFER lpAllocateBuffer, LPFREEBUFFER lpFreeBuffer, ULONG ulFlags, LPTSTR lpszFileName, LPTSTR lpszPrefix, LPSTREAM FAR * lppStream);
|
||||
static void FreeProws( LPSRowSet prows);
|
||||
|
||||
|
||||
BOOL Initialize( void);
|
||||
BOOL LogOn( void);
|
||||
|
||||
void AddMessageStore( CMsgStore *pStore);
|
||||
void SetCurrentMsgStore( LPMDB lpMdb) { m_lpMdb = lpMdb;}
|
||||
|
||||
// Open any given entry from the current Message Store
|
||||
BOOL OpenEntry( ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
static BOOL OpenMdbEntry( LPMDB lpMdb, ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
|
||||
// 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
|
||||
BOOL IterateStores( CMapiFolderList& list);
|
||||
BOOL IterateContents( CMapiContentIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
BOOL IterateHierarchy( CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
|
||||
// Properties
|
||||
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 GetLargeStringProperty( LPMAPIPROP pProp, ULONG tag, nsString& val);
|
||||
static BOOL IsLargeProperty( LPSPropValue pVal);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void ListProperties( LPMAPIPROP lpProp, BOOL getValues = TRUE);
|
||||
static void ListPropertyValue( LPSPropValue pVal, nsCString& s);
|
||||
|
||||
protected:
|
||||
BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
BOOL HandleContentsItem( ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
void GetStoreInfo( CMapiFolder *pFolder, long *pSzContents);
|
||||
|
||||
// array of available message stores, cached so that
|
||||
// message stores are only opened once, preventing multiple
|
||||
// logon's by the user if the store requires a logon.
|
||||
CMsgStore * FindMessageStore( ULONG cbEid, LPENTRYID lpEid);
|
||||
void ClearMessageStores( void);
|
||||
|
||||
static void CStrToUnicode( const char *pStr, nsString& result);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void GetPropTagName( ULONG tag, nsCString& s);
|
||||
static void ReportStringProp( const char *pTag, LPSPropValue pVal);
|
||||
static void ReportUIDProp( const char *pTag, LPSPropValue pVal);
|
||||
static void ReportLongProp( const char *pTag, LPSPropValue pVal);
|
||||
|
||||
|
||||
private:
|
||||
static int m_clients;
|
||||
static BOOL m_initialized;
|
||||
static nsVoidArray * m_pStores;
|
||||
static LPMAPISESSION m_lpSession;
|
||||
static LPMDB m_lpMdb;
|
||||
static HRESULT m_lastError;
|
||||
static PRUnichar * m_pUniBuff;
|
||||
static int m_uniBuffLen;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class CMapiFolder {
|
||||
@ -119,97 +219,6 @@ private:
|
||||
LPMDB m_lpMdb;
|
||||
};
|
||||
|
||||
class CMapiContentIter {
|
||||
public:
|
||||
virtual BOOL HandleContentItem( ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiHierarchyIter {
|
||||
public:
|
||||
virtual BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry) = 0;
|
||||
};
|
||||
|
||||
class CMapiApi {
|
||||
public:
|
||||
CMapiApi();
|
||||
~CMapiApi();
|
||||
|
||||
static BOOL LoadMapi( void);
|
||||
static BOOL LoadMapiEntryPoints( void);
|
||||
static void UnloadMapi( void);
|
||||
|
||||
static HINSTANCE m_hMapi32;
|
||||
|
||||
static void MAPIUninitialize( void);
|
||||
static HRESULT MAPIInitialize( LPVOID lpInit);
|
||||
static SCODE MAPIAllocateBuffer( ULONG cbSize, LPVOID FAR * lppBuffer);
|
||||
static ULONG MAPIFreeBuffer( LPVOID lpBuff);
|
||||
static HRESULT MAPILogonEx( ULONG ulUIParam, LPTSTR lpszProfileName, LPTSTR lpszPassword, FLAGS flFlags, LPMAPISESSION FAR * lppSession);
|
||||
static HRESULT OpenStreamOnFile( LPALLOCATEBUFFER lpAllocateBuffer, LPFREEBUFFER lpFreeBuffer, ULONG ulFlags, LPTSTR lpszFileName, LPTSTR lpszPrefix, LPSTREAM FAR * lppStream);
|
||||
static void FreeProws( LPSRowSet prows);
|
||||
|
||||
|
||||
BOOL Initialize( void);
|
||||
BOOL LogOn( void);
|
||||
|
||||
void AddMessageStore( CMsgStore *pStore);
|
||||
void SetCurrentMsgStore( LPMDB lpMdb) { m_lpMdb = lpMdb;}
|
||||
|
||||
// Open any given entry from the current Message Store
|
||||
BOOL OpenEntry( ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
static BOOL OpenMdbEntry( LPMDB lpMdb, ULONG cbEntry, LPENTRYID pEntryId, LPUNKNOWN *ppOpen);
|
||||
|
||||
// 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
|
||||
BOOL IterateStores( CMapiFolderList& list);
|
||||
BOOL IterateContents( CMapiContentIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
BOOL IterateHierarchy( CMapiHierarchyIter *pIter, LPMAPIFOLDER pFolder, ULONG flags = 0);
|
||||
|
||||
// Properties
|
||||
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);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void ListProperties( LPMAPIPROP lpProp, BOOL getValues = TRUE);
|
||||
static void ListPropertyValue( LPSPropValue pVal, nsCString& s);
|
||||
|
||||
protected:
|
||||
BOOL HandleHierarchyItem( ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
BOOL HandleContentsItem( ULONG oType, ULONG cb, LPENTRYID pEntry);
|
||||
void GetStoreInfo( CMapiFolder *pFolder, long *pSzContents);
|
||||
|
||||
// array of available message stores, cached so that
|
||||
// message stores are only opened once, preventing multiple
|
||||
// logon's by the user if the store requires a logon.
|
||||
CMsgStore * FindMessageStore( ULONG cbEid, LPENTRYID lpEid);
|
||||
void ClearMessageStores( void);
|
||||
|
||||
// Debugging & reporting stuff
|
||||
static void GetPropTagName( ULONG tag, nsCString& s);
|
||||
static void ReportStringProp( const char *pTag, LPSPropValue pVal);
|
||||
static void ReportUIDProp( const char *pTag, LPSPropValue pVal);
|
||||
static void ReportLongProp( const char *pTag, LPSPropValue pVal);
|
||||
|
||||
|
||||
private:
|
||||
static int m_clients;
|
||||
static BOOL m_initialized;
|
||||
static nsVoidArray * m_pStores;
|
||||
static LPMAPISESSION m_lpSession;
|
||||
static LPMDB m_lpMdb;
|
||||
static HRESULT m_lastError;
|
||||
};
|
||||
|
||||
|
||||
class CMapiFolderContents {
|
||||
public:
|
||||
|
@ -903,7 +903,7 @@ nsresult nsOutlookMail::ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, con
|
||||
LPMESSAGE lpMsg;
|
||||
nsCString type;
|
||||
LPSPropValue pVal;
|
||||
nsCString subject;
|
||||
nsString subject;
|
||||
|
||||
while (!done) {
|
||||
(*pCount)++;
|
||||
@ -941,7 +941,7 @@ nsresult nsOutlookMail::ImportAddresses( PRUint32 *pCount, PRUint32 *pTotal, con
|
||||
// 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)) {
|
||||
if (BuildCard( subject.GetUnicode(), pDb, newRow, lpMsg, pFieldMap)) {
|
||||
pDb->AddCardRowToDB( newRow);
|
||||
}
|
||||
}
|
||||
@ -986,7 +986,7 @@ void nsOutlookMail::SplitString( nsString& val1, nsString& val2)
|
||||
}
|
||||
}
|
||||
|
||||
PRBool nsOutlookMail::BuildCard( const char *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap)
|
||||
PRBool nsOutlookMail::BuildCard( const PRUnichar *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap)
|
||||
{
|
||||
|
||||
nsString lastName;
|
||||
@ -1023,16 +1023,7 @@ PRBool nsOutlookMail::BuildCard( const char *pName, nsIAddrDatabase *pDb, nsIMdb
|
||||
}
|
||||
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);
|
||||
|
@ -63,7 +63,7 @@ private:
|
||||
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);
|
||||
PRBool BuildCard( const PRUnichar *pName, nsIAddrDatabase *pDb, nsIMdbRow *newRow, LPMAPIPROP pUser, nsIImportFieldMap *pFieldMap);
|
||||
|
||||
private:
|
||||
PRBool m_gotFolders;
|
||||
|
@ -142,6 +142,9 @@ NS_IMETHODIMP nsOutlookSettings::Import(nsIMsgAccount **localMailAccount, PRBool
|
||||
HKEY OutlookSettings::FindAccountsKey( void)
|
||||
{
|
||||
HKEY sKey;
|
||||
if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\OMI Account Manager\\Accounts", 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &sKey) == ERROR_SUCCESS) {
|
||||
return( sKey);
|
||||
}
|
||||
if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager\\Accounts", 0, KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS, &sKey) == ERROR_SUCCESS) {
|
||||
return( sKey);
|
||||
}
|
||||
@ -165,11 +168,15 @@ PRBool OutlookSettings::DoImport( nsIMsgAccount **ppAccount)
|
||||
return( PR_FALSE);
|
||||
}
|
||||
|
||||
HKEY subKey;
|
||||
HKEY subKey = NULL;
|
||||
nsCString defMailName;
|
||||
|
||||
// First let's get the default mail account key name
|
||||
if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager", 0, KEY_QUERY_VALUE, &subKey) == ERROR_SUCCESS) {
|
||||
if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\Outlook\\OMI Account Manager", 0, KEY_QUERY_VALUE, &subKey) != ERROR_SUCCESS)
|
||||
if (::RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\Microsoft\\Office\\8.0\\Outlook\\OMI Account Manager", 0, KEY_QUERY_VALUE, &subKey) != ERROR_SUCCESS)
|
||||
subKey = NULL;
|
||||
|
||||
if (subKey != NULL) {
|
||||
// First let's get the default mail account key name
|
||||
BYTE * pBytes = nsOutlookRegUtil::GetValueBytes( subKey, "Default Mail Account");
|
||||
::RegCloseKey( subKey);
|
||||
if (pBytes) {
|
||||
|
@ -28,12 +28,19 @@
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
#include "nsString.h"
|
||||
%}
|
||||
|
||||
|
||||
interface nsIImportModule;
|
||||
interface nsIImportMailboxDescriptor;
|
||||
interface nsIImportABDescriptor;
|
||||
interface nsIImportGeneric;
|
||||
interface nsIImportFieldMap;
|
||||
|
||||
[ref] native nsStringRef(nsString);
|
||||
|
||||
[scriptable, uuid(50d7ea80-1726-11d3-a206-00a0cc26da63)]
|
||||
interface nsIImportService : nsISupports
|
||||
{
|
||||
@ -51,6 +58,9 @@ interface nsIImportService : nsISupports
|
||||
nsIImportABDescriptor CreateNewABDescriptor();
|
||||
nsIImportGeneric CreateNewGenericMail();
|
||||
nsIImportGeneric CreateNewGenericAddressBooks();
|
||||
|
||||
[noscript] void SystemStringToUnicode( in string sysStr, in nsStringRef uniStr);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -26,7 +26,7 @@ var fieldMap = null;
|
||||
function OnLoadFieldMapExport()
|
||||
{
|
||||
// top.bundle = srGetStrBundle("chrome://messenger/locale/importMsgs.properties");
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].createInstance();
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].getService();
|
||||
top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
|
||||
|
||||
// We need a field map object...
|
||||
|
@ -9,7 +9,7 @@ var dialogResult = null;
|
||||
function OnLoadFieldMapImport()
|
||||
{
|
||||
// top.bundle = srGetStrBundle("chrome://messenger/locale/importMsgs.properties");
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].createInstance();
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].getService();
|
||||
top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
|
||||
top.transferType = "moz/fieldmap";
|
||||
top.recordNum = 0;
|
||||
|
@ -41,7 +41,7 @@ function GetBundleString( strId)
|
||||
function OnLoadImportDialog()
|
||||
{
|
||||
top.bundle = srGetStrBundle("chrome://messenger/locale/importMsgs.properties");
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].createInstance();
|
||||
top.importService = Components.classes["component://mozilla/import/import-service"].getService();
|
||||
top.importService = top.importService.QueryInterface(Components.interfaces.nsIImportService);
|
||||
|
||||
top.progressInfo = new Object();
|
||||
|
@ -913,6 +913,8 @@ ImportMailThread( void *stuff)
|
||||
|
||||
pData->currentSize = 0;
|
||||
pData->currentTotal += size;
|
||||
|
||||
outBox->CloseStream();
|
||||
|
||||
if (fatalError) {
|
||||
IMPORT_LOG1( "*** ImportMailbox returned fatalError, mailbox #%d\n", (int) i);
|
||||
|
@ -22,7 +22,12 @@
|
||||
*/
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsICharsetAlias.h"
|
||||
#include "nsIPlatformCharset.h"
|
||||
#undef NS_IMPL_IDS
|
||||
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIComponentManager.h"
|
||||
@ -47,6 +52,7 @@
|
||||
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
static NS_DEFINE_IID(kImportModuleIID, NS_IIMPORTMODULE_IID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
|
||||
|
||||
static nsIImportService * gImportService = nsnull;
|
||||
@ -61,46 +67,11 @@ class nsImportService : public nsIImportService
|
||||
public:
|
||||
|
||||
nsImportService();
|
||||
virtual ~nsImportService();
|
||||
~nsImportService();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/* void DiscoverModules (); */
|
||||
NS_IMETHOD DiscoverModules(void);
|
||||
|
||||
/* long GetModuleCount (in string filter); */
|
||||
NS_IMETHOD GetModuleCount(const char *filter, PRInt32 *_retval);
|
||||
|
||||
/* void GetModuleInfo (in string filter, in long index, out string name, out string description); */
|
||||
NS_IMETHOD GetModuleInfo(const char *filter, PRInt32 index, PRUnichar **name, PRUnichar **description);
|
||||
|
||||
/* wstring GetModuleName (in string filter, in long index); */
|
||||
NS_IMETHOD GetModuleName(const char *filter, PRInt32 index, PRUnichar **_retval);
|
||||
|
||||
/* wstring GetModuleDescription (in string filter, in long index); */
|
||||
NS_IMETHOD GetModuleDescription(const char *filter, PRInt32 index, PRUnichar **_retval);
|
||||
|
||||
/* nsIImportModule GetModule (in string filter, in long index); */
|
||||
NS_IMETHOD GetModule(const char *filter, PRInt32 index, nsIImportModule **_retval);
|
||||
|
||||
/* nsIImportModule GetModuleWithCID (in nsCIDRef cid); */
|
||||
NS_IMETHOD GetModuleWithCID(const nsCID & cid, nsIImportModule **_retval);
|
||||
|
||||
/* nsIImportFieldMap CreateNewFieldMap (); */
|
||||
NS_IMETHOD CreateNewFieldMap(nsIImportFieldMap **_retval);
|
||||
|
||||
/* nsIImportMailboxDescriptor CreateNewMailboxDescriptor (); */
|
||||
NS_IMETHOD CreateNewMailboxDescriptor(nsIImportMailboxDescriptor **_retval);
|
||||
|
||||
/* nsIImportABDescriptor CreateNewABDescriptor (); */
|
||||
NS_IMETHOD CreateNewABDescriptor(nsIImportABDescriptor **_retval);
|
||||
|
||||
/* nsIImportGeneric CreateNewGenericMail (); */
|
||||
NS_IMETHOD CreateNewGenericMail(nsIImportGeneric **_retval);
|
||||
|
||||
/* nsIImportGeneric CreateNewGenericAddressBooks (); */
|
||||
NS_IMETHOD CreateNewGenericAddressBooks(nsIImportGeneric **_retval);
|
||||
|
||||
NS_DECL_NSIIMPORTSERVICE
|
||||
|
||||
private:
|
||||
nsresult LoadModuleInfo( const char *pClsId, const char *pSupports);
|
||||
@ -109,6 +80,8 @@ private:
|
||||
private:
|
||||
nsImportModuleList * m_pModules;
|
||||
PRBool m_didDiscovery;
|
||||
nsString m_sysCharset;
|
||||
nsIUnicodeDecoder * m_pDecoder;
|
||||
};
|
||||
|
||||
// extern nsresult NS_NewImportService(nsIImportService** aImportService);
|
||||
@ -204,11 +177,20 @@ nsImportService::nsImportService() : m_pModules( nsnull)
|
||||
IMPORT_LOG0( "* nsImport Service Created\n");
|
||||
|
||||
m_didDiscovery = PR_FALSE;
|
||||
m_pDecoder = nsnull;
|
||||
|
||||
// Go ahead an initialize the charset converter to avoid any
|
||||
// thread issues later.
|
||||
nsString str;
|
||||
SystemStringToUnicode( "Dummy", str);
|
||||
}
|
||||
|
||||
|
||||
nsImportService::~nsImportService()
|
||||
{
|
||||
if (m_pDecoder)
|
||||
NS_RELEASE( m_pDecoder);
|
||||
|
||||
gImportService = nsnull;
|
||||
|
||||
if (m_pModules != nsnull)
|
||||
@ -250,6 +232,90 @@ NS_IMETHODIMP nsImportService::CreateNewABDescriptor(nsIImportABDescriptor **_re
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsImportService::SystemStringToUnicode(const char *sysStr, nsString & uniStr)
|
||||
{
|
||||
|
||||
nsresult rv;
|
||||
if (m_sysCharset.IsEmpty()) {
|
||||
nsCOMPtr <nsIPlatformCharset> platformCharset = do_GetService(NS_PLATFORMCHARSET_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
rv = platformCharset->GetCharset(kPlatformCharsetSel_FileName, m_sysCharset);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
m_sysCharset.Assign("ISO-8859-1");
|
||||
}
|
||||
|
||||
if (!sysStr) {
|
||||
uniStr.Truncate();
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
if (*sysStr == '\0') {
|
||||
uniStr.Truncate();
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
|
||||
if (m_sysCharset.IsEmpty() ||
|
||||
m_sysCharset.EqualsIgnoreCase("us-ascii") ||
|
||||
m_sysCharset.EqualsIgnoreCase("ISO-8859-1")) {
|
||||
uniStr.Assign( sysStr);
|
||||
return( NS_OK);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (!m_pDecoder) {
|
||||
nsAutoString convCharset;
|
||||
|
||||
// Resolve charset alias
|
||||
NS_WITH_SERVICE( nsICharsetAlias, calias, kCharsetAliasCID, &rv);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
nsAutoString aAlias( m_sysCharset);
|
||||
if (aAlias.Length()) {
|
||||
rv = calias->GetPreferred( aAlias, convCharset);
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED( rv)) {
|
||||
IMPORT_LOG0( "*** Error getting charset alias to convert to uinicode\n");
|
||||
uniStr.Assign( sysStr);
|
||||
return( rv);
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE( nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED( rv) && (nsnull != ccm)) {
|
||||
// get an unicode converter
|
||||
rv = ccm->GetUnicodeDecoder( &convCharset, &m_pDecoder);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_pDecoder) {
|
||||
PRInt32 srcLen = PL_strlen( sysStr);
|
||||
PRUnichar * unichars;
|
||||
PRInt32 unicharLength = 0;
|
||||
rv = m_pDecoder->GetMaxLength( sysStr, srcLen, &unicharLength);
|
||||
// allocale an output buffer
|
||||
unichars = (PRUnichar *) PR_Malloc(unicharLength * sizeof(PRUnichar));
|
||||
if (unichars != nsnull) {
|
||||
// convert to unicode
|
||||
rv = m_pDecoder->Convert( sysStr, &srcLen, unichars, &unicharLength);
|
||||
uniStr.Assign(unichars, unicharLength);
|
||||
PR_Free(unichars);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
if (NS_FAILED( rv))
|
||||
uniStr.Assign( sysStr);
|
||||
|
||||
return( rv);
|
||||
}
|
||||
|
||||
|
||||
extern nsresult NS_NewGenericMail(nsIImportGeneric** aImportGeneric);
|
||||
|
||||
NS_IMETHODIMP nsImportService::CreateNewGenericMail(nsIImportGeneric **_retval)
|
||||
|
@ -16,15 +16,17 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsTextAddress.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIImportService.h"
|
||||
#include "nsIAddrDatabase.h"
|
||||
#include "nsAbBaseCID.h"
|
||||
#include "nsIAbCard.h"
|
||||
|
||||
static NS_DEFINE_CID(kAbCardCID, NS_ABCARD_CID);
|
||||
static NS_DEFINE_CID(kAbCardPropertyCID, NS_ABCARDPROPERTY_CID);
|
||||
static NS_DEFINE_CID(kImportServiceCID, NS_IMPORTSERVICE_CID);
|
||||
|
||||
#include "TextDebugLog.h"
|
||||
|
||||
@ -54,6 +56,18 @@ nsTextAddress::~nsTextAddress()
|
||||
}
|
||||
|
||||
|
||||
void nsTextAddress::ConvertToUnicode( const char *pStr, nsString& str)
|
||||
{
|
||||
if (!m_pService) {
|
||||
m_pService = do_GetService( kImportServiceCID);
|
||||
}
|
||||
if (m_pService) {
|
||||
m_pService->SystemStringToUnicode( pStr, str);
|
||||
}
|
||||
else
|
||||
str.Assign( pStr);
|
||||
}
|
||||
|
||||
nsresult nsTextAddress::ImportLDIF( PRBool *pAbort, const PRUnichar *pName, nsIFileSpec *pSrc, nsIAddrDatabase *pDb, nsString& errors)
|
||||
{
|
||||
NS_IF_RELEASE( m_database);
|
||||
@ -489,7 +503,7 @@ nsresult nsTextAddress::ProcessLine( const char *pLine, PRInt32 len, nsString& e
|
||||
}
|
||||
}
|
||||
if (newRow) {
|
||||
uVal = (const char *)fieldVal;
|
||||
ConvertToUnicode( fieldVal, uVal);
|
||||
rv = m_fieldMap->SetFieldValue( m_database, newRow, fieldNum, uVal.GetUnicode());
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,13 @@
|
||||
#define nsTextAddress_h__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsIFileSpec.h"
|
||||
#include "nsISupportsArray.h"
|
||||
#include "nsIImportFieldMap.h"
|
||||
|
||||
#include "nsIImportService.h"
|
||||
|
||||
class nsIAddrDatabase;
|
||||
class nsIMdbRow;
|
||||
@ -53,6 +54,7 @@ public:
|
||||
|
||||
private:
|
||||
nsresult ProcessLine( const char *pLine, PRInt32 len, nsString& errors);
|
||||
void ConvertToUnicode( const char *pStr, nsString& str);
|
||||
|
||||
static PRBool IsLineComplete( const char *pLine, PRInt32 len, char delim);
|
||||
static PRInt32 CountFields( const char *pLine, PRInt32 maxLen, char delim);
|
||||
@ -72,6 +74,7 @@ private:
|
||||
char m_delim;
|
||||
nsIAddrDatabase * m_database;
|
||||
nsIImportFieldMap * m_fieldMap;
|
||||
nsCOMPtr<nsIImportService> m_pService;
|
||||
};
|
||||
|
||||
|
||||
|
@ -624,17 +624,25 @@ NS_IMETHODIMP ImportAddressImpl::GetSampleData( PRInt32 index, PRBool *pFound, P
|
||||
PRInt32 lineLen;
|
||||
PRInt32 bufSz = 10240;
|
||||
char *pLine = new char[bufSz];
|
||||
|
||||
NS_WITH_SERVICE( nsIImportService, impSvc, kImportServiceCID, &rv);
|
||||
|
||||
rv = nsTextAddress::ReadRecordNumber( m_fileLoc, pLine, bufSz, m_delim, &lineLen, index);
|
||||
if (NS_SUCCEEDED( rv)) {
|
||||
nsString str;
|
||||
nsCString field;
|
||||
nsString uField;
|
||||
PRInt32 fNum = 0;
|
||||
while (nsTextAddress::GetField( pLine, lineLen, fNum, field, m_delim)) {
|
||||
if (fNum)
|
||||
str.Append( "\n");
|
||||
SanitizeSampleData( field);
|
||||
str.Append( field);
|
||||
if (impSvc)
|
||||
impSvc->SystemStringToUnicode( field, uField);
|
||||
else
|
||||
uField.Assign( field);
|
||||
|
||||
str.Append( uField);
|
||||
fNum++;
|
||||
field.Truncate();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user