if (!destDB) { pDestDB->Close( PR_TRUE);
if (!proxyAddrDatabase) { proxyAddrDatabase->Close( PR_TRUE);
PR_STATIC_CALLBACK( void) ImportAddressThread( void *stuff){	IMPORT_LOG0( "In Begin ImportAddressThread\n");	AddressThreadData *pData = (AddressThreadData *)stuff;	PRUint32	count = 0;	nsresult 	rv = pData->books->Count( &count);		nsISupports *				pSupports;	PRUint32					i;	PRBool						import;	PRUint32					size;	nsCOMPtr<nsIAddrDatabase>	destDB( getter_AddRefs( GetAddressBookFromUri( pData->pDestinationUri)));	nsIAddrDatabase *			pDestDB = nsnull;		nsString					success;	nsString					error;	for (i = 0; (i < count) && !(pData->abort); i++) {		pSupports = pData->books->ElementAt( i);		if (pSupports) {			nsCOMPtr<nsISupports> interface( dont_AddRef( pSupports));			nsCOMPtr<nsIImportABDescriptor> book( do_QueryInterface( pSupports));			if (book) {				import = PR_FALSE;				size = 0;				rv = book->GetImport( &import);				if (import)					rv = book->GetSize( &size);								if (size && import) {					PRUnichar *pName;					book->GetPreferredName( &pName);					if (destDB) {						destDB->QueryInterface( NS_GET_IID(nsIAddrDatabase), (void **)&pDestDB);					}					else {						pDestDB = GetAddressBook( pName, PR_TRUE);					}					PRBool fatalError = PR_FALSE;					pData->currentSize = size;					if (pDestDB) {						PRUnichar *pSuccess = nsnull;						PRUnichar *pError = nsnull;						/*						if (pData->fieldMap) {							PRInt32		sz = 0;							PRInt32		mapIndex;							PRBool		active;							pData->fieldMap->GetMapSize( &sz);							IMPORT_LOG1( "**** Field Map Size: %d\n", (int) sz);							for (PRInt32 i = 0; i < sz; i++) {								pData->fieldMap->GetFieldMap( i, &mapIndex);								pData->fieldMap->GetFieldActive( i, &active);								IMPORT_LOG3( "Field map #%d: index=%d, active=%d\n", (int) i, (int) mapIndex, (int) active);							}						}						*/						rv = pData->addressImport->ImportAddressBook(	book, 																	pDestDB, // destination																	pData->fieldMap, // fieldmap													pData->bAddrLocInput,																	&pError,																	&pSuccess,																	&fatalError);						if (pSuccess) {							success.Append( pSuccess);							nsCRT::free( pSuccess);						}						if (pError) {							error.Append( pError);							nsCRT::free( pError);						}					}					else {						nsImportGenericAddressBooks::ReportError( pName, &error);					}					nsCRT::free( pName);					pData->currentSize = 0;					pData->currentTotal += size;										if (!destDB) {						pDestDB->Close( PR_TRUE);					}					NS_IF_RELEASE( pDestDB);					if (fatalError) {						pData->fatalError = PR_TRUE;						break;					}				}			}		}		if (destDB) {			destDB->Close( PR_TRUE);		}	}		nsImportGenericAddressBooks::SetLogs( success, error, pData->successLog, pData->errorLog);	if (pData->abort || pData->fatalError) {		// FIXME: do what is necessary to get rid of what has been imported so far.		// Nothing if we went into an existing address book!  Otherwise, delete		// the ones we created?	}	pData->ThreadDelete();	}