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()
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
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:
# 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
logging.getLogger('').addHandler(console)
return
+
+
if(__name__ == "__main__"):
main()