detect timeout?

This commit is contained in:
Cyberes 2024-03-06 00:04:11 -07:00
parent 878ec708e1
commit c3e6e68bb6
2 changed files with 10 additions and 2 deletions

View File

@ -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

View File

@ -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]
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'