Tolerance cache validation added
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 27 Jun 2012 12:23:17 +0000 (14:23 +0200)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 27 Jun 2012 13:28:10 +0000 (15:28 +0200)
caching_data.py
fix_imap_internaldate.py
mailbox_state.py

index cde1a19..e40c3c3 100644 (file)
@@ -93,7 +93,7 @@ class CachingData:
             logging.debug("New mailbox %s cached.", box_key)
         return self.data[user][box_key]
     
-    def report_date_conflicts(self):
+    def report_conflicts(self):
         """Write a date conflicts report in a file."""
         with open("conflict_stats.txt", 'w') as statsfile:
             owner_total_conflicts = {}
index 5ac1d5c..30ee148 100644 (file)
@@ -55,7 +55,7 @@ def main():
     caching_data = CachingData()
     logging.warning("Cache version %s loaded.", caching_data.version)
     user_reader = csv.DictReader(open("userdata.csv", "r"), delimiter=',')
-    
+
     # server name is stored in the config
     server = config.get('basic_settings', 'imap_server')
     # tolerance is now in seconds
@@ -71,7 +71,7 @@ def main():
             try:
                 box = caching_data.retrieve_cached_mailbox(mailbox[0], mailbox[1], user['username'])
                 mail_ids = session.fetch_messages()
-                new_ids = box.synchronize(mail_ids)
+                new_ids = box.synchronize(mail_ids, tolerance)
                 logging.info("%s new messages out of %s found in %s.", len(new_ids), len(mail_ids), box.name)
             except UserWarning as ex:
                 logging.error(ex)
@@ -111,7 +111,7 @@ def main():
                 box.confirm_change()
 
         # final report on date conflicts
-        caching_data.report_date_conflicts()
+        caching_data.report_conflicts()
 
 def load_configuration():
     """Loads the script configuration from a file or creates such."""
index e38c584..a786e32 100644 (file)
@@ -27,6 +27,8 @@ class MailboxState:
     owner = None
     # list of bytes for last cached mail uids
     uids = None
+    # tolerance with which the mailbox was synced
+    tolerance = None
     # boolean flag for committing state changes
     needs_save = None
     # integer for found date conflicts
@@ -42,6 +44,7 @@ class MailboxState:
         self.owner = owner
 
         self.uids = []
+        self.tolerance = 0
         self.needs_save = False
 
         self.date_conflicts = 0
@@ -68,6 +71,7 @@ class MailboxState:
         self.owner = dict["owner"]
 
         self.uids = dict["uids"]
+        self.tolerance = dict["tolerance"]
         self.needs_save = False
 
         self.date_conflicts = 0
@@ -81,11 +85,12 @@ class MailboxState:
         """Makes the class printable."""
         return self.key
 
-    def synchronize(self, list_ids):
+    def synchronize(self, list_ids, tolerance):
         """Adds new messages to the cache and returns a list of them.
         Confirm the changes to a mailbox to finally save it."""
         new_ids = []
-        if(len(self.uids)==0):
+        # cache is invalid if mailbox is synced with different tolerance
+        if(len(self.uids)==0 or tolerance != self.tolerance):
             new_ids = list_ids
         else:
             for uid in list_ids:
@@ -97,7 +102,8 @@ class MailboxState:
         self.uids = list_ids
         return new_ids
 
-    def confirm_change(self):
-        """Confirm the chages to the cached mailbox."""
+    def confirm_change(self, tolerance):
+        """Confirm the chages to the cached mailbox and specify used tolerance."""
         self.needs_save = True
+        self.tolerance = tolerance
         return