fix check_email_thread to do proper threading, take delay as arg

This commit is contained in:
craigerl 2020-12-03 14:48:27 -08:00
parent f175f7e6e3
commit e171e16854
1 changed files with 61 additions and 60 deletions

View File

@ -232,13 +232,12 @@ def resend_email(count, fromcall):
# end resend_email()
def check_email_thread():
# print "Email thread disabled."
# return
def check_email_thread(check_email_delay):
LOG.debug("Starting Email thread")
# how do we skip first run?
threading.Timer(55, check_email_thread).start()
while True:
# threading.Timer(55, check_email_thread).start()
time.sleep(check_email_delay)
shortcuts = CONFIG['shortcuts']
# swap key/value
@ -259,10 +258,9 @@ def check_email_thread():
server.login(CONFIG['imap']['login'], CONFIG['imap']['password'])
except Exception:
LOG.exception("Failed to login with IMAP server")
return
#return
continue
# if 'gmail' in CONFIG['imap']['host'].lower():
# server.select_folder('INBOX')
server.select_folder('INBOX')
messages = server.search(['SINCE', today])
@ -300,6 +298,7 @@ def check_email_thread():
server.remove_flags(msgid, [SEEN])
server.logout()
# end check_email()
@ -498,7 +497,9 @@ def main(args=args):
time.sleep(2)
check_email_thread() # start email reader thread
check_email_delay = 60 # initial email check interval
checkemailthread = threading.Thread(target=check_email_thread, args=(check_email_delay, )) # args must be tuple
checkemailthread.start()
LOG.info("Start main loop")
while True: