From 8a771fc719ce21bc1f545891c2c117b70d364204 Mon Sep 17 00:00:00 2001 From: "alecf%netscape.com" Date: Tue, 28 Mar 2000 04:58:05 +0000 Subject: [PATCH] - add generic interface to access mail filter lists in both servers and folders. in the base class, folders just forward to their root server. - expose event notifications through nsIFolder so that non-folders can trigger notifications on individual folders - add generic OnItemEvent to nsIFolderListener, and implement in base classes --- mailnews/base/public/nsIFolder.idl | 28 +++++++- mailnews/base/public/nsIFolderListener.idl | 42 +++++++++--- mailnews/base/public/nsIMsgFolder.idl | 4 ++ mailnews/base/public/nsIMsgIncomingServer.idl | 10 ++- mailnews/base/src/nsMsgFolderDataSource.cpp | 7 ++ mailnews/base/src/nsMsgMessageDataSource.cpp | 8 ++- .../base/src/nsMsgNotificationManager.cpp | 7 ++ mailnews/base/util/nsMsgFolder.cpp | 66 ++++++++++++++++++- mailnews/base/util/nsMsgFolder.h | 17 +---- mailnews/base/util/nsMsgIncomingServer.cpp | 56 +++++++++++++++- mailnews/base/util/nsMsgIncomingServer.h | 2 + 11 files changed, 216 insertions(+), 31 deletions(-) diff --git a/mailnews/base/public/nsIFolder.idl b/mailnews/base/public/nsIFolder.idl index 8e6b1913836..2a43b5e8025 100644 --- a/mailnews/base/public/nsIFolder.idl +++ b/mailnews/base/public/nsIFolder.idl @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- Mode: IDL; 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 @@ -41,6 +41,32 @@ interface nsIFolder : nsICollection { void RemoveFolderListener(in nsIFolderListener listener); nsIFolder FindSubFolder(in string subFolderName); + void NotifyPropertyChanged(in nsIAtom property, + in string oldValue, + in string newValue); + void NotifyIntPropertyChanged(in nsIAtom property, + in long oldValue, + in long newValue); + void NotifyBoolPropertyChanged(in nsIAtom property, + in boolean oldValue, + in boolean newValue); + void NotifyPropertyFlagChanged(in nsISupports item, + in nsIAtom property, + in unsigned long oldValue, + in unsigned long newValue); + void NotifyUnicharPropertyChanged(in nsIAtom property, + in wstring oldValue, + in wstring newValue); + + void NotifyItemAdded(in nsISupports parentItem, in nsISupports item, in string viewString); + void NotifyItemDeleted(in nsISupports parentItem, in nsISupports item, in string viewString); + + void NotifyFolderEvent(in nsIAtom event); + + void NotifyFolderLoaded(); + void NotifyDeleteOrMoveMessagesCompleted(in nsIFolder folder); + + void Shutdown(in boolean shutdownChildren); }; diff --git a/mailnews/base/public/nsIFolderListener.idl b/mailnews/base/public/nsIFolderListener.idl index 62b6dcbc971..6d38715ba23 100644 --- a/mailnews/base/public/nsIFolderListener.idl +++ b/mailnews/base/public/nsIFolderListener.idl @@ -28,15 +28,41 @@ interface nsIFolder; [scriptable, uuid(1c5ef9f0-d1c0-11d2-94CA-006097222B83)] /* XXX regenerate */ interface nsIFolderListener : nsISupports { - void OnItemAdded(in nsISupports parentItem, in nsISupports item, in string viewString); - void OnItemRemoved(in nsISupports parentItem, in nsISupports item, in string viewString); + void OnItemAdded(in nsISupports parentItem, + in nsISupports item, + in string viewString); + + void OnItemRemoved(in nsISupports parentItem, + in nsISupports item, + in string viewString); + + void OnItemPropertyChanged(in nsISupports item, + in nsIAtom property, + in string oldValue, + in string newValue); + + void OnItemIntPropertyChanged(in nsISupports item, + in nsIAtom property, + in long oldValue, + in long newValue); + + void OnItemBoolPropertyChanged(in nsISupports item, + in nsIAtom property, + in boolean oldValue, + in boolean newValue); + + void OnItemUnicharPropertyChanged(in nsISupports item, + in nsIAtom property, + in wstring oldValue, + in wstring newValue); + + void OnItemPropertyFlagChanged(in nsISupports item, + in nsIAtom property, + in unsigned long oldFlag, + in unsigned long newFlag); + + void OnItemEvent(in nsIFolder item, in nsIAtom event); - void OnItemPropertyChanged(in nsISupports item, in nsIAtom property, in string oldValue, in string newValue); - void OnItemIntPropertyChanged(in nsISupports item, in nsIAtom property, in long oldValue, in long newValue); - void OnItemBoolPropertyChanged(in nsISupports item, in nsIAtom property, in boolean oldValue, in boolean newValue); - void OnItemUnicharPropertyChanged(in nsISupports item, in nsIAtom property, in wstring oldValue, in wstring newValue); - void OnItemPropertyFlagChanged(in nsISupports item, in nsIAtom property, in unsigned long oldFlag, - in unsigned long newFlag); void OnFolderLoaded(in nsIFolder aFolder); void OnDeleteOrMoveMessagesCompleted(in nsIFolder aFolder); }; diff --git a/mailnews/base/public/nsIMsgFolder.idl b/mailnews/base/public/nsIMsgFolder.idl index db5eaa3b793..d56f275e7cf 100644 --- a/mailnews/base/public/nsIMsgFolder.idl +++ b/mailnews/base/public/nsIMsgFolder.idl @@ -38,6 +38,7 @@ interface nsIMsgWindow; interface nsIMsgDatabase; interface nsIDBFolderInfo; interface nsMsgKeyArray; +interface nsIMsgFilterList; interface nsIMsgFolderCacheElement; interface nsAutoString; @@ -115,6 +116,9 @@ interface nsIMsgFolder : nsIFolder { * the phantom server folder */ readonly attribute nsIMsgFolder rootFolder; + + /* filter for this folder */ + readonly attribute nsIMsgFilterList filterList; void ForceDBClosed (); void Delete (); diff --git a/mailnews/base/public/nsIMsgIncomingServer.idl b/mailnews/base/public/nsIMsgIncomingServer.idl index c495d93a927..e57772d1499 100644 --- a/mailnews/base/public/nsIMsgIncomingServer.idl +++ b/mailnews/base/public/nsIMsgIncomingServer.idl @@ -26,6 +26,8 @@ interface nsIFolder; interface nsIMsgFolderCache; interface nsIMsgWindow; +interface nsIMsgFilterList; + /* * Interface for incoming mail/news host * this is the base interface for all mail server types (imap, pop, nntp, etc) @@ -111,8 +113,14 @@ interface nsIMsgIncomingServer : nsISupports { going off at the same time. */ attribute boolean serverBusy; + /* should we use a secure channel? */ + attribute boolean isSecure; + /* what kind of logon redirector to use for this server, if any */ attribute string redirectorType; + + readonly attribute nsIMsgFilterList filterList; + /* we use this to set the default local path. we use this when migrating prefs */ void SetDefaultLocalPath(in nsIFileSpec aDefaultLocalPath); @@ -157,8 +165,6 @@ interface nsIMsgIncomingServer : nsISupports { wstring toString(); - attribute boolean isSecure; - /* used for comparing nsIMsgIncomingServers */ boolean equals(in nsIMsgIncomingServer server); }; diff --git a/mailnews/base/src/nsMsgFolderDataSource.cpp b/mailnews/base/src/nsMsgFolderDataSource.cpp index 258feb2f4bc..a1a579041fa 100644 --- a/mailnews/base/src/nsMsgFolderDataSource.cpp +++ b/mailnews/base/src/nsMsgFolderDataSource.cpp @@ -875,6 +875,13 @@ nsMsgFolderDataSource::OnItemPropertyFlagChanged(nsISupports *item, } +NS_IMETHODIMP +nsMsgFolderDataSource::OnItemEvent(nsIFolder *aFolder, nsIAtom *aEvent) +{ + return NS_OK; +} + + NS_IMETHODIMP nsMsgFolderDataSource::OnFolderLoaded(nsIFolder *folder) { nsresult rv = NS_OK; diff --git a/mailnews/base/src/nsMsgMessageDataSource.cpp b/mailnews/base/src/nsMsgMessageDataSource.cpp index bacae92d843..0fc4b72cf29 100644 --- a/mailnews/base/src/nsMsgMessageDataSource.cpp +++ b/mailnews/base/src/nsMsgMessageDataSource.cpp @@ -606,6 +606,7 @@ NS_IMETHODIMP nsMsgMessageDataSource::OnItemRemoved(nsISupports *parentItem, nsI return OnItemAddedOrRemoved(parentItem, item, viewString, PR_FALSE); } + nsresult nsMsgMessageDataSource::OnItemAddedOrRemoved(nsISupports *parentItem, nsISupports *item, const char *viewString, PRBool added) { @@ -726,6 +727,12 @@ nsMsgMessageDataSource::OnItemPropertyFlagChanged(nsISupports *item, return rv; } +NS_IMETHODIMP +nsMsgMessageDataSource::OnItemEvent(nsIFolder *aFolder, nsIAtom *aEvent) +{ + return NS_OK; +} + NS_IMETHODIMP nsMsgMessageDataSource::OnFolderLoaded(nsIFolder *folder) { nsresult rv = NS_OK; @@ -893,7 +900,6 @@ nsMsgMessageDataSource::createMessageNode(nsIMessage *message, return rv; } - nsresult nsMsgMessageDataSource::createMessageNameNode(nsIMessage *message, PRBool sort, diff --git a/mailnews/base/src/nsMsgNotificationManager.cpp b/mailnews/base/src/nsMsgNotificationManager.cpp index a14242e1115..658f4e8c338 100644 --- a/mailnews/base/src/nsMsgNotificationManager.cpp +++ b/mailnews/base/src/nsMsgNotificationManager.cpp @@ -248,6 +248,13 @@ nsMsgNotificationManager::OnItemPropertyFlagChanged(nsISupports *item, return rv; } +NS_IMETHODIMP +nsMsgNotificationManager::OnItemEvent(nsIFolder *folder, nsIAtom *aEvent) +{ + return NS_OK; +} + + NS_IMETHODIMP nsMsgNotificationManager::OnFolderLoaded(nsIFolder *folder) { nsresult rv = NS_OK; diff --git a/mailnews/base/util/nsMsgFolder.cpp b/mailnews/base/util/nsMsgFolder.cpp index e372b54f463..4813920a215 100644 --- a/mailnews/base/util/nsMsgFolder.cpp +++ b/mailnews/base/util/nsMsgFolder.cpp @@ -44,6 +44,7 @@ #include "nsIAllocator.h" #include "nsIURL.h" #include "nsMsgUtils.h" // for NS_MsgHashIfNecessary() + #include "nsIIOService.h" static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID); @@ -107,10 +108,12 @@ nsMsgFolder::nsMsgFolder(void) nsMsgFolder::~nsMsgFolder(void) { + nsresult rv; + if(mSubFolders) { PRUint32 count; - nsresult rv = mSubFolders->Count(&count); + rv = mSubFolders->Count(&count); NS_ASSERTION(NS_SUCCEEDED(rv), "Count failed"); for (int i = count - 1; i >= 0; i--) @@ -350,6 +353,26 @@ NS_IMETHODIMP nsMsgFolder::RemoveFolderListener(nsIFolderListener * listener) NS_IMETHODIMP nsMsgFolder::SetParent(nsIFolder *aParent) { mParent = getter_AddRefs(NS_GetWeakReference(aParent)); + + if (aParent) { + nsresult rv; + nsCOMPtr parentMsgFolder = + do_QueryInterface(aParent, &rv); + + if (NS_SUCCEEDED(rv)) { + + // servers do not have parents, so we must not be a server + mIsServer = PR_FALSE; + mIsServerIsValid = PR_TRUE; + + // also set the server itself while we're here. + + nsCOMPtr server; + nsresult rv = parentMsgFolder->GetServer(getter_AddRefs(server)); + if (NS_SUCCEEDED(rv) && server) + mServer = getter_AddRefs(NS_GetWeakReference(server)); + } + } return NS_OK; } @@ -2038,7 +2061,7 @@ nsMsgFolder::SetDeleteIsMoveToTrash(PRBool bVal) nsresult nsMsgFolder::NotifyPropertyChanged(nsIAtom *property, - char *oldValue, char* newValue) + const char *oldValue, const char* newValue) { nsCOMPtr supports; if(NS_SUCCEEDED(QueryInterface(NS_GET_IID(nsISupports), getter_AddRefs(supports)))) @@ -2245,6 +2268,24 @@ nsresult nsMsgFolder::NotifyDeleteOrMoveMessagesCompleted(nsIFolder *folder) return NS_OK; } +nsresult nsMsgFolder::NotifyFolderEvent(nsIAtom* aEvent) +{ + PRInt32 i; + for(i = 0; i < mListeners->Count(); i++) + { + //Folderlistener's aren't refcounted. + nsIFolderListener *listener = (nsIFolderListener*)mListeners->ElementAt(i); + listener->OnItemEvent(this, aEvent); + } + //Notify listeners who listen to every folder + nsresult rv; + NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kMsgMailSessionCID, &rv); + if(NS_SUCCEEDED(rv)) + mailSession->NotifyFolderEvent(this, aEvent); + + return NS_OK; +} + nsresult nsGetMailFolderSeparator(nsString& result) { @@ -2276,3 +2317,24 @@ nsMsgFolder::RecursiveSetDeleteIsMoveToTrash(PRBool bVal) } return SetDeleteIsMoveToTrash(bVal); } + +NS_IMETHODIMP +nsMsgFolder::GetFilterList(nsIMsgFilterList **aResult) +{ + nsresult rv; + + // only get filters for root folders in the base class +#ifdef NS_DEBUG + PRBool isServer=PR_FALSE; + rv = GetIsServer(&isServer); + NS_ASSERTION(NS_SUCCEEDED(rv), "error getting serverness"); + NS_ASSERTION(isServer, "Getting filter for non-server?"); +#endif + + nsCOMPtr server; + rv = GetServer(getter_AddRefs(server)); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(server, NS_ERROR_FAILURE); + + return server->GetFilterList(aResult); +} diff --git a/mailnews/base/util/nsMsgFolder.h b/mailnews/base/util/nsMsgFolder.h index 8c4fc177421..dbf1b52c165 100644 --- a/mailnews/base/util/nsMsgFolder.h +++ b/mailnews/base/util/nsMsgFolder.h @@ -38,6 +38,7 @@ #include "nsCOMPtr.h" #include "nsIURL.h" #include "nsWeakReference.h" +#include "nsIMsgFilterList.h" /* * MsgFolder @@ -84,6 +85,7 @@ public: NS_IMETHOD GetCanFileMessages(PRBool *aCanFileMessages); NS_IMETHOD GetCanCreateSubfolders(PRBool *aCanCreateSubfolders); NS_IMETHOD GetCanRename(PRBool *aCanRename); + NS_IMETHOD GetFilterList(nsIMsgFilterList **aFilterList); NS_IMETHOD ForceDBClosed(void); NS_IMETHOD Delete(void); NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders, nsIMsgWindow *msgWindow); @@ -225,20 +227,7 @@ public: protected: - nsresult NotifyPropertyChanged(nsIAtom *property, char* oldValue, char* newValue); - nsresult NotifyIntPropertyChanged(nsIAtom *property, PRInt32 oldValue, PRInt32 newValue); - nsresult NotifyBoolPropertyChanged(nsIAtom *property, PRBool oldValue, PRBool newValue); - nsresult NotifyUnicharPropertyChanged(nsIAtom *property, const PRUnichar* oldValue, const PRUnichar* newValue); - - nsresult NotifyPropertyFlagChanged(nsISupports *item, nsIAtom *property, PRUint32 oldValue, - PRUint32 newValue); - nsresult NotifyItemAdded(nsISupports *parentItem, nsISupports *item, const char *viewString); - nsresult NotifyItemDeleted(nsISupports *parentItem, nsISupports *item, const char* viewString); - - nsresult NotifyFolderLoaded(); - nsresult NotifyDeleteOrMoveMessagesCompleted(nsIFolder *folder); - // this is a little helper function that is not part of the public interface. // we use it to get the IID of the incoming server for the derived folder. // w/out a function like this we would have to implement GetServer in each @@ -290,8 +279,8 @@ protected: PRBool mIsServer; nsString mName; nsCOMPtr mPath; - char * mBaseMessageURI; //The uri with the message scheme PRBool mDeleteIsMoveToTrash; + char * mBaseMessageURI; //The uri with the message scheme // static stuff for cross-instance objects like atoms static PRInt32 gInstanceCount; diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index bc65f217afd..c72064509fd 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -29,19 +29,24 @@ #include "prprf.h" #include "nsIServiceManager.h" -#include "nsIPref.h" #include "nsCOMPtr.h" +#include "nsXPIDLString.h" + +#include "nsMsgBaseCID.h" #include "nsIMsgFolder.h" #include "nsIMsgFolderCache.h" #include "nsIMsgFolderCacheElement.h" #include "nsIMsgWindow.h" +#include "nsIMsgFilterService.h" +#include "nsIMsgProtocolInfo.h" + +#include "nsIPref.h" #include "nsIWebShell.h" #include "nsIWebShellWindow.h" #include "nsINetPrompt.h" #include "nsIWalletService.h" -#include "nsXPIDLString.h" + #include "nsIRDFService.h" -#include "nsIMsgProtocolInfo.h" #include "nsIAppShellService.h" #include "nsAppShellCIDs.h" #include "nsIXULWindow.h" @@ -55,6 +60,7 @@ static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID); static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID); static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID); static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID); +static NS_DEFINE_CID(kMsgFilterServiceCID, NS_MSGFILTERSERVICE_CID); MOZ_DECL_CTOR_COUNTER(nsMsgIncomingServer); @@ -70,6 +76,13 @@ nsMsgIncomingServer::nsMsgIncomingServer(): nsMsgIncomingServer::~nsMsgIncomingServer() { + nsresult rv; + if (mFilterList) { + nsCOMPtr filterService = + do_GetService(kMsgFilterServiceCID, &rv); + if (NS_SUCCEEDED(rv)) + rv = filterService->CloseFilterList(mFilterList); + } if (m_prefs) nsServiceManager::ReleaseService(kPrefServiceCID, m_prefs, nsnull); @@ -862,6 +875,43 @@ nsMsgIncomingServer::clearPrefEnum(const char *aPref, void *aClosure) prefs->ClearUserPref(aPref); } +nsresult +nsMsgIncomingServer::GetFilterList(nsIMsgFilterList **aResult) +{ + + nsresult rv; + + if (!mFilterList) { + nsCOMPtr folder; + rv = GetRootFolder(getter_AddRefs(folder)); + + nsCOMPtr msgFolder(do_QueryInterface(folder, &rv)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr thisFolder; + rv = msgFolder->GetPath(getter_AddRefs(thisFolder)); + NS_ENSURE_SUCCESS(rv, rv); + + nsFileSpec filterFile; + + rv = thisFolder->GetFileSpec(&filterFile); + NS_ENSURE_SUCCESS(rv, rv); + + filterFile += "rules.dat"; + + nsCOMPtr filterService = + do_GetService(kMsgFilterServiceCID, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + rv = filterService->OpenFilterList(&filterFile, getter_AddRefs(mFilterList)); + NS_ENSURE_SUCCESS(rv, rv); + } + + *aResult = mFilterList; + NS_IF_ADDREF(*aResult); + +} + // use the convenience macros to implement the accessors NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, HostName, "hostname"); diff --git a/mailnews/base/util/nsMsgIncomingServer.h b/mailnews/base/util/nsMsgIncomingServer.h index 294422e2529..fc64e929bd5 100644 --- a/mailnews/base/util/nsMsgIncomingServer.h +++ b/mailnews/base/util/nsMsgIncomingServer.h @@ -25,6 +25,7 @@ #include "nsIMsgIncomingServer.h" #include "nsIPref.h" +#include "nsIMsgFilterList.h" #include "msgCore.h" #include "nsIFolder.h" #include "nsCOMPtr.h" @@ -74,6 +75,7 @@ protected: nsresult CreateRootFolder(); nsresult StorePassword(); // stuff the password in the single signon database + nsCOMPtr mFilterList; // pref callback to clear the user prefs static void clearPrefEnum(const char *aPref, void *aClosure); };