print "(at your option) any later version." print "This program is distributed in the hope that it will be useful," print "but WITHOUT ANY WARRANTY; without even the implied warranty of" print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" print "GNU General Public License for more details." print print "Libraries used:" print "html2text (c) 2012 Aaron Swartz (GPLv3)" print "requests_structures.py (c) The Requests Project (original Apachev2; any modifications GPLv3)" print print "This program is dedicated to the memory of Aaron Swartz." client.c_state = client.ClientState() #I no longer think this is needed, but just in case. client.cachedir = os.path.abspath(sys.argv[1]) client.initialize_account_info() client.password = open(os.path.join(client.cachedir,"settings")).readline().rstrip() client.ClientNetSync.connmanager = lambda(self): None nsync = client.ClientNetSync() #Local function to add all files in a folder to cache def folder_cache_add(folder): nsync.cache[folder]=[] for fname in os.listdir(os.path.join(client.cachedir,folder)): nsync.add_to_cache(folder+"/"+fname,open(os.path.join(client.cachedir,folder+"/"+fname)).read(),False) #If we have a pickle, use it; otherwise, read in all emails and parse them (slow) if os.path.isfile(client.cachedir+"/client.pickle"): nsync.cache = pickle.load(open(client.cachedir+"/client.pickle","rb")) else:
def main(): global msg_dict global nsync global l_timedep_tasks #Name of program and intro text print "MailTask Alpha: The Email Manager" print "(c) 2015 by Patrick Simmons" print print "This program is free software: you can redistribute it and/or modify" print "it under the terms of the GNU General Public License as published by" print "the Free Software Foundation, either version 3 of the License, or" print "(at your option) any later version." print "This program is distributed in the hope that it will be useful," print "but WITHOUT ANY WARRANTY; without even the implied warranty of" print "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the" print "GNU General Public License for more details." print print "Libraries used:" print "html2text (c) 2012 Aaron Swartz (GPLv3)" print "requests_structures.py (c) The Requests Project (original Apachev2; any modifications GPLv3)" print print "This program is dedicated to the memory of Aaron Swartz." client.c_state = client.ClientState() #I no longer think this is needed, but just in case. client.cachedir = os.path.abspath(".") client.initialize_account_info() client.password = open(os.path.join(client.cachedir,"settings")).readline().rstrip() msg_dict = Msg_Dict() nsync = client.ClientNetSync() #Local function to add all files in a folder to cache def folder_cache_add(folder,process_instead=False): if not process_instead: nsync.cache[folder]=[] for fname in os.listdir(os.path.join(client.cachedir,folder)): if not process_instead: nsync.add_to_cache(folder+"/"+fname,open(os.path.join(client.cachedir,folder+"/"+fname)).read(),False) else: msg_dict.process_msg(email.parser.Parser().parse(open(os.path.join(client.cachedir,folder+"/"+fname))),folder+"/"+fname) #If we have a pickle, use it; otherwise, read in all emails and parse them (slow) if os.path.isfile(client.cachedir+"/client.pickle"): nsync.cache = pickle.load(open(client.cachedir+"/client.pickle","rb")) if os.path.isfile(client.cachedir+"/l_timedep_tasks.pickle"): l_timedep_tasks = pickle.load(open(client.cachedir+"/l_timedep_tasks.pickle","rb")) else: #Add all account folders to cache for x in range(len(client.account_info)): folder_cache_add(repr(x)+"/INBOX") folder_cache_add(repr(x)+"/Sent") folder_cache_add("Tasks") if os.path.isfile(client.cachedir+"/msg_dict.pickle"): msg_dict = pickle.load(open(client.cachedir+"/msg_dict.pickle","rb")) else: for x in range(len(client.account_info)): folder_cache_add(repr(x)+"/INBOX",True) folder_cache_add(repr(x)+"/Sent",True) folder_cache_add("Tasks",True) nsync.initialize_cache() #email_info and ignored_senders initialize_email_info_and_ignored_senders_accounts() #Main loop last_timedep_check=0 startup_status=0 try: while True: while server_synchronize(): if len(nsync.server_update_queue) > 50 and (startup_status==0 or startup_status==2) or len(nsync.server_update_queue) < 40 and startup_status==1: startup_status+=1 if os.path.isfile(client.cachedir+"/FORCE_EXIT") or startup_status==3: pickle.dump(nsync.cache,open(client.cachedir+"/client.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(msg_dict,open(client.cachedir+"/msg_dict.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(l_timedep_tasks,open(client.cachedir+"/l_timedep_tasks.pickle","wb"),pickle.HIGHEST_PROTOCOL) if startup_status==3: print "FATAL: We appear to have lost our cmessage connection." sys.exit(0) time.sleep(5) if time.time()-last_timedep_check > 600: print "Performing timed pickle backup." sys.stdout.flush() do_timedep_check() last_timedep_check=time.time() if os.path.isfile(client.cachedir+"/client.pickle"): shutil.copyfile(client.cachedir+"/client.pickle",client.cachedir+"/client.pickle.bak") if os.path.isfile(client.cachedir+"/msg_dict.pickle"): shutil.copyfile(client.cachedir+"/msg_dict.pickle",client.cachedir+"/msg_dict.pickle.bak") if os.path.isfile(client.cachedir+"/l_timedep_tasks.pickle"): shutil.copyfile(client.cachedir+"/l_timedep_tasks.pickle",client.cachedir+"/l_timedep_tasks.pickle.bak") pickle.dump(nsync.cache,open(client.cachedir+"/client.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(msg_dict,open(client.cachedir+"/msg_dict.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(l_timedep_tasks,open(client.cachedir+"/l_timedep_tasks.pickle","wb"),pickle.HIGHEST_PROTOCOL) except Exception as e: pickle.dump(nsync.cache,open(client.cachedir+"/client.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(msg_dict,open(client.cachedir+"/msg_dict.pickle","wb"),pickle.HIGHEST_PROTOCOL) pickle.dump(l_timedep_tasks,open(client.cachedir+"/l_timedep_tasks.pickle","wb"),pickle.HIGHEST_PROTOCOL) print "Failed with exception: "+repr(e) sys.stdout.flush()