Skip to content

Commit

Permalink
Removing interval loop. This shouldn't be the responsibility of this …
Browse files Browse the repository at this point in the history
…tool as its use-case dependent.
  • Loading branch information
jamesridgway committed Sep 28, 2024
1 parent 24d532a commit 31a675e
Showing 1 changed file with 29 additions and 36 deletions.
65 changes: 29 additions & 36 deletions bin/attachment-downloader
Original file line number Diff line number Diff line change
Expand Up @@ -196,49 +196,42 @@ if __name__ == '__main__':

password = options.password if options.password else get_password()

while True:
logging.info("Logging in to: '%s' as '%s'", options.host, options.username)
mail = Imbox(options.host,
username=options.username,
password=password,
port=options.port,
ssl=tls,
ssl_context=ssl.create_default_context(),
starttls=starttls)

logging.info("Logging in to: '%s' as '%s'", options.host, options.username)
mail = Imbox(options.host,
username=options.username,
password=password,
port=options.port,
ssl=tls,
ssl_context=ssl.create_default_context(),
starttls=starttls)
logging.info("Logged in to: '%s' as '%s'", options.host, options.username)

logging.info("Logged in to: '%s' as '%s'", options.host, options.username)
folders = []

folders = []

if options.imap_folder:
folders = [options.imap_folder]
else:
status, folders = mail.folders()
folders = [folder.decode().split(" \"/\" ")[1] for folder in folders]
folders = [f for f in folders if not f == '"[Gmail]"']

logging.info("Folders: %s", folders)
for folder in folders:
filter_options = build_filter_options()
if options.imap_folder:
folders = [options.imap_folder]
else:
status, folders = mail.folders()
folders = [folder.decode().split(" \"/\" ")[1] for folder in folders]
folders = [f for f in folders if not f == '"[Gmail]"']

try:
messages = mail.messages(**filter_options)
logging.info("Folders: %s", folders)
for folder in folders:
filter_options = build_filter_options()

for (uid, message) in messages:
process_message(filename_template, options, message)
except Exception as e:
logging.error("Failed to process messages for folder '%s'", folder)
logging.exception(e)
try:
messages = mail.messages(**filter_options)

logging.info('Finished processing messages')
for (uid, message) in messages:
process_message(filename_template, options, message)
except Exception as e:
logging.error("Failed to process messages for folder '%s'", folder)
logging.exception(e)

logging.info('Logging out of: %s', options.host)
mail.logout()
logging.info('Finished processing messages')

if os.getenv("AD_INTERVAL") is None:
break
else:
time.sleep(int(os.getenv("AD_INTERVAL")))
logging.info('Logging out of: %s', options.host)
mail.logout()

logging.info("Done")

0 comments on commit 31a675e

Please sign in to comment.