if (NS_SUCCEEDED(rv) && news_directory_value && (PL_strlen(news_directory_value) > 0)) { newsrcDir = news_directory_value; PR_FREEIF(news_directory_value); } else {  #ifdef XP_UNIX nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::Unix_HomeDirectory); #elif XP_BEOS nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::BeOS_HomeDirectory); #else #error where_are_your_newsrc_files #endif  newsrcDir = homeDir; }
rv = newsDir->GetFileSpec(&newsrcDir); if (NS_FAILED(rv)) return rv;
nsMsgAccountManager::MigrateNewsAccounts(nsIMsgIdentity *identity){	nsresult rv;    nsFileSpec newsrcDir; // the directory that holds the newsrc files (and the fat file, if we are using one)    nsFileSpec newsHostsDir; // the directory that holds the host directory, and the summary files.	nsFileSpec profileDir;    char *news_directory_value = nsnull;    // the host directories will be under <profile dir>/News or    // <"news.directory" pref>/News.    //    // the newsrc file don't necessarily live under there.    //    // if we didn't use the map file (UNIX) then we want to force the newsHostsDir to be    // <profile>/News.  in 4.x, on UNIX, the summary files lived in ~/.netscape/xover-cache/<hostname>    // in 5.0, they will live under <profile>/News/<hostname>, like the other platforms.    // in 4.x, on UNIX, the "news.directory" pref pointed to the directory to where    // the newsrc files lived.  we don't want that for the newsHostsDir.#ifdef USE_NEWSRC_MAP_FILE  // if they used -installer, this pref will point to where their files got copied    rv = m_prefs->CopyCharPref(PREF_NEWS_DIRECTORY, &news_directory_value);#else    rv = NS_ERROR_FAILURE;#endif /* USE_NEWSRC_MAP_FILE */	if (NS_SUCCEEDED(rv) && news_directory_value && (PL_strlen(news_directory_value) > 0)) {      newsHostsDir = news_directory_value;      PR_FREEIF(news_directory_value);    }    else {      NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv);      if (NS_FAILED(rv)) return NS_ERROR_FAILURE;            rv = profile->GetCurrentProfileDir(&profileDir);      if (NS_FAILED(rv)) return NS_ERROR_FAILURE;            newsHostsDir = profileDir;            // we want <profile>/News, not <profile>      newsHostsDir += NEW_NEWS_DIR_NAME;            // create <profile>/News if it doesn't exist      if (!newsHostsDir.Exists()) {		newsHostsDir.CreateDir();      }    }    #ifdef USE_NEWSRC_MAP_FILE	    // if we are using the fat file, it lives in the newsHostsDir.    newsrcDir = newsHostsDir;    // the fat file is really <newsrcDir>/<fat file name>    // example:  News\fat on Windows, News\NewsFAT on the Mac    // don't worry, after we migrate, the fat file is going away    nsFileSpec fatFile(newsrcDir);	fatFile += NEWS_FAT_FILE_NAME;    // for each news server in the fat file call MigrateNewsAccount();	char buffer[512];	char psuedo_name[512];	char filename[512];	char is_newsgroup[512];	PRBool ok;	nsInputFileStream inputStream(fatFile);		if (inputStream.eof()) {		inputStream.close();		return NS_ERROR_FAILURE;	}	    /* we expect the first line to be NEWSRC_MAP_FILE_COOKIE */	ok = inputStream.readline(buffer, sizeof(buffer));	    if ((!ok) || (PL_strncmp(buffer, NEWSRC_MAP_FILE_COOKIE, PL_strlen(NEWSRC_MAP_FILE_COOKIE)))) {		inputStream.close();		return NS_ERROR_FAILURE;	}   		while (!inputStream.eof()) {		char * p;		PRInt32 i;				ok = inputStream.readline(buffer, sizeof(buffer));		if (!ok) {			inputStream.close();			return NS_ERROR_FAILURE;		}  				/* TODO: replace this with nsString code? */		/*		This used to be scanf() call which would incorrectly		parse long filenames with spaces in them.  - JRE		*/				filename[0] = '\0';		is_newsgroup[0]='\0';				for (i = 0, p = buffer; *p && *p != '\t' && i < 500; p++, i++)			psuedo_name[i] = *p;		psuedo_name[i] = '\0';		if (*p) 		{			for (i = 0, p++; *p && *p != '\t' && i < 500; p++, i++)				filename[i] = *p;			filename[i]='\0';			if (*p) 			{				for (i = 0, p++; *p && *p != '\r' && i < 500; p++, i++)					is_newsgroup[i] = *p;				is_newsgroup[i]='\0';			}		}				if(PL_strncmp(is_newsgroup, "TRUE", 4)) {#ifdef NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS			// most likely, the fat file has been copied (or moved ) from			// its old location.  So the absolute file paths will be wrong.			// all we care about is the leaf, so use that.			nsFileSpec oldRcFile(filename);			char *leaf = oldRcFile.GetLeafName();			nsFileSpec rcFile(newsrcDir);			rcFile += leaf;			nsCRT::free(leaf);			leaf = nsnull;#else			nsFileSpec rcFile(newsrcDir);			rcFile += filename;#endif /* NEWS_FAT_STORES_ABSOLUTE_NEWSRC_FILE_PATHS */			// psuedo-name is of the form newsrc-<host> or snewsrc-<host>.  			// right now, we can't handle snewsrc, so if we get one of those			// gracefully handle it by ignoring it.			if (PL_strncmp(PSUEDO_NAME_PREFIX,psuedo_name,PL_strlen(PSUEDO_NAME_PREFIX)) != 0) {				continue;			}			// check that there is a hostname to get after the "newsrc-" part			NS_ASSERTION(PL_strlen(psuedo_name) > PL_strlen(PSUEDO_NAME_PREFIX), "psuedo_name is too short");			if (PL_strlen(psuedo_name) <= PL_strlen(PSUEDO_NAME_PREFIX)) {				return NS_ERROR_FAILURE;			}			char *hostname = psuedo_name + PL_strlen(PSUEDO_NAME_PREFIX);            rv = MigrateNewsAccount(identity, hostname, rcFile, newsHostsDir);            if (NS_FAILED(rv)) {				// failed to migrate.  bail out				return rv;			}		}	}		inputStream.close();#else /* USE_NEWSRC_MAP_FILE */    rv = m_prefs->CopyCharPref(PREF_PREMIGRATION_NEWS_DIRECTORY, &news_directory_value);    if (NS_FAILED(rv) || !news_directory_value || (PL_strlen(news_directory_value) == 0)) {#ifdef DEBUG_ACCOUNTMANAGER      printf("%s was not set, attempting to use %s instead.\n",PREF_PREMIGRATION_NEWS_DIRECTORY,PREF_NEWS_DIRECTORY);#endif      PR_FREEIF(news_directory_value);      rv = m_prefs->CopyCharPref(PREF_NEWS_DIRECTORY, &news_directory_value);    }    	if (NS_SUCCEEDED(rv) && news_directory_value && (PL_strlen(news_directory_value) > 0)) {      newsrcDir = news_directory_value;      PR_FREEIF(news_directory_value);    }    else {      // "news.directory" and "premigration.news.directory" fail, use the home directory.#ifdef XP_UNIX      nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::Unix_HomeDirectory);#elif XP_BEOS      nsSpecialSystemDirectory homeDir(nsSpecialSystemDirectory::BeOS_HomeDirectory);#else#error where_are_your_newsrc_files#endif /* XP_UNIX, XP_BEOS */      newsrcDir = homeDir;	}    for (nsDirectoryIterator i(newsrcDir, PR_FALSE); i.Exists(); i++) {      nsFileSpec possibleRcFile = i.Spec();      char *filename = possibleRcFile.GetLeafName();            if ((PL_strncmp(NEWSRC_FILE_PREFIX, filename, PL_strlen(NEWSRC_FILE_PREFIX)) == 0) && (PL_strlen(filename) > PL_strlen(NEWSRC_FILE_PREFIX))) {#ifdef DEBUG_ACCOUNTMANAGER        printf("found a newsrc file: %s\n", filename);#endif        char *hostname = filename + PL_strlen(NEWSRC_FILE_PREFIX);        rv = MigrateNewsAccount(identity, hostname, possibleRcFile, newsHostsDir);        if (NS_FAILED(rv)) {          // failed to migrate.  bail out          return rv;        }      }      nsCRT::free(filename);      filename = nsnull;    }#endif /* USE_NEWSRC_MAP_FILE */	return NS_OK;}