from mail_iterator import MailIterator
from caching_data import CachingData
+CONFIG_FILENAME = "fix_imap_internaldate.cfg"
+LOG_FILENAME = "fix_imap_internaldate.log"
+CSV_FILENAME = "userdata.csv"
+
def main():
"""Interprets command arguments and initializes configuration and logger.
Then begins mail synchronization."""
def load_configuration():
"""Loads the script configuration from a file or creates such."""
config = configparser.RawConfigParser()
- success = config.read('confscript.cfg')
+ success = config.read(CONFIG_FILENAME)
if(len(success)==0):
config.add_section('basic_settings')
config.set('basic_settings', 'file_log_level', logging.INFO)
config.set('basic_settings', 'console_log_level', logging.INFO)
config.set('basic_settings', 'imap_server', 'imap.company.com')
config.set('basic_settings', 'tolerance', 30)
- with open('confscript.cfg', 'w') as configfile:
+ with open(CONFIG_FILENAME, 'w') as configfile:
config.write(configfile)
configfile.write("# 0 NOTSET, 10 DEBUG, 20 INFO, 30 WARNING, 40 ERROR, 50 CRITICAL")
return config
def prepare_logger(config):
"""Sets up the logging functionality"""
-
+
# reset the log
- with open('fix_imap_internaldate.log', 'w'):
+ with open(LOG_FILENAME, 'w'):
pass
-
+
# add basic configuration
- logging.basicConfig(filename='fix_imap_internaldate.log',
+ logging.basicConfig(filename=LOG_FILENAME,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=config.getint('basic_settings', 'file_log_level'))
-
+
# add a handler for a console output
console = logging.StreamHandler()
console.setLevel(config.getint('basic_settings', 'console_log_level'))
tolerance = config.getint('basic_settings', 'tolerance') * 60
# iterate through the users in the csv data
- user_reader = csv.DictReader(open("userdata.csv", "r"), delimiter=',')
+ user_reader = csv.DictReader(open(CSV_FILENAME, "r"), delimiter=',')
for user in user_reader:
try:
session = MailIterator(server, user['username'], user['password'])
# if all messages were successfully fixed confirm caching
if(not test_mode):
box.confirm_change()
-
+
# final report on date conflicts
caching_data.report_conflicts()
return