make autosync date constraints be per-server, r/sr=standard8
authorDavid Bienvenu <bienvenu@nventure.com>
Tue, 01 Sep 2009 08:50:16 -0700
changeset 3476 7545b0d96cc7c896a05e738ed51155633512125e
parent 3475 9c1a3c3eaa80d09b41eb76e8b885dc5f4b36edc2
child 3477 75d76cb10bcec67d45f0c3e3ce8c0a111f9833f1
push idunknown
push userunknown
push dateunknown
make autosync date constraints be per-server, r/sr=standard8
mailnews/imap/public/nsIImapIncomingServer.idl
mailnews/imap/src/nsAutoSyncManager.cpp
mailnews/imap/src/nsAutoSyncManager.h
mailnews/imap/src/nsImapIncomingServer.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/imap/test/unit/test_autosync_date_constraints.js
mailnews/mailnews.js
--- a/mailnews/imap/public/nsIImapIncomingServer.idl
+++ b/mailnews/imap/public/nsIImapIncomingServer.idl
@@ -50,17 +50,17 @@ typedef long nsMsgImapDeleteModel;
 [scriptable, uuid(bbfc33de-fe89-11d3-a564-0060b0fc04b7)]
 interface nsMsgImapDeleteModels
 {
   const long IMAPDelete = 0;    /* delete with a big red x */
   const long MoveToTrash = 1;   /* delete moves message to the trash */
   const long DeleteNoTrash = 2; /* delete is shift delete - don't create or use trash */
 };
 
-[scriptable, uuid(99599429-f9ea-48d9-ab4a-a05ec2395f5c)]
+[scriptable, uuid(3b5ada31-561f-4a76-b1be-0b2bba8e9389)]
 interface nsIImapIncomingServer : nsISupports {
 
   attribute long maximumConnectionsNumber;
   attribute long timeOutLimits;
   attribute ACString adminUrl;
   attribute ACString serverDirectory;
   attribute long capabilityPref;
   attribute boolean cleanupInboxOnExit;
@@ -94,16 +94,20 @@ interface nsIImapIncomingServer : nsISup
   attribute boolean useCompressDeflate;
 
   attribute AString trashFolderName;
 
   boolean getIsPFC(in ACString folderName);
   nsIMsgFolder getPFC(in boolean createIfMissing);
   attribute boolean downloadBodiesOnGetNewMail;
   attribute boolean autoSyncOfflineStores;
+
+  /// Max age of messages we will autosync to, or keep in offline store.
+  attribute long autoSyncMaxAgeDays;
+
   void GetImapConnectionAndLoadUrl(in nsIEventTarget aClientEventTarget,
                                            in nsIImapUrl aImapUrl,
                                            in nsISupports aConsumer);
 
   void RemoveConnection(in nsIImapProtocol aImapConnection);
   void ResetNamespaceReferences();
   void pseudoInterruptMsgLoad(in nsIMsgFolder aImapFolder, in nsIMsgWindow aMsgWindow, out boolean interrupted);
   void ResetConnection(in ACString folderName);
--- a/mailnews/imap/src/nsAutoSyncManager.cpp
+++ b/mailnews/imap/src/nsAutoSyncManager.cpp
@@ -43,31 +43,24 @@
 #include "nsIMsgMailNewsUrl.h"
 #include "nsIMsgAccountManager.h"
 #include "nsIMsgIncomingServer.h"
 #include "nsIMsgMailSession.h"
 #include "nsMsgFolderFlags.h"
 #include "nsImapIncomingServer.h"
 #include "nsMsgUtils.h"
 #include "nsIIOService.h"
-#include "nsIPrefService.h"
 
 NS_IMPL_ISUPPORTS1(nsDefaultAutoSyncMsgStrategy, nsIAutoSyncMsgStrategy)
 
 const char* kAppIdleNotification = "mail:appIdle";
 const char* kStartupDoneNotification = "mail-startup-done";
 
 nsDefaultAutoSyncMsgStrategy::nsDefaultAutoSyncMsgStrategy()
 {
-  m_offlineMsgAgeLimit = -1;
-
-  // Check if we've limited the offline storage by age.
-  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (prefBranch)
-    prefBranch->GetIntPref("mail.autosync.max_age_days", &m_offlineMsgAgeLimit);
 }
 
 nsDefaultAutoSyncMsgStrategy::~nsDefaultAutoSyncMsgStrategy()
 {
 }
 
 NS_IMETHODIMP nsDefaultAutoSyncMsgStrategy::Sort(nsIMsgFolder *aFolder, 
   nsIMsgDBHdr *aMsgHdr1, nsIMsgDBHdr *aMsgHdr2, nsAutoSyncStrategyDecisionType *aDecision)
@@ -118,20 +111,29 @@ NS_IMETHODIMP nsDefaultAutoSyncMsgStrate
   return NS_OK;
 }
 
 NS_IMETHODIMP nsDefaultAutoSyncMsgStrategy::IsExcluded(nsIMsgFolder *aFolder, 
   nsIMsgDBHdr *aMsgHdr, PRBool *aDecision)
 {
   NS_ENSURE_ARG_POINTER(aDecision);
   NS_ENSURE_ARG_POINTER(aMsgHdr);
+  NS_ENSURE_ARG_POINTER(aFolder);
+  nsCOMPtr<nsIMsgIncomingServer> server;
+
+  nsresult rv = aFolder->GetServer(getter_AddRefs(server));
+  NS_ENSURE_SUCCESS(rv, rv);
+  nsCOMPtr<nsIImapIncomingServer> imapServer(do_QueryInterface(server, &rv));
+  PRInt32 offlineMsgAgeLimit = -1;
+  imapServer->GetAutoSyncMaxAgeDays(&offlineMsgAgeLimit);
+  NS_ENSURE_SUCCESS(rv, rv);
   PRInt64 msgDate;
   aMsgHdr->GetDate(&msgDate);
-  *aDecision = m_offlineMsgAgeLimit > 0 &&
-    msgDate < MsgConvertAgeInDaysToCutoffDate(m_offlineMsgAgeLimit);
+  *aDecision = offlineMsgAgeLimit > 0 &&
+    msgDate < MsgConvertAgeInDaysToCutoffDate(offlineMsgAgeLimit);
   return NS_OK;
 }
 
 NS_IMPL_ISUPPORTS1(nsDefaultAutoSyncFolderStrategy, nsIAutoSyncFolderStrategy)
 
 nsDefaultAutoSyncFolderStrategy::nsDefaultAutoSyncFolderStrategy()
 {
 }
