From: Plamen Dimitrov Date: Wed, 27 Jun 2012 12:23:17 +0000 (+0200) Subject: Tolerance cache validation added X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=3b81023ffc458c8b906592daf089c127fbde4385;p=imap-fix-internaldate Tolerance cache validation added --- diff --git a/caching_data.py b/caching_data.py index cde1a19..e40c3c3 100644 --- a/caching_data.py +++ b/caching_data.py @@ -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 = {} diff --git a/fix_imap_internaldate.py b/fix_imap_internaldate.py index 5ac1d5c..30ee148 100644 --- a/fix_imap_internaldate.py +++ b/fix_imap_internaldate.py @@ -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.""" diff --git a/mailbox_state.py b/mailbox_state.py index e38c584..a786e32 100644 --- a/mailbox_state.py +++ b/mailbox_state.py @@ -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