From 0611ca4bef117cef02a0286f294c3aef2a7ad9ea Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Fri, 11 Feb 2000 00:55:54 +0000 Subject: [PATCH] fix for #26413 - new accounts were picking up old accounts's values, so clear them all out of the prefs r=putterman --- mailnews/base/public/nsIMsgAccount.idl | 2 ++ mailnews/base/public/nsIMsgIdentity.idl | 6 +++++ mailnews/base/public/nsIMsgIncomingServer.idl | 6 +++++ mailnews/base/src/nsMsgAccount.cpp | 18 +++++++++++++ mailnews/base/src/nsMsgAccount.h | 4 ++- mailnews/base/src/nsMsgAccountManager.cpp | 26 +++++++++++++++++++ mailnews/base/util/nsMsgIdentity.cpp | 20 ++++++++++++++ mailnews/base/util/nsMsgIdentity.h | 9 +++---- mailnews/base/util/nsMsgIncomingServer.cpp | 20 ++++++++++++++ mailnews/base/util/nsMsgIncomingServer.h | 2 ++ 10 files changed, 106 insertions(+), 7 deletions(-) diff --git a/mailnews/base/public/nsIMsgAccount.idl b/mailnews/base/public/nsIMsgAccount.idl index 333ce1269c81..9333a1c6a471 100644 --- a/mailnews/base/public/nsIMsgAccount.idl +++ b/mailnews/base/public/nsIMsgAccount.idl @@ -59,6 +59,8 @@ interface nsIMsgAccount : nsISupports { /* remove an identity from this account (probably does not work) */ void removeIdentity(in nsIMsgIdentity identity); + void clearAllValues(); + /* name in javascript */ wstring toString(); }; diff --git a/mailnews/base/public/nsIMsgIdentity.idl b/mailnews/base/public/nsIMsgIdentity.idl index 22497b5401d2..ca0ed3f110ef 100644 --- a/mailnews/base/public/nsIMsgIdentity.idl +++ b/mailnews/base/public/nsIMsgIdentity.idl @@ -93,6 +93,12 @@ interface nsIMsgIdentity : nsISupports { * to ask the user to complete all the fields */ attribute boolean valid; + + /** + * this is really dangerous. this destroys all pref values + * do not call this unless you know what you're doing! + */ + void clearAllValues(); wstring toString(); }; diff --git a/mailnews/base/public/nsIMsgIncomingServer.idl b/mailnews/base/public/nsIMsgIncomingServer.idl index c4b43960400b..59aed953c11c 100644 --- a/mailnews/base/public/nsIMsgIncomingServer.idl +++ b/mailnews/base/public/nsIMsgIncomingServer.idl @@ -139,6 +139,12 @@ interface nsIMsgIncomingServer : nsISupports { nsIFileSpec getFileValue(in string attr); void setFileValue(in string attr, in nsIFileSpec value); + /** + * this is really dangerous. this destroys all pref values + * do not call this unless you know what you're doing! + */ + void clearAllValues(); + attribute boolean valid; wstring toString(); diff --git a/mailnews/base/src/nsMsgAccount.cpp b/mailnews/base/src/nsMsgAccount.cpp index ce29d1063c37..cb2c70319f3f 100644 --- a/mailnews/base/src/nsMsgAccount.cpp +++ b/mailnews/base/src/nsMsgAccount.cpp @@ -354,3 +354,21 @@ nsMsgAccount::ToString(PRUnichar **aResult) } +NS_IMETHODIMP +nsMsgAccount::ClearAllValues() +{ + nsresult rv; + nsCAutoString rootPref("mail.account."); + rootPref += m_accountKey; + + rv = m_prefs->EnumerateChildren(rootPref, clearPrefEnum, (void *)m_prefs); + + return rv; +} + +void +nsMsgAccount::clearPrefEnum(const char *aPref, void *aClosure) +{ + nsIPref *prefs = (nsIPref *)aClosure; + prefs->ClearUserPref(aPref); +} diff --git a/mailnews/base/src/nsMsgAccount.h b/mailnews/base/src/nsMsgAccount.h index 4cadc617c931..87682a3d9a57 100644 --- a/mailnews/base/src/nsMsgAccount.h +++ b/mailnews/base/src/nsMsgAccount.h @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -45,5 +45,7 @@ private: nsresult getPrefService(); nsresult createIncomingServer(); nsresult createIdentities(); + + static void clearPrefEnum(const char *aPref, void *aClosure); }; diff --git a/mailnews/base/src/nsMsgAccountManager.cpp b/mailnews/base/src/nsMsgAccountManager.cpp index 1a3b7007ec18..cdfcdbaa2bd2 100644 --- a/mailnews/base/src/nsMsgAccountManager.cpp +++ b/mailnews/base/src/nsMsgAccountManager.cpp @@ -502,7 +502,33 @@ nsMsgAccountManager::RemoveAccount(nsIMsgAccount *aAccount) NS_IF_RELEASE(removedServer); NotifyServerUnloaded(server); + + // now clear out the server once and for all. + // watch out! could be scary + server->ClearAllValues(); } + nsCOMPtr identityArray; + + rv = aAccount->GetIdentities(getter_AddRefs(identityArray)); + if (NS_SUCCEEDED(rv)) { + + PRUint32 count=0; + identityArray->Count(&count); + + PRUint32 i; + for (i=0; i identity; + rv = identityArray->QueryElementAt(i, NS_GET_IID(nsIMsgIdentity), + (void **)getter_AddRefs(identity)); + if (NS_SUCCEEDED(rv)) + // clear out all identity information. + // watch out! could be scary + identity->ClearAllValues(); + } + + } + + aAccount->ClearAllValues(); return NS_OK; } diff --git a/mailnews/base/util/nsMsgIdentity.cpp b/mailnews/base/util/nsMsgIdentity.cpp index 5aca2c1d855c..5163bc9e526f 100644 --- a/mailnews/base/util/nsMsgIdentity.cpp +++ b/mailnews/base/util/nsMsgIdentity.cpp @@ -374,6 +374,26 @@ nsMsgIdentity::SetSignature(nsIFileSpec *sig) return NS_OK; } +NS_IMETHODIMP +nsMsgIdentity::ClearAllValues() +{ + nsresult rv; + nsCAutoString rootPref("mail.identity."); + rootPref += m_identityKey; + + rv = m_prefs->EnumerateChildren(rootPref, clearPrefEnum, (void *)m_prefs); + + return rv; +} + +void +nsMsgIdentity::clearPrefEnum(const char *aPref, void *aClosure) +{ + nsIPref *prefs = (nsIPref *)aClosure; + prefs->ClearUserPref(aPref); +} + + NS_IMPL_GETSET(nsMsgIdentity, VCard, nsIMsgVCard*, m_vCard); NS_IMPL_GETTER_STR(nsMsgIdentity::GetKey, m_identityKey); diff --git a/mailnews/base/util/nsMsgIdentity.h b/mailnews/base/util/nsMsgIdentity.h index 3159cbebc893..7fa62708c34c 100644 --- a/mailnews/base/util/nsMsgIdentity.h +++ b/mailnews/base/util/nsMsgIdentity.h @@ -27,12 +27,6 @@ #include "nsIPref.h" #include "msgCore.h" -/////////////////////////////////////////////////////////////////////////////////// -// an identity is an object designed to encapsulate all the information we need -// to know about a user identity. I expect this interface to grow and change a lot -// as we flesh out our thoughts on multiple identities and what properties go into -// these identities. -////////////////////////////////////////////////////////////////////////////////// class NS_MSG_BASE nsMsgIdentity : public nsIMsgIdentity @@ -71,6 +65,9 @@ protected: nsresult getDefaultIntPref(const char *pref, PRInt32 *); nsresult setIntPref(const char *pref, PRInt32); +private: + static void clearPrefEnum(const char *aPref, void *aClosure); + }; diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index f05a81f27263..21f4d3e40e24 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -750,6 +750,26 @@ nsMsgIncomingServer::Equals(nsIMsgIncomingServer *server, PRBool *_retval) return rv; } +NS_IMETHODIMP +nsMsgIncomingServer::ClearAllValues() +{ + nsresult rv; + nsCAutoString rootPref("mail.server."); + rootPref += m_serverKey; + + rv = m_prefs->EnumerateChildren(rootPref, clearPrefEnum, (void *)m_prefs); + + return rv; +} + +void +nsMsgIncomingServer::clearPrefEnum(const char *aPref, void *aClosure) +{ + nsIPref *prefs = (nsIPref *)aClosure; + prefs->ClearUserPref(aPref); +} + + // use the convenience macros to implement the accessors NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, HostName, "hostname"); NS_IMPL_SERVERPREF_INT(nsMsgIncomingServer, Port, "port"); diff --git a/mailnews/base/util/nsMsgIncomingServer.h b/mailnews/base/util/nsMsgIncomingServer.h index a0501d984382..01eb986ebb7a 100644 --- a/mailnews/base/util/nsMsgIncomingServer.h +++ b/mailnews/base/util/nsMsgIncomingServer.h @@ -73,6 +73,8 @@ protected: nsresult CreateRootFolder(); + // pref callback to clear the user prefs + static void clearPrefEnum(const char *aPref, void *aClosure); }; #endif // nsMsgIncomingServer_h__