IMPORT_LOG1( "GetChildNamed for new folder returned rv: 0x%lx\n", (long) rv);
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);		PRUint32		i;	PRBool			import;	PRUint32		size;		PRUint32		depth = 1;	PRUint32		newDepth;	nsString		lastName;	PRUnichar *		pName;		nsCOMPtr<nsIMsgFolder>  	curFolder( destRoot);	nsCOMPtr<nsIMsgFolder>		curProxy;	nsCOMPtr<nsIMsgFolder>		newFolder;	nsCOMPtr<nsIFileSpec>  		outBox;	nsCOMPtr<nsISupports>		subFolder;	nsCOMPtr<nsIEnumerator>     enumerator;	PRBool						exists;		nsString	success;	nsString	error;	nsCOMPtr<nsIStringBundle>	bundle( dont_AddRef( nsImportStringBundle::GetStringBundleProxy()));	// Initialize the curFolder proxy object	nsCOMPtr<nsIProxyObjectManager> proxyMgr = 	         do_GetService(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);		if (NS_SUCCEEDED(rv))			// GetSubfolders() will initialize folders if they are not already initialized.			curProxy->GetSubFolders(getter_AddRefs(enumerator));	}	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);  // Note that the front-end js script only displays one import result string so   // we combine both good and bad import status into one string (in var 'success').	for (i = 0; (i < count) && !(pData->abort); i++) {		nsCOMPtr<nsIImportMailboxDescriptor> box =			do_QueryElementAt(pData->boxes, i);		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) {          // OK, we are going to add a subfolder under the last/previous folder we processed, so          // find this folder (stored in 'lastName') who is going to be the new parent folder.				IMPORT_LOG1( "* Finding folder for child named: %s\n", lastName.get());				rv = curProxy->GetChildNamed( lastName.get(), getter_AddRefs( subFolder));				if (NS_FAILED( rv)) {					nsImportGenericMail::ReportError( IMPORT_ERROR_MB_FINDCHILD, lastName.get(), &success);					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;				}				// Make sure this new parent folder obj has the correct subfolder list so far.				rv = curProxy->GetSubFolders(getter_AddRefs(enumerator));				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.Assign(NS_LITERAL_STRING("Unknown!"));							exists = PR_FALSE;			rv = curProxy->ContainsChildNamed( lastName.get(), &exists);			if (exists) {				nsXPIDLString subName;				curProxy->GenerateUniqueSubfolderName( lastName.get(), nsnull, getter_Copies(subName));				if (!subName.IsEmpty()) 					lastName.Assign(subName);			}							IMPORT_LOG1( "* Creating new import folder: %s\n", lastName.get());			rv = curProxy->CreateSubfolder( lastName.get(),nsnull);							IMPORT_LOG1( "New folder created, rv: 0x%lx\n", (long) rv);			if (NS_SUCCEEDED( rv)) {				rv = curProxy->GetChildNamed( lastName.get(), 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.get(), &success);			}			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();          // OK, we've copied the actual folder/file over if the folder size is not 0          // (ie, the msg summary is no longer valid) so close the msg database so that          // when the folder is reopened the folder db can be reconstructed (which          // validates msg summary and forces folder to be reparsed).				newFolder->ForceDBClosed();				if (fatalError) {					IMPORT_LOG1( "*** ImportMailbox returned fatalError, mailbox #%d\n", (int) i);					pData->fatalError = PR_TRUE;					break;				}			}		}	}	// Now save the new acct info to pref file.	nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);        if (NS_SUCCEEDED(rv) && accMgr) {	  rv = accMgr->SaveAccountInfo();	  NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file");	}		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, nsnull);		}		else {			// FIXME: just delete the stuff we created?		}	}	IMPORT_LOG1( "Import mailbox thread done: %d\n", (int) pData->currentTotal);	pData->ThreadDelete();	}