diff --git a/mailnews/base/public/nsIMsgFolder.idl b/mailnews/base/public/nsIMsgFolder.idl index 22a371725eb..7365ee88bd4 100644 --- a/mailnews/base/public/nsIMsgFolder.idl +++ b/mailnews/base/public/nsIMsgFolder.idl @@ -350,4 +350,6 @@ const nsMsgBiffState nsMsgBiffState_Unknown = 2; // We dunno whether there is ne void enableNotifications(in long notificationType, in boolean enable); + attribute nsIMsgRetentionSettings retentionSettings; + }; diff --git a/mailnews/base/public/nsIMsgIncomingServer.idl b/mailnews/base/public/nsIMsgIncomingServer.idl index 8c3a93abed8..f85e8bd0c01 100644 --- a/mailnews/base/public/nsIMsgIncomingServer.idl +++ b/mailnews/base/public/nsIMsgIncomingServer.idl @@ -27,6 +27,7 @@ interface nsIFolder; interface nsIMsgFolderCache; interface nsIMsgWindow; interface nsIMsgFilterList; +interface nsIMsgRetentionSettings; /* * Interface for incoming mail/news host @@ -190,6 +191,8 @@ interface nsIMsgIncomingServer : nsISupports { attribute boolean canDelete; attribute boolean loginAtStartUp; + + attribute nsIMsgRetentionSettings retentionSettings; }; %{C++ diff --git a/mailnews/base/util/nsMsgDBFolder.cpp b/mailnews/base/util/nsMsgDBFolder.cpp index fd45ada4050..93c4824b577 100644 --- a/mailnews/base/util/nsMsgDBFolder.cpp +++ b/mailnews/base/util/nsMsgDBFolder.cpp @@ -1206,6 +1206,43 @@ nsMsgDBFolder::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode) return NS_OK; } +NS_IMETHODIMP nsMsgDBFolder::GetRetentionSettings(nsIMsgRetentionSettings **settings) +{ + NS_ENSURE_ARG_POINTER(settings); + nsresult rv = NS_OK; + if (!m_retentionSettings) + { + GetDatabase(nsnull); + if (mDatabase) + { + // get the settings from the db - if the settings from the db say the folder + // is not overriding the incoming server settings, get the settings from the + // server. + rv = mDatabase->GetMsgRetentionSettings(getter_AddRefs(m_retentionSettings)); + if (NS_SUCCEEDED(rv) && m_retentionSettings) + { + nsMsgRetainByPreference retainBy; + m_retentionSettings->GetRetainByPreference(&retainBy); + if (retainBy == nsIMsgRetentionSettings::nsMsgRetainByServerDefaults) + { + nsCOMPtr incomingServer; + rv = GetServer(getter_AddRefs(incomingServer)); + if (NS_SUCCEEDED(rv) && incomingServer) + incomingServer->GetRetentionSettings(getter_AddRefs(m_retentionSettings)); + } + + } + } + } + *settings = m_retentionSettings; + return rv; +} + +NS_IMETHODIMP nsMsgDBFolder::SetRetentionSettings(nsIMsgRetentionSettings *settings) +{ + m_retentionSettings = settings; + return NS_OK; +} nsresult nsMsgDBFolder::NotifyStoreClosedAllHeaders() { diff --git a/mailnews/base/util/nsMsgDBFolder.h b/mailnews/base/util/nsMsgDBFolder.h index 1ceb396198b..904f4845f29 100644 --- a/mailnews/base/util/nsMsgDBFolder.h +++ b/mailnews/base/util/nsMsgDBFolder.h @@ -92,6 +92,8 @@ public: NS_IMETHOD GetOfflineFileChannel(nsMsgKey msgKey, nsIFileChannel **aFileChannel); NS_IMETHOD HasMsgOffline(nsMsgKey msgKey, PRBool *result); NS_IMETHOD DownloadMessagesForOffline(nsISupportsArray *messages); + NS_IMETHOD GetRetentionSettings(nsIMsgRetentionSettings **settings); + NS_IMETHOD SetRetentionSettings(nsIMsgRetentionSettings *settings); protected: virtual nsresult ReadDBFolderInfo(PRBool force); @@ -126,6 +128,7 @@ protected: // this is currently used when we do a save as of an imap or news message.. nsCOMPtr m_tempMessageStream; + nsCOMPtr m_retentionSettings; static nsIAtom* mFolderLoadedAtom; static nsIAtom* mDeleteOrMoveMsgCompletedAtom; static nsIAtom* mDeleteOrMoveMsgFailedAtom; diff --git a/mailnews/base/util/nsMsgIncomingServer.cpp b/mailnews/base/util/nsMsgIncomingServer.cpp index e8522ec0405..a9d755ef2c3 100644 --- a/mailnews/base/util/nsMsgIncomingServer.cpp +++ b/mailnews/base/util/nsMsgIncomingServer.cpp @@ -33,6 +33,7 @@ #include "nsXPIDLString.h" #include "nsMsgBaseCID.h" +#include "nsMsgDBCID.h" #include "nsIMsgFolder.h" #include "nsIMsgFolderCache.h" #include "nsIMsgFolderCacheElement.h" @@ -1053,6 +1054,27 @@ nsMsgIncomingServer::getProtocolInfo(nsIMsgProtocolInfo **aResult) return NS_OK; } +NS_IMETHODIMP nsMsgIncomingServer::GetRetentionSettings(nsIMsgRetentionSettings **settings) +{ + NS_ENSURE_ARG_POINTER(settings); + if (!m_retentionSettings) + { + m_retentionSettings = do_CreateInstance(NS_MSG_RETENTIONSETTINGS_CONTRACTID); + + // Create an empty retention settings object, + // get the settings from the server prefs, and init the object from the prefs. + } + *settings = m_retentionSettings; + return NS_OK; +} + +NS_IMETHODIMP nsMsgIncomingServer::SetRetentionSettings(nsIMsgRetentionSettings *settings) +{ + m_retentionSettings = settings; + return NS_OK; +} + + // use the convenience macros to implement the accessors NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Username, "userName"); NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, PrefPassword, "password"); diff --git a/mailnews/base/util/nsMsgIncomingServer.h b/mailnews/base/util/nsMsgIncomingServer.h index 1204c6ad5ba..a6f09a057c9 100644 --- a/mailnews/base/util/nsMsgIncomingServer.h +++ b/mailnews/base/util/nsMsgIncomingServer.h @@ -30,6 +30,7 @@ #include "nsIFolder.h" #include "nsCOMPtr.h" #include "nsWeakReference.h" +#include "nsIMsgDatabase.h" class nsIMsgFolderCache; class nsIMsgProtocolInfo; @@ -68,6 +69,7 @@ protected: NS_IMETHOD SetPrefPassword(const char * aPassword); nsCOMPtr m_rootFolder; + nsCOMPtr m_retentionSettings; nsresult getDefaultCharPref(const char *pref, char **); nsresult getDefaultUnicharPref(const char *pref, PRUnichar **); nsresult getDefaultBoolPref(const char *pref, PRBool *); diff --git a/mailnews/db/msgdb/build/nsMsgDBCID.h b/mailnews/db/msgdb/build/nsMsgDBCID.h index 69e31386ffb..1cbdb40fb1b 100644 --- a/mailnews/db/msgdb/build/nsMsgDBCID.h +++ b/mailnews/db/msgdb/build/nsMsgDBCID.h @@ -42,4 +42,10 @@ { 0x9e4b07ee, 0xe980, 0x11d2, \ { 0xa5, 0x06, 0x00, 0x60, 0xb0, 0xfc, 0x04, 0xb7 } } +#define NS_MSG_RETENTIONSETTINGS_CID \ +{ 0x1bd976d6, 0xdf44, 0x11d4, \ + {0xa5, 0xb6, 0x00, 0x60, 0xb0, 0xfc, 0x04, 0xb7} } + +#define NS_MSG_RETENTIONSETTINGS_CONTRACTID \ + "@mozilla.org/msgDatabase/retentionSettings;1" #endif diff --git a/mailnews/db/msgdb/build/nsMsgDBFactory.cpp b/mailnews/db/msgdb/build/nsMsgDBFactory.cpp index e7e42bbd2c0..64ed790ab1f 100644 --- a/mailnews/db/msgdb/build/nsMsgDBFactory.cpp +++ b/mailnews/db/msgdb/build/nsMsgDBFactory.cpp @@ -36,10 +36,12 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID); static NS_DEFINE_CID(kCMailDB, NS_MAILDB_CID); static NS_DEFINE_CID(kCNewsDB, NS_NEWSDB_CID); static NS_DEFINE_CID(kCImapDB, NS_IMAPDB_CID); +static NS_DEFINE_CID(kCMsgRetentionSettings, NS_MSG_RETENTIONSETTINGS_CID); NS_GENERIC_FACTORY_CONSTRUCTOR(nsMailDatabase) NS_GENERIC_FACTORY_CONSTRUCTOR(nsNewsDatabase) NS_GENERIC_FACTORY_CONSTRUCTOR(nsImapMailDatabase) +NS_GENERIC_FACTORY_CONSTRUCTOR(nsMsgRetentionSettings) // Module implementation for the msg db library class nsMsgDBModule : public nsIModule @@ -61,6 +63,7 @@ protected: nsCOMPtr mMailDBFactory; nsCOMPtr mNewsDBFactory; nsCOMPtr mImapDBFactory; + nsCOMPtr mMsgRetentionSettingsFactory; }; @@ -95,6 +98,7 @@ void nsMsgDBModule::Shutdown() mMailDBFactory = null_nsCOMPtr(); mNewsDBFactory = null_nsCOMPtr(); mImapDBFactory = null_nsCOMPtr(); + mMsgRetentionSettingsFactory = null_nsCOMPtr(); } // Create a factory object for creating instances of aClass. @@ -141,6 +145,12 @@ NS_IMETHODIMP nsMsgDBModule::GetClassObject(nsIComponentManager *aCompMgr, rv = NS_NewGenericFactory(getter_AddRefs(mImapDBFactory), &nsImapMailDatabaseConstructor); fact = mImapDBFactory; } + else if (aClass.Equals(kCMsgRetentionSettings)) + { + if (!mMsgRetentionSettingsFactory) + rv = NS_NewGenericFactory(getter_AddRefs(mMsgRetentionSettingsFactory), &nsMsgRetentionSettingsConstructor); + fact = mMsgRetentionSettingsFactory; + } if (fact) rv = fact->QueryInterface(aIID, r_classObj); @@ -162,8 +172,10 @@ static Components gComponents[] = { nsnull }, { "Imap DB", &kCImapDB, nsnull }, - + { "Msg Retention Settings", &kCMsgRetentionSettings, + NS_MSG_RETENTIONSETTINGS_CONTRACTID} }; + #define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0])) NS_IMETHODIMP nsMsgDBModule::RegisterSelf(nsIComponentManager *aCompMgr, diff --git a/mailnews/db/msgdb/public/nsIMsgDatabase.idl b/mailnews/db/msgdb/public/nsIMsgDatabase.idl index b5f159f69de..aeb13868d53 100644 --- a/mailnews/db/msgdb/public/nsIMsgDatabase.idl +++ b/mailnews/db/msgdb/public/nsIMsgDatabase.idl @@ -35,6 +35,30 @@ interface nsISimpleEnumerator; interface nsIMsgThread; interface nsIDBFolderInfo; +typedef unsigned long nsMsgRetainByPreference; + +[scriptable, uuid(063bd2ac-de85-11d4-a5b6-0060b0fc04b7)] + +interface nsIMsgRetentionSettings : nsISupports +{ + const unsigned long nsMsgRetainAll = 0; + const unsigned long nsMsgRetainByServerDefaults = 1; + const unsigned long nsMsgRetainByAge = 2; + const unsigned long nsMsgRetainByNumHeaders = 3; + + attribute nsMsgRetainByPreference retainByPreference; + attribute unsigned long daysToKeepHdrs; + attribute unsigned long numHeadersToKeep; + + // this is orthogonal to retaining by age or num headers, i.e., if + // it's set, we'll only keep NNN unread messages only, or unread + // messages less than NNN days old. + attribute boolean keepUnreadMessagesOnly; + // this is for keeping offline bodies. + attribute unsigned long daysToKeepBodies; +}; + + typedef long nsMsgDBCommit; [scriptable, uuid(aa4d45d0-3956-11d3-8d76-00805f8a6617)] @@ -164,6 +188,9 @@ interface nsIMsgDatabase : nsIDBChangeAnnouncer { in nsIDBChangeListener instigator); readonly attribute nsMsgKey FirstNew; + + attribute nsIMsgRetentionSettings msgRetentionSettings; + boolean HasNew(); void ClearNewList(in boolean notify); void AddToNewList(in nsMsgKey key); diff --git a/mailnews/db/msgdb/public/nsMsgDatabase.h b/mailnews/db/msgdb/public/nsMsgDatabase.h index 961e1d5f257..720ba58b7da 100644 --- a/mailnews/db/msgdb/public/nsMsgDatabase.h +++ b/mailnews/db/msgdb/public/nsMsgDatabase.h @@ -50,162 +50,25 @@ class nsMsgDatabase : public nsIMsgDatabase { public: NS_DECL_ISUPPORTS - - ////////////////////////////////////////////////////////////////////////////// - // nsIDBChangeAnnouncer methods: - NS_IMETHOD AddListener(nsIDBChangeListener *listener); - NS_IMETHOD RemoveListener(nsIDBChangeListener *listener); - - NS_IMETHOD NotifyKeyChangeAll(nsMsgKey keyChanged, PRUint32 aOldFlags, PRUint32 aNewFlags, - nsIDBChangeListener *instigator); - NS_IMETHOD NotifyKeyAddedAll(nsMsgKey keyAdded, nsMsgKey parentKey, PRInt32 flags, + NS_DECL_NSIDBCHANGEANNOUNCER + NS_DECL_NSIMSGDATABASE + virtual nsresult IsHeaderRead(nsIMsgDBHdr *hdr, PRBool *pRead); + virtual nsresult MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead, nsIDBChangeListener *instigator); - NS_IMETHOD NotifyKeyDeletedAll(nsMsgKey keyDeleted, nsMsgKey parentKey, PRInt32 flags, - nsIDBChangeListener *instigator); - NS_IMETHOD NotifyParentChangedAll(nsMsgKey keyReparented, nsMsgKey oldParent, nsMsgKey newParent, - nsIDBChangeListener *instigator); - - NS_IMETHOD NotifyReadChanged(nsIDBChangeListener *instigator); - NS_IMETHOD NotifyAnnouncerGoingAway(void); - - ////////////////////////////////////////////////////////////////////////////// - // nsIMsgDatabase methods: - NS_IMETHOD Open(nsIFileSpec *folderName, PRBool create, PRBool upgrading, nsIMsgDatabase** pMessageDB); - NS_IMETHOD Close(PRBool forceCommit); - - // argh, these two shouldn't be Interface methods, but I can't diddle the interfaces - // until the idl works on windows. grumble grumble. - NS_IMETHOD OpenMDB(const char *dbName, PRBool create); - NS_IMETHOD CloseMDB(PRBool commit); - - NS_IMETHOD Commit(nsMsgDBCommit commitType); - // Force closed is evil, and we should see if we can do without it. - // In 4.x, it was mainly used to remove corrupted databases. - NS_IMETHOD ForceClosed(void); - // get a message header for the given key. Caller must release()! - NS_IMETHOD GetMsgHdrForKey(nsMsgKey key, nsIMsgDBHdr **msg); - - //Returns whether or not this database contains the given key - NS_IMETHOD ContainsKey(nsMsgKey key, PRBool *containsKey); - - // Must call AddNewHdrToDB after creating. The idea is that you create - // a new header, fill in its properties, and then call AddNewHdrToDB. - // AddNewHdrToDB will send notifications to any listeners. - NS_IMETHOD CreateNewHdr(nsMsgKey key, nsIMsgDBHdr **newHdr); - virtual nsresult CreateMsgHdr(nsIMdbRow* hdrRow, nsMsgKey key, nsIMsgDBHdr **result); - - NS_IMETHOD CopyHdrFromExistingHdr(nsMsgKey key, nsIMsgDBHdr *existingHdr, nsIMsgDBHdr **newHdr); - NS_IMETHOD AddNewHdrToDB(nsIMsgDBHdr *newHdr, PRBool notify); - - NS_IMETHOD ListAllKeys(nsMsgKeyArray &outputKeys); - NS_IMETHOD EnumerateMessages(nsISimpleEnumerator* *result); - NS_IMETHOD EnumerateUnreadMessages(nsISimpleEnumerator* *result); - NS_IMETHOD EnumerateThreads(nsISimpleEnumerator* *result); - + virtual nsresult OpenMDB(const char *dbName, PRBool create); + virtual nsresult CloseMDB(PRBool commit); + virtual nsresult CreateMsgHdr(nsIMdbRow* hdrRow, nsMsgKey key, nsIMsgDBHdr **result); + virtual nsresult GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result); + virtual nsresult EnumerateUnreadMessages(nsISimpleEnumerator* *result); // this might just be for debugging - we'll see. nsresult ListAllThreads(nsMsgKeyArray *threadIds); - - // helpers for user command functions like delete, mark read, etc. - - NS_IMETHOD MarkHdrRead(nsIMsgDBHdr *msgHdr, PRBool bRead, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkHdrReplied(nsIMsgDBHdr *msgHdr, PRBool bReplied, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkHdrMarked(nsIMsgDBHdr *msgHdr, PRBool mark, - nsIDBChangeListener *instigator); - - // MDN support - NS_IMETHOD MarkMDNNeeded(nsMsgKey key, PRBool bNeeded, - nsIDBChangeListener *instigator); - - // MarkMDNneeded only used when mail server is a POP3 server - // or when the IMAP server does not support user defined - // PERMANENTFLAGS - NS_IMETHOD IsMDNNeeded(nsMsgKey key, PRBool *isNeeded); - - NS_IMETHOD MarkMDNSent(nsMsgKey key, PRBool bNeeded, - nsIDBChangeListener *instigator); - NS_IMETHOD IsMDNSent(nsMsgKey key, PRBool *isSent); - -// methods to get and set docsets for ids. - NS_IMETHOD MarkRead(nsMsgKey key, PRBool bRead, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkReplied(nsMsgKey key, PRBool bReplied, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkForwarded(nsMsgKey key, PRBool bForwarded, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkHasAttachments(nsMsgKey key, PRBool bHasAttachments, - nsIDBChangeListener *instigator); - - NS_IMETHOD MarkThreadRead(nsIMsgThread *thread, nsIDBChangeListener *instigator, nsMsgKeyArray *thoseMarked); - NS_IMETHOD MarkThreadIgnored(nsIMsgThread *thread, nsMsgKey threadKey, PRBool bIgnored, - nsIDBChangeListener *instigator); - NS_IMETHOD MarkThreadWatched(nsIMsgThread *thread, nsMsgKey threadKey, PRBool bWatched, - nsIDBChangeListener *instigator); - - NS_IMETHOD IsRead(nsMsgKey key, PRBool *pRead); - NS_IMETHOD IsIgnored(nsMsgKey key, PRBool *pIgnored); - NS_IMETHOD IsMarked(nsMsgKey key, PRBool *pMarked); - NS_IMETHOD HasAttachments(nsMsgKey key, PRBool *pHasThem); - - NS_IMETHOD MarkAllRead(nsMsgKeyArray *thoseMarked); - NS_IMETHOD MarkReadByDate (PRTime te, PRTime endDate, nsMsgKeyArray *markedIds); - - NS_IMETHOD DeleteMessages(nsMsgKeyArray* nsMsgKeys, nsIDBChangeListener *instigator); - NS_IMETHOD DeleteMessage(nsMsgKey key, - nsIDBChangeListener *instigator, - PRBool commit); - NS_IMETHOD DeleteHeader(nsIMsgDBHdr *msgHdr, nsIDBChangeListener *instigator, - PRBool commit, PRBool notify); - - NS_IMETHOD RemoveHeaderMdbRow(nsIMsgDBHdr *msgHdr); - - NS_IMETHOD UndoDelete(nsIMsgDBHdr *msgHdr); - - NS_IMETHOD MarkLater(nsMsgKey key, PRTime until); - NS_IMETHOD MarkMarked(nsMsgKey key, PRBool mark, - nsIDBChangeListener *instigator); - NS_IMETHOD MarkOffline(nsMsgKey key, PRBool offline, - nsIDBChangeListener *instigator); - - NS_IMETHOD AllMsgKeysImapDeleted(nsMsgKeyArray *keys, PRBool *allKeysDeleted); - - NS_IMETHOD MarkImapDeleted(nsMsgKey key, PRBool deleted, - nsIDBChangeListener *instigator); - - NS_IMETHOD GetFirstNew(nsMsgKey *result); - NS_IMETHOD HasNew(PRBool *_retval); - NS_IMETHOD ClearNewList(PRBool notify); - NS_IMETHOD AddToNewList(nsMsgKey key); - - // used mainly to force the timestamp of a local mail folder db to - // match the time stamp of the corresponding berkeley mail folder, - // but also useful to tell the summary to mark itself invalid - NS_IMETHOD SetSummaryValid(PRBool valid); - - // offline operations - NS_IMETHOD ListAllOfflineOpIds(nsMsgKeyArray *offlineOpIds); - NS_IMETHOD ListAllOfflineDeletes(nsMsgKeyArray *offlineDeletes); - - NS_IMETHOD GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result); - NS_IMETHOD GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgThread **result) ; - - NS_IMETHOD GetHighWaterArticleNum(nsMsgKey *key); - NS_IMETHOD GetLowWaterArticleNum(nsMsgKey *key); ////////////////////////////////////////////////////////////////////////////// // nsMsgDatabase methods: nsMsgDatabase(); virtual ~nsMsgDatabase(); - NS_IMETHOD IsHeaderRead(nsIMsgDBHdr *hdr, PRBool *pRead); static nsIMdbFactory *GetMDBFactory(); - NS_IMETHOD GetDBFolderInfo(nsIDBFolderInfo **result); nsIMdbEnv *GetEnv() {return m_mdbEnv;} nsIMdbStore *GetStore() {return m_mdbStore;} virtual PRUint32 GetCurVersion(); @@ -293,8 +156,6 @@ protected: virtual PRBool SetHdrReadFlag(nsIMsgDBHdr *, PRBool pRead); virtual PRUint32 GetStatusFlags(nsIMsgDBHdr *msgHdr, PRUint32 origFlags); // helper function which doesn't involve thread object - NS_IMETHOD MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead, - nsIDBChangeListener *instigator); virtual nsresult RemoveHeaderFromDB(nsMsgHdr *msgHdr); virtual nsresult RemoveHeaderFromThread(nsMsgHdr *msgHdr); @@ -305,6 +166,8 @@ protected: nsCOMPtr m_collationKeyGenerator; nsCOMPtr m_mimeConverter; + nsCOMPtr m_retentionSettings; + // mdb bookkeeping stuff nsresult InitExistingDB(); nsresult InitNewDB(); @@ -381,4 +244,21 @@ protected: }; +class nsMsgRetentionSettings : public nsIMsgRetentionSettings +{ +public: + nsMsgRetentionSettings(); + virtual ~nsMsgRetentionSettings(); + + NS_DECL_ISUPPORTS + NS_DECL_NSIMSGRETENTIONSETTINGS +protected: + nsMsgRetainByPreference m_retainByPreference; + PRUint32 m_daysToKeepHdrs; + PRUint32 m_numHeadersToKeep; + PRUint32 m_keepUnreadMessagesProp; + PRBool m_keepUnreadMessagesOnly; + PRUint32 m_daysToKeepBodies; +}; + #endif diff --git a/mailnews/db/msgdb/public/nsNewsDatabase.h b/mailnews/db/msgdb/public/nsNewsDatabase.h index de18f4bf08e..6c4fadec151 100644 --- a/mailnews/db/msgdb/public/nsNewsDatabase.h +++ b/mailnews/db/msgdb/public/nsNewsDatabase.h @@ -50,7 +50,7 @@ public: // methods to get and set docsets for ids. NS_IMETHOD IsRead(nsMsgKey key, PRBool *pRead); - NS_IMETHOD IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead); + virtual nsresult IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead); virtual PRBool IsArticleOffline(nsMsgKey key); virtual nsresult AddHdrFromXOver(const char * line, nsMsgKey *msgId); diff --git a/mailnews/db/msgdb/src/nsMsgDatabase.cpp b/mailnews/db/msgdb/src/nsMsgDatabase.cpp index bc82bda8075..b053d3fd58e 100644 --- a/mailnews/db/msgdb/src/nsMsgDatabase.cpp +++ b/mailnews/db/msgdb/src/nsMsgDatabase.cpp @@ -812,7 +812,7 @@ NS_IMETHODIMP nsMsgDatabase::Open(nsIFileSpec *folderName, PRBool create, PRBool // Open the MDB database synchronously. If successful, this routine // will set up the m_mdbStore and m_mdbEnv of the database object // so other database calls can work. -NS_IMETHODIMP nsMsgDatabase::OpenMDB(const char *dbName, PRBool create) +nsresult nsMsgDatabase::OpenMDB(const char *dbName, PRBool create) { nsresult ret = NS_OK; nsIMdbFactory *myMDBFactory = GetMDBFactory(); @@ -928,7 +928,7 @@ NS_IMETHODIMP nsMsgDatabase::OpenMDB(const char *dbName, PRBool create) return ret; } -NS_IMETHODIMP nsMsgDatabase::CloseMDB(PRBool commit) +nsresult nsMsgDatabase::CloseMDB(PRBool commit) { if (commit) Commit(nsMsgDBCommitType::kSessionCommit); @@ -1467,7 +1467,7 @@ PRUint32 nsMsgDatabase::GetStatusFlags(nsIMsgDBHdr *msgHdr, PRUint32 origFlags) return statusFlags; } -NS_IMETHODIMP nsMsgDatabase::IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead) +nsresult nsMsgDatabase::IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead) { if (!msgHdr) return NS_MSG_MESSAGE_NOT_FOUND; @@ -1541,7 +1541,7 @@ PRBool nsMsgDatabase::SetHdrReadFlag(nsIMsgDBHdr *msgHdr, PRBool bRead) return SetHdrFlag(msgHdr, bRead, MSG_FLAG_READ); } -NS_IMETHODIMP nsMsgDatabase::MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead, +nsresult nsMsgDatabase::MarkHdrReadInDB(nsIMsgDBHdr *msgHdr, PRBool bRead, nsIDBChangeListener *instigator) { nsresult rv; @@ -2453,7 +2453,7 @@ nsMsgUnreadFilter(nsIMsgDBHdr* msg, void* closure) return !wasRead ? NS_OK : NS_COMFALSE; } -NS_IMETHODIMP +nsresult nsMsgDatabase::EnumerateUnreadMessages(nsISimpleEnumerator* *result) { nsMsgDBEnumerator* e = new nsMsgDBEnumerator(this, nsMsgUnreadFilter, this); @@ -3137,7 +3137,7 @@ NS_IMETHODIMP nsMsgDatabase::GetThreadContainingMsgHdr(nsIMsgDBHdr *msgHdr, nsIM } -NS_IMETHODIMP nsMsgDatabase::GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result) +nsresult nsMsgDatabase::GetThreadForMsgKey(nsMsgKey msgKey, nsIMsgThread **result) { nsresult ret = NS_OK; if (!result) @@ -3372,4 +3372,152 @@ nsresult nsMsgDatabase::DumpThread(nsMsgKey threadId) } #endif /* DEBUG */ +NS_IMETHODIMP nsMsgDatabase::SetMsgRetentionSettings(nsIMsgRetentionSettings *retentionSettings) +{ + m_retentionSettings = retentionSettings; + if (retentionSettings && m_dbFolderInfo) + { + nsresult rv; + + nsMsgRetainByPreference retainByPreference; + PRUint32 daysToKeepHdrs; + PRUint32 numHeadersToKeep; + PRBool keepUnreadMessagesOnly; + PRUint32 daysToKeepBodies; + + rv = retentionSettings->GetRetainByPreference(&retainByPreference); + NS_ENSURE_SUCCESS(rv, rv); + rv = retentionSettings->GetDaysToKeepHdrs(&daysToKeepHdrs); + NS_ENSURE_SUCCESS(rv, rv); + rv = retentionSettings->GetNumHeadersToKeep(&numHeadersToKeep); + NS_ENSURE_SUCCESS(rv, rv); + rv = retentionSettings->GetKeepUnreadMessagesOnly(&keepUnreadMessagesOnly); + NS_ENSURE_SUCCESS(rv, rv); + rv = retentionSettings->GetDaysToKeepBodies(&daysToKeepBodies); + NS_ENSURE_SUCCESS(rv, rv); + // need to write this to the db. We'll just use the dbfolderinfo to write properties. + m_dbFolderInfo->SetUint32Property("retainBy", retainByPreference); + m_dbFolderInfo->SetUint32Property("daysToKeepHdrs", daysToKeepHdrs); + m_dbFolderInfo->SetUint32Property("numHdrsToKeep", numHeadersToKeep); + m_dbFolderInfo->SetUint32Property("daysToKeepBodies", daysToKeepBodies); + m_dbFolderInfo->SetUint32Property("keepUnreadOnly", (keepUnreadMessagesOnly) ? 1 : 0); + } + return NS_OK; +} + +NS_IMETHODIMP nsMsgDatabase::GetMsgRetentionSettings(nsIMsgRetentionSettings **retentionSettings) +{ + NS_ENSURE_ARG_POINTER(retentionSettings); + if (!m_retentionSettings) + { + // create a new one, and initialize it from the db. + m_retentionSettings = new nsMsgRetentionSettings; + if (m_retentionSettings && m_dbFolderInfo) + { + nsresult rv; + + nsMsgRetainByPreference retainByPreference; + PRUint32 daysToKeepHdrs = 0; + PRUint32 numHeadersToKeep = 0; + PRUint32 keepUnreadMessagesProp = 0; + PRBool keepUnreadMessagesOnly = PR_FALSE; + PRUint32 daysToKeepBodies = 0; + + rv = m_dbFolderInfo->GetUint32Property("retainBy", &retainByPreference); + m_dbFolderInfo->GetUint32Property("daysToKeepHdrs", &daysToKeepHdrs); + m_dbFolderInfo->GetUint32Property("numHdrsToKeep", &numHeadersToKeep); + m_dbFolderInfo->GetUint32Property("daysToKeepBodies", &daysToKeepBodies); + m_dbFolderInfo->GetUint32Property("keepUnreadOnly", &keepUnreadMessagesProp); + keepUnreadMessagesOnly = (keepUnreadMessagesProp == 1); + m_retentionSettings->SetRetainByPreference(retainByPreference); + m_retentionSettings->SetDaysToKeepHdrs(daysToKeepHdrs); + m_retentionSettings->SetNumHeadersToKeep(numHeadersToKeep); + m_retentionSettings->SetKeepUnreadMessagesOnly(keepUnreadMessagesOnly); + m_retentionSettings->SetDaysToKeepBodies(daysToKeepBodies); + } + } + *retentionSettings = m_retentionSettings; + NS_IF_ADDREF(*retentionSettings); + return NS_OK; +} + +NS_IMPL_ISUPPORTS1(nsMsgRetentionSettings, nsIMsgRetentionSettings) + +nsMsgRetentionSettings::nsMsgRetentionSettings() +{ + NS_INIT_ISUPPORTS(); +} + +nsMsgRetentionSettings::~nsMsgRetentionSettings() +{ +} + +/* attribute unsigned long retainByPreference */ + +NS_IMETHODIMP nsMsgRetentionSettings::GetRetainByPreference(nsMsgRetainByPreference *retainByPreference) +{ + NS_ENSURE_ARG_POINTER(retainByPreference); + *retainByPreference = m_retainByPreference; + return NS_OK; +} + +NS_IMETHODIMP nsMsgRetentionSettings::SetRetainByPreference(nsMsgRetainByPreference retainByPreference) +{ + m_retainByPreference = retainByPreference; + return NS_OK; +} + +/* attribute long daysToKeepHdrs; */ +NS_IMETHODIMP nsMsgRetentionSettings::GetDaysToKeepHdrs(PRUint32 *aDaysToKeepHdrs) +{ + NS_ENSURE_ARG_POINTER(aDaysToKeepHdrs); + *aDaysToKeepHdrs = m_daysToKeepHdrs; + return NS_OK; +} + +NS_IMETHODIMP nsMsgRetentionSettings::SetDaysToKeepHdrs(PRUint32 aDaysToKeepHdrs) +{ + m_daysToKeepHdrs = aDaysToKeepHdrs; + return NS_OK; +} + +/* attribute long numHeadersToKeep; */ +NS_IMETHODIMP nsMsgRetentionSettings::GetNumHeadersToKeep(PRUint32 *aNumHeadersToKeep) +{ + NS_ENSURE_ARG_POINTER(aNumHeadersToKeep); + *aNumHeadersToKeep = m_numHeadersToKeep; + return NS_OK; +} +NS_IMETHODIMP nsMsgRetentionSettings::SetNumHeadersToKeep(PRUint32 aNumHeadersToKeep) +{ + m_numHeadersToKeep = aNumHeadersToKeep; + return NS_OK; +} + +/* attribute boolean keepUnreadMessagesOnly; */ +NS_IMETHODIMP nsMsgRetentionSettings::GetKeepUnreadMessagesOnly(PRBool *aKeepUnreadMessagesOnly) +{ + NS_ENSURE_ARG_POINTER(aKeepUnreadMessagesOnly); + *aKeepUnreadMessagesOnly = m_keepUnreadMessagesOnly; + return NS_OK; +} +NS_IMETHODIMP nsMsgRetentionSettings::SetKeepUnreadMessagesOnly(PRBool aKeepUnreadMessagesOnly) +{ + m_keepUnreadMessagesOnly = aKeepUnreadMessagesOnly; + return NS_OK; +} + +/* attribute long daysToKeepBodies; */ +NS_IMETHODIMP nsMsgRetentionSettings::GetDaysToKeepBodies(PRUint32 *aDaysToKeepBodies) +{ + NS_ENSURE_ARG_POINTER(aDaysToKeepBodies); + *aDaysToKeepBodies = m_daysToKeepBodies; + return NS_OK; +} +NS_IMETHODIMP nsMsgRetentionSettings::SetDaysToKeepBodies(PRUint32 aDaysToKeepBodies) +{ + m_daysToKeepBodies = aDaysToKeepBodies; + return NS_OK; +} + diff --git a/mailnews/db/msgdb/src/nsNewsDatabase.cpp b/mailnews/db/msgdb/src/nsNewsDatabase.cpp index d5a3ba85813..7c9c6ca1355 100644 --- a/mailnews/db/msgdb/src/nsNewsDatabase.cpp +++ b/mailnews/db/msgdb/src/nsNewsDatabase.cpp @@ -173,7 +173,7 @@ NS_IMETHODIMP nsNewsDatabase::IsRead(nsMsgKey key, PRBool *pRead) return NS_OK; } -NS_IMETHODIMP nsNewsDatabase::IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead) +nsresult nsNewsDatabase::IsHeaderRead(nsIMsgDBHdr *msgHdr, PRBool *pRead) { nsresult rv; nsMsgKey messageKey;