IMPORT_LOG0("****** CREATED NEW FOLDER FOR IMPORT\n");
IMPORT_LOG1("Folder '%s' created successfully\n", NS_ConvertUCS2toUTF8(folderName).get());
PRBool nsImportGenericMail::CreateFolder( nsIMsgFolder **ppFolder){  nsresult rv;  *ppFolder = nsnull;  nsCOMPtr<nsIStringBundle> bundle;  nsCOMPtr<nsIStringBundleService> bundleService(do_GetService(                                     NS_STRINGBUNDLE_CONTRACTID, &rv));  if (NS_FAILED(rv) || !bundleService)       return PR_FALSE;  rv = bundleService->CreateBundle(IMPORT_MSGS_URL, getter_AddRefs(bundle));  if (NS_FAILED(rv))       return PR_FALSE;  nsXPIDLString folderName;  if (!m_pName.IsEmpty()) {    const PRUnichar *moduleName[] = { m_pName.get() };    rv = bundle->FormatStringFromName(NS_LITERAL_STRING("ModuleFolderName").get(),                                      moduleName, 1,                                      getter_Copies(folderName));  }  else {    rv = bundle->GetStringFromName(NS_LITERAL_STRING("DefaultFolderName").get(),                                   getter_Copies(folderName));  }  if (NS_FAILED(rv)) {      IMPORT_LOG0( "*** Failed to get Folder Name!\n");      return PR_FALSE;  }  nsCOMPtr <nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv);  if (NS_FAILED(rv)) {    IMPORT_LOG0( "*** Failed to create account manager!\n");    return PR_FALSE;  }  nsCOMPtr <nsIMsgIncomingServer> server;  rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server));   // if Local Folders does not exist already, create it  if (NS_FAILED(rv) || !server)  {    nsCOMPtr <nsIMessengerMigrator> messengerMigrator = do_GetService(NS_MESSENGERMIGRATOR_CONTRACTID, &rv);    if (NS_FAILED(rv)) {      IMPORT_LOG0( "*** Failed to create messenger migrator!\n");      return PR_FALSE;    }    rv = messengerMigrator->CreateLocalMailAccount(PR_FALSE);    if (NS_FAILED(rv)) {      IMPORT_LOG0( "*** Failed to create Local Folders!\n");      return PR_FALSE;    }    rv = accMgr->GetLocalFoldersServer(getter_AddRefs(server));   }  if (NS_SUCCEEDED(rv) && server) {    nsCOMPtr <nsIMsgFolder> localRootFolder;    rv = server->GetRootMsgFolder(getter_AddRefs(localRootFolder));     if (localRootFolder) {      // we need to call GetSubFolders() so that the folders get initialized       // if they are not initialized yet.       nsCOMPtr <nsIEnumerator> aEnumerator;      rv = localRootFolder->GetSubFolders(getter_AddRefs(aEnumerator));      if (NS_SUCCEEDED(rv)) {        // check if the folder name we picked already exists.        PRBool exists = PR_FALSE;        rv = localRootFolder->ContainsChildNamed(folderName.get(), &exists);        if (exists) {          nsXPIDLString name;          localRootFolder->GenerateUniqueSubfolderName(folderName.get(), nsnull, getter_Copies(name));          if (!name.IsEmpty())            folderName.Assign(name);          else {            IMPORT_LOG0( "*** Failed to find a unique folder name!\n");            return PR_FALSE;          }        }        IMPORT_LOG1( "* Creating folder for importing mail: %s\n", folderName.get());        rv = localRootFolder->CreateSubfolder(folderName.get(), nsnull);        if (NS_SUCCEEDED(rv)) {          nsCOMPtr<nsISupports> subFolder;          rv = localRootFolder->GetChildNamed(folderName.get(), getter_AddRefs(subFolder));          if (subFolder) {            subFolder->QueryInterface(NS_GET_IID(nsIMsgFolder), (void **) ppFolder);            if (*ppFolder) {              IMPORT_LOG0("****** CREATED NEW FOLDER FOR IMPORT\n");              return PR_TRUE;            }          } // if subFolder        }      }    } // if localRootFolder  } // if server  IMPORT_LOG0("****** FAILED TO CREATE FOLDER FOR IMPORT\n");  return PR_FALSE;}