Tolerance cache validation added
[imap-fix-internaldate] / mailbox_state.py
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