--- a/mailnews/imap/src/nsAutoSyncManager.h
+++ b/mailnews/imap/src/nsAutoSyncManager.h
@@ -117,17 +117,16 @@ class nsDefaultAutoSyncMsgStrategy : pub
   public:
     NS_DECL_ISUPPORTS
     NS_DECL_NSIAUTOSYNCMSGSTRATEGY
 
     nsDefaultAutoSyncMsgStrategy();
 
   private:
     ~nsDefaultAutoSyncMsgStrategy();
-    PRInt32 m_offlineMsgAgeLimit;
 };
 
 /**
  * Default strategy implementation to prioritize folders in the download queue.  
  */
 class nsDefaultAutoSyncFolderStrategy : public nsIAutoSyncFolderStrategy
 {
   public:
--- a/mailnews/imap/src/nsImapIncomingServer.cpp
+++ b/mailnews/imap/src/nsImapIncomingServer.cpp
@@ -319,16 +319,19 @@ NS_IMPL_SERVERPREF_BOOL(nsImapIncomingSe
                         "use_condstore")
 
 NS_IMPL_SERVERPREF_BOOL(nsImapIncomingServer, IsGMailServer,
                         "is_gmail")
 
 NS_IMPL_SERVERPREF_BOOL(nsImapIncomingServer, UseCompressDeflate,
                         "use_compress_deflate")
 
+NS_IMPL_SERVERPREF_INT(nsImapIncomingServer, AutoSyncMaxAgeDays,
+                        "autosync_max_age_days")
+
 NS_IMETHODIMP
 nsImapIncomingServer::GetShuttingDown(PRBool *retval)
 {
   NS_ENSURE_ARG_POINTER(retval);
   *retval = m_shuttingDown;
   return NS_OK;
 }
 
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -1203,25 +1203,26 @@ NS_IMETHODIMP nsImapMailFolder::GetNoSel
   return GetFlag(nsMsgFolderFlags::ImapNoselect, aResult);
 }
 
 NS_IMETHODIMP nsImapMailFolder::ApplyRetentionSettings()
 {
   PRInt32 numDaysToKeepOfflineMsgs = -1;
 
   // Check if we've limited the offline storage by age.
-  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));
-  if (prefBranch)
-    prefBranch->GetIntPref("mail.autosync.max_age_days", &numDaysToKeepOfflineMsgs);
+  nsCOMPtr<nsIImapIncomingServer> imapServer;
+  nsresult rv = GetImapIncomingServer(getter_AddRefs(imapServer));
+  NS_ENSURE_SUCCESS(rv, rv);
+  imapServer->GetAutoSyncMaxAgeDays(&numDaysToKeepOfflineMsgs);
 
   nsCOMPtr<nsIMsgDatabase> holdDBOpen;
   if (numDaysToKeepOfflineMsgs > 0)
   {
     PRBool dbWasCached = mDatabase != nsnull;
-    nsresult rv = GetDatabase();
+    rv = GetDatabase();
     NS_ENSURE_SUCCESS(rv, rv);
     nsCOMPtr <nsISimpleEnumerator> hdrs;
     rv = mDatabase->EnumerateMessages(getter_AddRefs(hdrs));
     NS_ENSURE_SUCCESS(rv, rv);
     PRBool hasMore = PR_FALSE;
 
     PRTime cutOffDay =
       MsgConvertAgeInDaysToCutoffDate(numDaysToKeepOfflineMsgs);
--- a/mailnews/imap/test/unit/test_autosync_date_constraints.js
+++ b/mailnews/imap/test/unit/test_autosync_date_constraints.js
@@ -91,17 +91,17 @@ function run_test()
   prefBranch.setIntPref("mail.server.server1.max_cached_connections", 1);
   // Make sure no biff notifications happen
   prefBranch.setBoolPref("mail.biff.play_sound", false);
   prefBranch.setBoolPref("mail.biff.show_alert", false);
   prefBranch.setBoolPref("mail.biff.show_tray_icon", false);
   prefBranch.setBoolPref("mail.biff.animate_dock_icon", false);
   // We aren't interested in downloading messages automatically
   prefBranch.setBoolPref("mail.server.server1.download_on_biff", false);
-  prefBranch.setIntPref("mail.autosync.max_age_days", 4);
+  prefBranch.setIntPref("mail.server.server1.autosync_max_age_days", 4);
 
   // Get the server list...
   gIMAPIncomingServer.performExpand(null);
 
   gRootFolder = gIMAPIncomingServer.rootFolder;
   gIMAPInbox = gRootFolder.getChildNamed("INBOX");
   gMsgImapInboxFolder = gIMAPInbox.QueryInterface(Ci.nsIMsgImapMailFolder);
   // these hacks are required because we've created the inbox before
--- a/mailnews/mailnews.js
+++ b/mailnews/mailnews.js
@@ -522,17 +522,17 @@ pref("mail.server.default.inhibitWhiteLi
 // should we inhibit whitelisting of the domain for a server's identities?
 pref("mail.server.default.inhibitWhiteListingIdentityDomain", false);
 
 // to activate auto-sync feature (preemptive message download for imap) by default
 pref("mail.server.default.autosync_offline_stores",true);
 pref("mail.server.default.offline_download",true);
 
 // -1 means no limit, no purging of offline stores.
-pref("mail.autosync.max_age_days", -1);
+pref("mail.server.default.autosync_max_age_days", -1);
 
 pref("mail.server.default.archive_granularity", 1);
 // the probablilty threshold over which messages are classified as junk
 // this number is divided by 100 before it is used. The classifier can be fine tuned
 // by changing this pref. Typical values are .99, .95, .90, .5, etc.
 pref("mail.adaptivefilters.junk_threshold", 90);
 pref("mail.spam.version", 0); // used to determine when to migrate global spam settings
 pref("mail.spam.logging.enabled", false);