Arguments parser added, conf file clarifications
authorPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 27 Jun 2012 13:15:28 +0000 (15:15 +0200)
committerPlamen Dimitrov <plamen.dimitrov@intra2net.com>
Wed, 27 Jun 2012 13:28:10 +0000 (15:28 +0200)
confscript.cfg
fix_imap_internaldate.py
mailbox_state.py

index a9ee033..e287aa8 100644 (file)
@@ -1,4 +1,5 @@
 [basic_settings]
+# 0 NOTSET, 10 DEBUG, 20 INFO, 30 WARNING, 40 ERROR, 50 CRITICAL 
 file_log_level = 20
 console_log_level = 20
 imap_server = intranator.m.i2n
index 30ee148..c14fbce 100644 (file)
@@ -24,28 +24,15 @@ from mail_iterator import MailIterator
 from caching_data import CachingData
 
 def main():
-    """Iterates through csv list of users and their mailboxes"""
-    
-    """parser = argparse.ArgumentParser(description='Fix the INTERNALDATE field on IMAP servers.')
-    parser.add_argument('--h', metavar='N', type=int, nargs='+',
-                       help='an integer for the accumulator')
-    parser.add_argument('--u', dest='accumulate', type=bool,
-                       const=sum, default=max,
-                       help='sum the integers (default: find the max)')
+    """Iterates through csv list of users and synchronize their messages"""
+
+    parser = argparse.ArgumentParser(description="Fix the INTERNALDATE field on IMAP servers. "
+                                                "Small tool to fix the IMAP internaldate "
+                                                "in case it's too much off compared to the last date "
+                                                "stored in the received lines.")
+    parser.add_argument('-u', '--update', dest='test_mode', action='store_false',
+                        default=True, help='update all e-mails and exit test mode')
     args = parser.parse_args()
-    print(args.accumulate(args.integers))"""
-
-    if(len(sys.argv) > 1):
-        if(sys.argv[1]=="--h"):
-            print("The default mode of the script is test mode."
-                  "Add '--u' argument to exit to modify messages."
-                  "For a detailed list of each message with a date conflict change"
-                  "change the 'log_level' in the configuration file from '30' to '20'.")
-            return
-        if(sys.argv[1]=="--u"):
-            test_mode = False
-    else:
-        test_mode = True
 
     # config and logging setup
     config = load_configuration()
@@ -54,6 +41,10 @@ def main():
     date_parser = MailDateParser()
     caching_data = CachingData()
     logging.warning("Cache version %s loaded.", caching_data.version)
+    if(args.test_mode):
+        logging.info("Testing mode initiated.")
+    else:
+        logging.info("Update mode initiated.")
     user_reader = csv.DictReader(open("userdata.csv", "r"), delimiter=',')
 
     # server name is stored in the config
@@ -92,7 +83,7 @@ def main():
                     continue
                 if(date_parser.compare_dates(received_date, internal_date, tolerance)):
                     #print(received_date, internal_date)
-                    if(test_mode==0):
+                    if(args.test_mode==0):
                         try:
                             session.update_message(mid, box.name, received_date)
                         except UserWarning as ex:
@@ -107,7 +98,7 @@ def main():
                     # count total emails for every user and mailbox
                     box.date_conflicts += 1
             # if all messages were successfully fixed confirm caching
-            if(not test_mode):
+            if(not args.test_mode):
                 box.confirm_change()
 
         # final report on date conflicts
@@ -148,5 +139,7 @@ def prepare_logger(config):
     logging.getLogger('').addHandler(console)
     return
 
+
+
 if(__name__ == "__main__"):
     main()
index a786e32..2d1e3af 100644 (file)
@@ -92,6 +92,7 @@ class MailboxState:
         # cache is invalid if mailbox is synced with different tolerance
         if(len(self.uids)==0 or tolerance != self.tolerance):
             new_ids = list_ids
+            self.tolerance = tolerance
         else:
             for uid in list_ids:
                 try:
@@ -102,8 +103,7 @@ class MailboxState:
         self.uids = list_ids
         return new_ids
 
-    def confirm_change(self, tolerance):
+    def confirm_change(self):
         """Confirm the chages to the cached mailbox and specify used tolerance."""
         self.needs_save = True
-        self.tolerance = tolerance
         return