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 = {}
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
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)
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."""
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
self.owner = owner
self.uids = []
+ self.tolerance = 0
self.needs_save = False
self.date_conflicts = 0
self.owner = dict["owner"]
self.uids = dict["uids"]
+ self.tolerance = dict["tolerance"]
self.needs_save = False
self.date_conflicts = 0
"""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:
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