do some clean up in preperation of migrating the fcc prefs. (for bug #10583)

change the newsrcFilePath attribute to be a nsIFileSpec, instead of a string.(bug #13306)
add code to do hashing of hostname. [not turned on yet].  (for bug #13480)
remove the obsolete GetRootFolderPath() code from the incoming servers.
This commit is contained in:
sspitzer%netscape.com 1999-09-09 21:17:32 +00:00
parent 0283a98cb6
commit 8457354b34
9 changed files with 233 additions and 165 deletions

View File

@ -96,6 +96,7 @@ static NS_DEFINE_CID(kCNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
#define PREF_4X_MAIL_SMTP_NAME "mail.smtp_name"
#define PREF_4X_MAIL_SERVER_TYPE "mail.server_type"
#define PREF_4X_NETWORK_HOSTS_IMAP_SERVER "network.hosts.imap_servers"
#define PREF_4X_MAIL_USE_IMAP_SENTMAIL "mail.imap_sentmail_path"
#ifdef DEBUG_seth
#define DEBUG_CLEAR_PREF 1
@ -303,6 +304,7 @@ private:
static PRBool writeFolderCache(nsHashKey *aKey, void *aData, void *closure);
// methods for migration / upgrading
nsresult MigrateIdentity(nsIMsgIdentity *identity);
nsresult CopyIdentity(nsIMsgIdentity *srcIdentity, nsIMsgIdentity *destIdentity);
nsresult MigrateImapAccounts(nsIMsgIdentity *identity);
@ -316,8 +318,8 @@ private:
nsresult MigrateAndClearOldPopPrefs(nsIMsgIncomingServer *server, const char *hostname);
nsresult MigrateNewsAccounts(nsIMsgIdentity *identity);
nsresult MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostname, const char *newsrcfile, nsFileSpec &newsHostsDir);
nsresult MigrateAndClearOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostname, const char *newsrcfile);
nsresult MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostname, nsFileSpec &newsrcfile, nsFileSpec &newsHostsDir);
nsresult MigrateAndClearOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostname, nsFileSpec &newsrcfile);
nsresult SetServerRootPref(const char *pref_name, nsFileSpec & dir);
static char *getUniqueKey(const char* prefix, nsHashtable *hashTable);
@ -1084,8 +1086,6 @@ nsMsgAccountManager::UpgradePrefs()
{
nsresult rv;
PRInt32 oldMailType;
char *oldStr = nsnull;
PRBool oldBool;
rv = getPrefService();
if (NS_FAILED(rv)) return rv;
@ -1106,111 +1106,8 @@ nsMsgAccountManager::UpgradePrefs()
rv = createKeyedIdentity("identity1", getter_AddRefs(identity));
if (NS_FAILED(rv)) return rv;
// identity stuff
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_USEREMAIL, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetEmail(oldStr);
}
else {
identity->SetEmail("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_USEREMAIL);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_USERNAME, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetFullName(oldStr);
}
else {
identity->SetFullName("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_USERNAME);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_REPLY_TO, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetReplyTo(oldStr);
}
else {
identity->SetReplyTo("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_REPLY_TO);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_ORGANIZATION, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetOrganization(oldStr);
}
else {
identity->SetOrganization("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_ORGANIZATION);
#endif
}
rv = m_prefs->GetBoolPref(PREF_4X_MAIL_COMPOSE_HTML, &oldBool);
if (NS_SUCCEEDED(rv)) {
identity->SetComposeHtml(oldBool);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_COMPOSE_HTML);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_SMTP_SERVER, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetSmtpHostname(oldStr);
}
else {
identity->SetSmtpHostname("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_NETWORK_HOSTS_SMTP_SERVER);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_SMTP_NAME, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetSmtpUsername(oldStr);
}
else {
identity->SetSmtpUsername("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_SMTP_NAME);
#endif
}
rv = MigrateIdentity(identity);
if (NS_FAILED(rv)) return rv;
if ( oldMailType == 0) { // POP
rv = MigratePopAccounts(identity);
@ -1238,6 +1135,131 @@ nsMsgAccountManager::UpgradePrefs()
return NS_OK;
}
nsresult
nsMsgAccountManager::MigrateIdentity(nsIMsgIdentity *identity)
{
nsresult rv;
char *oldStr = nsnull;
PRBool oldBool;
// identity stuff
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_USEREMAIL, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetEmail(oldStr);
}
else {
identity->SetEmail("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_USEREMAIL);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_USERNAME, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetFullName(oldStr);
}
else {
identity->SetFullName("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_USERNAME);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_REPLY_TO, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetReplyTo(oldStr);
}
else {
identity->SetReplyTo("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_REPLY_TO);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_IDENTITY_ORGANIZATION, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetOrganization(oldStr);
}
else {
identity->SetOrganization("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_IDENTITY_ORGANIZATION);
#endif
}
rv = m_prefs->GetBoolPref(PREF_4X_MAIL_COMPOSE_HTML, &oldBool);
if (NS_SUCCEEDED(rv)) {
identity->SetComposeHtml(oldBool);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_COMPOSE_HTML);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_NETWORK_HOSTS_SMTP_SERVER, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetSmtpHostname(oldStr);
}
else {
identity->SetSmtpHostname("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_NETWORK_HOSTS_SMTP_SERVER);
#endif
}
rv = m_prefs->CopyCharPref(PREF_4X_MAIL_SMTP_NAME, &oldStr);
if (NS_SUCCEEDED(rv)) {
if (oldStr) {
identity->SetSmtpUsername(oldStr);
}
else {
identity->SetSmtpUsername("");
}
PR_FREEIF(oldStr);
#ifdef DEBUG_CLEAR_PREF
// clear the 4.x pref to avoid confusion
rv = m_prefs->ClearUserPref(PREF_4X_MAIL_SMTP_NAME);
#endif
}
#ifdef NOT_READY_YET
// migrate the mail.default_* and news.default_* prefs
PRBool use_imap_sentmail;
rv = m_prefs->GetBoolPref(PREF_4X_MAIL_USE_IMAP_SENTMAIL, &use_imap_sentmail);
if (use_imap_sentmail) {
}
else {
}
#endif /* 0 */
return NS_OK;
}
nsresult
nsMsgAccountManager::MigrateLocalMailAccounts(nsIMsgIdentity *identity)
{
@ -1918,11 +1940,11 @@ nsMsgAccountManager::MigrateNewsAccounts(nsIMsgIdentity *identity)
}
nsresult
nsMsgAccountManager::MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostname, const char *newsrcfile, nsFileSpec & newsHostsDir)
nsMsgAccountManager::MigrateNewsAccount(nsIMsgIdentity *identity, const char *hostname, nsFileSpec & newsrcfile, nsFileSpec & newsHostsDir)
{
nsresult rv;
nsFileSpec thisNewsHostsDir = newsHostsDir;
if (!newsrcfile) return NS_ERROR_NULL_POINTER;
if (!identity) return NS_ERROR_NULL_POINTER;
if (!hostname) return NS_ERROR_NULL_POINTER;
// create the account
@ -1982,7 +2004,7 @@ nsMsgAccountManager::MigrateNewsAccount(nsIMsgIdentity *identity, const char *ho
}
nsresult
nsMsgAccountManager::MigrateAndClearOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostname, const char *newsrcfile)
nsMsgAccountManager::MigrateAndClearOldNntpPrefs(nsIMsgIncomingServer *server, const char *hostname, nsFileSpec & newsrcfile)
{
nsresult rv;
@ -1999,7 +2021,11 @@ nsMsgAccountManager::MigrateAndClearOldNntpPrefs(nsIMsgIncomingServer *server, c
#endif /* CAN_UPGRADE_4x_PASSWORDS */
#endif /* SUPPORT_SNEWS */
nntpServer->SetNewsrcFilePath((char *)newsrcfile);
nsCOMPtr <nsIFileSpec> path;
rv = NS_NewFileSpecWithSpec(newsrcfile, getter_AddRefs(path));
if (NS_FAILED(rv)) return rv;
nntpServer->SetNewsrcFilePath(path);
return NS_OK;
}

View File

@ -35,6 +35,14 @@
#include "nsIRDFService.h"
#include "nsRDFCID.h"
#ifdef DEBUG_seth
#define DO_HASHING_OF_HOSTNAME 1
#endif
#ifdef DO_HASHING_OF_HOSTNAME
#include "nsMsgUtils.h"
#endif /* DO_HASHING_OF_HOSTNAME */
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
@ -493,8 +501,6 @@ nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
nsresult rv;
rv = GetFileValue("directory", aLocalPath);
if (NS_SUCCEEDED(rv) && *aLocalPath) return rv;
nsXPIDLCString type;
GetType(getter_Copies(type));
@ -512,11 +518,17 @@ nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
rv = GetHostName(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
path->AppendRelativeUnixPath(hostname);
#ifdef DO_HASHING_OF_HOSTNAME
nsCAutoString hashedHostname = "";
hashedHostname += hostname;
NS_MsgHashIfNecessary(hashedHostname);
if (NS_FAILED(rv)) return rv;
path->AppendRelativeUnixPath(hashedHostname);
#else
path->AppendRelativeUnixPath(hostname);
#endif /* DO_HASHING_OF_HOSTNAME */
SetLocalPath(path);
*aLocalPath = path;
NS_ADDREF(*aLocalPath);
@ -530,7 +542,9 @@ nsMsgIncomingServer::SetLocalPath(nsIFileSpec *spec)
spec->CreateDir();
return SetFileValue("directory", spec);
}
return NS_OK;
else {
return NS_ERROR_NULL_POINTER;
}
}
// use the convenience macros to implement the accessors

View File

@ -87,7 +87,6 @@ private:
nsIImapUrl* aImapUrl,
nsIImapProtocol** aImapConnection);
PRBool ConnectionTimeOut(nsIImapProtocol* aImapConnection);
char *m_rootFolderPath;
nsCOMPtr<nsISupportsArray> m_connectionCache;
nsCOMPtr<nsISupportsArray> m_urlQueue;
nsVoidArray m_urlConsumers;
@ -122,7 +121,7 @@ NS_IMETHODIMP nsImapIncomingServer::QueryInterface(REFNSIID aIID, void** aInstan
}
nsImapIncomingServer::nsImapIncomingServer() : m_rootFolderPath(nsnull)
nsImapIncomingServer::nsImapIncomingServer()
{
NS_INIT_REFCNT();
nsresult rv;
@ -133,7 +132,6 @@ nsImapIncomingServer::nsImapIncomingServer() : m_rootFolderPath(nsnull)
nsImapIncomingServer::~nsImapIncomingServer()
{
PR_FREEIF(m_rootFolderPath);
}
NS_IMETHODIMP nsImapIncomingServer::SetKey(char * aKey) // override nsMsgIncomingServer's implementation...

View File

@ -40,14 +40,8 @@ public:
nsNoIncomingServer();
virtual ~nsNoIncomingServer();
NS_IMETHOD GetRootFolderPath(char **);
NS_IMETHOD SetRootFolderPath(char *);
NS_IMETHOD GetServerURI(char * *uri);
NS_IMETHOD GetPrettyName(PRUnichar **retval);
private:
char *m_rootFolderPath;
};
NS_IMPL_ISUPPORTS_INHERITED(nsNoIncomingServer,
@ -56,21 +50,15 @@ NS_IMPL_ISUPPORTS_INHERITED(nsNoIncomingServer,
nsNoIncomingServer::nsNoIncomingServer() :
m_rootFolderPath(0)
nsNoIncomingServer::nsNoIncomingServer()
{
NS_INIT_REFCNT();
}
nsNoIncomingServer::~nsNoIncomingServer()
{
PR_FREEIF(m_rootFolderPath);
}
NS_IMPL_SERVERPREF_STR(nsNoIncomingServer,
RootFolderPath,
"directory")
nsresult
nsNoIncomingServer::GetServerURI(char **uri)
{

View File

@ -17,10 +17,10 @@
*/
#include "nsISupports.idl"
#include "nsIFileSpec.idl"
[scriptable, uuid(21ea0654-f773-11d2-8aec-004005263078)]
interface nsINntpIncomingServer : nsISupports {
attribute string newsrcFilePath;
/* the on-disk path to the newsrc file for this server */
attribute nsIFileSpec newsrcFilePath;
};

View File

@ -139,8 +139,6 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
printf("CreateSubFolders: %s = %s\n", mURI, (const char *)path);
#endif
char *newsrcFilePathStr = nsnull;
//Are we assured this is the server for this folder?
nsCOMPtr<nsIMsgIncomingServer> server;
rv = GetServer(getter_AddRefs(server));
@ -151,19 +149,11 @@ nsMsgNewsFolder::CreateSubFolders(nsFileSpec &path)
getter_AddRefs(nntpServer));
if (NS_FAILED(rv)) return rv;
rv = nntpServer->GetNewsrcFilePath(&newsrcFilePathStr);
nsCOMPtr<nsIFileSpec> newsrcFilePath;
rv = nntpServer->GetNewsrcFilePath(getter_AddRefs(newsrcFilePath));
if (NS_FAILED(rv)) return rv;
nsFileSpec newsrcFile(newsrcFilePathStr);
PR_FREEIF(newsrcFilePathStr);
newsrcFilePathStr = nsnull;
if (NS_SUCCEEDED(rv)) {
#ifdef DEBUG_NEWS
printf("uri = %s newsrc file = %s\n", mURI, (const char *)newsrcFile);
#endif
rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFile);
}
rv = LoadNewsrcFileAndCreateNewsgroups(newsrcFilePath);
}
else {
#ifdef DEBUG_NEWS
@ -1067,10 +1057,10 @@ NS_IMETHODIMP nsMsgNewsFolder::CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr,
}
nsresult
nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile)
nsMsgNewsFolder::LoadNewsrcFileAndCreateNewsgroups(nsIFileSpec * newsrcFile)
{
nsInputFileStream newsrcStream(newsrcFile);
nsresult rv = NS_OK;
nsresult rv = NS_OK;
PRInt32 numread = 0;
if (NS_FAILED(m_inputStream.GrowBuffer(NEWSRC_FILE_BUFFER_SIZE))) {

View File

@ -105,7 +105,7 @@ protected:
//Returns the child as well.
nsresult AddSubfolder(nsAutoString name, nsIMsgFolder **child, char *setStr);
nsresult LoadNewsrcFileAndCreateNewsgroups(nsFileSpec &newsrcFile);
nsresult LoadNewsrcFileAndCreateNewsgroups(nsIFileSpec * newsrcFile);
PRInt32 RememberLine(char *line);
nsresult ForgetLine(void);

View File

@ -18,12 +18,28 @@
#include "nsNntpIncomingServer.h"
#include "nsXPIDLString.h"
#include "nsIPref.h"
#ifdef DEBUG_seth
#define DO_HASHING_OF_HOSTNAME 1
#endif
#ifdef DO_HASHING_OF_HOSTNAME
#include "nsMsgUtils.h"
#endif /* DO_HASHING_OF_HOSTNAME */
#if defined(XP_UNIX) || defined(XP_BEOS)
#define NEWSRC_FILE_PREFIX ".newsrc-"
#else
#define NEWSRC_FILE_PREFIX ""
#endif /* XP_UNIX || XP_BEOS */
static NS_DEFINE_CID(kCPrefServiceCID, NS_PREF_CID);
NS_IMPL_ISUPPORTS_INHERITED(nsNntpIncomingServer,
nsMsgIncomingServer,
nsINntpIncomingServer);
nsNntpIncomingServer::nsNntpIncomingServer()
{
@ -34,13 +50,52 @@ nsNntpIncomingServer::~nsNntpIncomingServer()
{
}
NS_IMPL_SERVERPREF_STR(nsNntpIncomingServer,
RootFolderPath,
"directory")
NS_IMPL_SERVERPREF_STR(nsNntpIncomingServer,
NewsrcFilePath,
"newsrc.file")
NS_IMETHODIMP
nsNntpIncomingServer::GetNewsrcFilePath(nsIFileSpec **aNewsrcFilePath)
{
nsresult rv;
rv = GetFileValue("newsrc.file", aNewsrcFilePath);
if (NS_SUCCEEDED(rv) && *aNewsrcFilePath) return rv;
nsCOMPtr<nsIFileSpec> path;
NS_WITH_SERVICE(nsIPref, prefs, kCPrefServiceCID, &rv);
if (NS_FAILED(rv) || (!prefs)) {
return rv;
}
rv = prefs->GetFilePref("mail.newsrc_root", getter_AddRefs(path));
if (NS_FAILED(rv)) return rv;
nsXPIDLCString hostname;
rv = GetHostName(getter_Copies(hostname));
if (NS_FAILED(rv)) return rv;
nsCAutoString newsrcFileName = NEWSRC_FILE_PREFIX;
newsrcFileName += hostname;
#ifdef DO_HASHING_OF_HOSTNAME
NS_MsgHashIfNecessary(newsrcFileName);
#endif /* DO_HASHING_OF_HOSTNAME */
path->AppendRelativeUnixPath(newsrcFileName);
SetNewsrcFilePath(path);
*aNewsrcFilePath = path;
NS_ADDREF(*aNewsrcFilePath);
return NS_OK;
}
NS_IMETHODIMP
nsNntpIncomingServer::SetNewsrcFilePath(nsIFileSpec *spec)
{
if (spec) {
spec->CreateDir();
return SetFileValue("newsrc.file", spec);
}
else {
return NS_ERROR_FAILURE;
}
}
nsresult
nsNntpIncomingServer::GetServerURI(char **uri)

View File

@ -41,9 +41,6 @@ public:
nsNntpIncomingServer();
virtual ~nsNntpIncomingServer();
NS_IMETHOD GetRootFolderPath(char **);
NS_IMETHOD SetRootFolderPath(char *);
NS_IMETHOD GetServerURI(char * *uri);
};