Headers encoding corrected and cache version validation added
[imap-fix-internaldate] / caching_data.py
index 17ecf5b..cde1a19 100644 (file)
@@ -20,6 +20,7 @@ import logging
 from mailbox_state import MailboxState
 
 CACHE_FILENAME = "message_cache.dat"
+CACHE_VERSION = 1
 
 class CachingData:
     """This class is responsible for the caching of data."""
@@ -36,10 +37,14 @@ class CachingData:
         try:
             cachefile = open(CACHE_FILENAME, 'rb')
             self.version, self.data = pickle.load(cachefile)
+            if(self.version != CACHE_VERSION):
+                logging.warning("Cache file has version %s and the script version is %s.",
+                                self.version, self.data)
+                raise IOError
             logging.info("Cache version %s", self.version)
             logging.debug("%s users found.", len(self.data))
         except IOError:
-            self.version = 0
+            self.version = CACHE_VERSION
             self.data = {}
             with open(CACHE_FILENAME, 'wb') as cachefile:
                 pickle.dump((0, self.data), cachefile)
@@ -70,7 +75,6 @@ class CachingData:
                 return
             
             # serialize in file
-            self.version += 1
             pickle.dump((self.version, self.data), cachefile)
             logging.debug("%s users stored.", len(self.data))
             cachefile.close()