diff --git a/README.md b/README.md index 3fd5724..c6fa08b 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ No viewer yet, but the database is organized to do so. Does not support differen 4. Edit `config.yml` and configure your login info. 5. `python3 run.py` -A systemd service is included. +A sample systemd service file is included. ## To Do diff --git a/iarchiver/mail.py b/iarchiver/mail.py index 9c56552..7935b93 100644 --- a/iarchiver/mail.py +++ b/iarchiver/mail.py @@ -2,6 +2,8 @@ import concurrent.futures import email import hashlib import imaplib +import logging +import sys import time from email.header import decode_header from email.utils import parsedate_to_datetime @@ -42,6 +44,8 @@ class MailConnection: self.mail.login(username, password) self.attachments_dir = attachments_dir.expanduser().absolute().resolve() self.folder_structure = {} + self.logger = logging.getLogger('iarchiver.mail') + self.logger.setLevel(logging.INFO) def load_folders(self): folders = [tuple(f.decode().split(' "/" ')[1].replace('"', '').split('/')) for f in self.mail.list()[1]] @@ -59,7 +63,11 @@ class MailConnection: if data[0] is None: return raw_email_bytes = data[0][1] - detected = chardet.detect(raw_email_bytes) + try: + detected = chardet.detect(raw_email_bytes) + except TypeError as e: + self.logger.critical(f'Failed to decode an email. Timeout? - {e}') + sys.exit(1) encoding = detected['encoding'] if not encoding: encoding = 'utf-8'