qol stuff

This commit is contained in:
Cyberes 2024-03-06 13:34:14 -07:00
parent 8643fd247a
commit ebadffecc4
3 changed files with 9 additions and 6 deletions

View File

@ -1,6 +1,6 @@
# https://support.google.com/mail/answer/7190?hl=en # https://support.google.com/mail/answer/7190?hl=en
gmail_categories = [ gmail_categories = [
# 'category:primary', 'category:primary',
'category:social', 'category:social',
'category:promotions', 'category:promotions',
'category:updates', 'category:updates',

View File

@ -52,7 +52,7 @@ class MailConnection:
try: try:
detected = chardet.detect(raw_email_bytes) detected = chardet.detect(raw_email_bytes)
except TypeError as e: except TypeError as e:
self.logger.critical(f'Failed to decode an email. Timeout? - {e}') self.logger.critical(f'Failed to decode an email. Timeout? Server error? - "{e}"')
sys.exit(1) sys.exit(1)
encoding = detected['encoding'] encoding = detected['encoding']
if not encoding: if not encoding:

11
main.py
View File

@ -39,6 +39,12 @@ def main(args):
num_folders_to_sync = len(mail.folder_structure) num_folders_to_sync = len(mail.folder_structure)
logger.info(f'Syncing {num_folders_to_sync} folders...') logger.info(f'Syncing {num_folders_to_sync} folders...')
last_refresh = database.have_we_done_a_full_sync_at_all()
last_refresh_imap_date = None
if last_refresh:
last_refresh_imap_date = unix_timestamp_since_to_imap_timestamp(last_refresh)
logger.info(f'Syncing emails received after {last_refresh_imap_date}')
new_emails = 0 new_emails = 0
new_attachments = 0 new_attachments = 0
did_full_sync = False did_full_sync = False
@ -49,10 +55,8 @@ def main(args):
# Exclude folder # Exclude folder
continue continue
logger.info(folder_name) logger.info(folder_name)
last_refresh = database.have_we_done_a_full_sync_at_all()
if last_refresh: if last_refresh:
date = unix_timestamp_since_to_imap_timestamp(last_refresh) search_criterion = ['(SINCE "' + last_refresh_imap_date + '")']
search_criterion = ['(SINCE "' + date + '")']
else: else:
did_full_sync = True did_full_sync = True
search_criterion = ['ALL'] search_criterion = ['ALL']
@ -67,7 +71,6 @@ def main(args):
elapsed = datetime.now() - sync_start_time elapsed = datetime.now() - sync_start_time
database.finish_sync('refresh' if not did_full_sync else 'full', new_emails, new_attachments, int(elapsed.total_seconds())) database.finish_sync('refresh' if not did_full_sync else 'full', new_emails, new_attachments, int(elapsed.total_seconds()))
logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails and {new_attachments} attachments.') logger.info(f'Finished email {"refresh" if not did_full_sync else "sync"} in {humanize.naturaldelta(elapsed)} and added {new_emails} new emails and {new_attachments} attachments.')