pStr = lastName.ToNewCString();
ConvertFromUnicode(lastName.GetUnicode(), strName);
ImportMailThread( void *stuff){	IMPORT_LOG0( "In Begin ImporMailThread\n");	ImportThreadData *pData = (ImportThreadData *)stuff;		IMPORT_LOG0( "In ImportMailThread!!!!!!!\n");			nsresult rv = NS_OK;	nsCOMPtr<nsIMsgFolder>  	destRoot( pData->destRoot);							PRUint32	count = 0;	rv = pData->boxes->Count( &count);		nsISupports *	pSupports;	PRUint32		i;	PRBool			import;	PRUint32		size;		PRUint32		depth = 1;	PRUint32		newDepth;	nsString		lastName;	PRUnichar *		pName;	char *			pStr;		nsCOMPtr<nsIMsgFolder>  	curFolder( destRoot);	nsCOMPtr<nsIMsgFolder>		curProxy;	nsCOMPtr<nsIMsgFolder>		newFolder;	nsCOMPtr<nsIFileSpec>  		outBox;	nsCOMPtr<nsISupports>		subFolder;	PRBool						exists;		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->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder),										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, bundle);		pData->abort = PR_TRUE;	}	IMPORT_LOG1( "Total number of mailboxes: %d\n", (int) count);	for (i = 0; (i < count) && !(pData->abort); i++) {		pSupports = pData->boxes->ElementAt( i);		if (pSupports) {			nsCOMPtr<nsISupports> iFace( dont_AddRef( pSupports));			nsCOMPtr<nsIImportMailboxDescriptor> box( do_QueryInterface( pSupports));			if (box) {				pData->currentMailbox = i;				import = PR_FALSE;				size = 0;				rv = box->GetImport( &import);				if (import)					rv = box->GetSize( &size);				rv = box->GetDepth( &newDepth);				if (newDepth > depth) {					pStr = lastName.ToNewCString();					IMPORT_LOG1( "* Finding folder for child named: %s\n", pStr);					rv = curProxy->GetChildNamed( pStr, getter_AddRefs( subFolder));					nsCRT::free( pStr);					if (NS_FAILED( rv)) {						nsImportGenericMail::ReportError( IMPORT_ERROR_MB_FINDCHILD, lastName.GetUnicode(), &error);						pData->fatalError = PR_TRUE;						break;					}					rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder), 													subFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy));					if (NS_FAILED( rv)) {						nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle);						pData->fatalError = PR_TRUE;						break;					}					IMPORT_LOG1( "Created proxy for new subFolder: 0x%lx\n", (long) rv);				}				else if (newDepth < depth) {					rv = NS_OK;					while ((newDepth < depth) && NS_SUCCEEDED( rv)) {						nsCOMPtr<nsIFolder> parFolder;						curProxy->GetParent( getter_AddRefs( parFolder));						rv = proxyMgr->GetProxyForObject( NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIMsgFolder),														parFolder, PROXY_SYNC | PROXY_ALWAYS, getter_AddRefs( curProxy));						depth--;					}					if (NS_FAILED( rv)) {						nsImportStringBundle::GetStringByID( IMPORT_ERROR_MB_NOPROXY, error, bundle);						pData->fatalError = PR_TRUE;						break;					}				}				depth = newDepth;				pName = nsnull;				box->GetDisplayName( &pName);				if (pName) {					lastName = pName;					nsCRT::free( pName);				}				else					lastName.AssignWithConversion("Unknown!");								pStr = lastName.ToNewCString();				exists = PR_FALSE;				rv = curProxy->ContainsChildNamed( pStr, &exists);				if (exists) {					char *pSubName = nsnull;					curProxy->GenerateUniqueSubfolderName( pStr, nsnull, &pSubName);					if (pSubName) {						nsCRT::free( pStr);						pStr = pSubName;					}				}				lastName.AssignWithConversion(pStr);								IMPORT_LOG1( "* Creating new import folder: %s\n", pStr);				nsAutoString newName; newName.AssignWithConversion(pStr);				rv = curProxy->CreateSubfolder( newName.GetUnicode(),nsnull);								IMPORT_LOG1( "New folder created, rv: 0x%lx\n", (long) rv);				if (NS_SUCCEEDED( rv)) {					rv = curProxy->GetChildNamed( pStr, getter_AddRefs( subFolder));					IMPORT_LOG1( "GetChildNamed for new folder returned rv: 0x%lx\n", (long) rv);					if (NS_SUCCEEDED( rv)) {						newFolder = do_QueryInterface( subFolder);						if (newFolder) {							newFolder->GetPath( getter_AddRefs( outBox));							IMPORT_LOG0( "Got path for newly created folder\n");						}						else {							IMPORT_LOG0( "Newly created folder not found\n");						}					}				}								if (NS_FAILED( rv)) {					nsImportGenericMail::ReportError( IMPORT_ERROR_MB_CREATE, lastName.GetUnicode(), &error);				}												nsCRT::free( pStr);				if (size && import && newFolder && outBox && NS_SUCCEEDED( rv)) {					PRBool fatalError = PR_FALSE;					pData->currentSize = size;					PRUnichar *pSuccess = nsnull;					PRUnichar *pError = nsnull;					rv = pData->mailImport->ImportMailbox( box, outBox, &pError, &pSuccess, &fatalError);					if (pError) {						error.Append( pError);						nsCRT::free( pError);					}					if (pSuccess) {						success.Append( pSuccess);						nsCRT::free( pSuccess);					}					pData->currentSize = 0;					pData->currentTotal += size;										outBox->CloseStream();					if (fatalError) {						IMPORT_LOG1( "*** ImportMailbox returned fatalError, mailbox #%d\n", (int) i);						pData->fatalError = PR_TRUE;						break;					}				}			}		}	}		nsImportGenericMail::SetLogs( success, error, pData->successLog, pData->errorLog);	if (pData->abort || pData->fatalError) {		IMPORT_LOG0( "Abort or fatalError set\n");		if (pData->ownsDestRoot) {			IMPORT_LOG0( "Calling destRoot->RecursiveDelete\n");			destRoot->RecursiveDelete( PR_TRUE);		}		else {			// FIXME: just delete the stuff we created?		}	}	IMPORT_LOG1( "Import mailbox thread done: %d\n", (int) pData->currentTotal);	pData->ThreadDelete();	}