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. 4. Edit `config.yml` and configure your login info.
5. `python3 run.py` 5. `python3 run.py`
A systemd service is included. A sample systemd service file is included.
## To Do ## To Do

View File

@ -2,6 +2,8 @@ import concurrent.futures
import email import email
import hashlib import hashlib
import imaplib import imaplib
import logging
import sys
import time import time
from email.header import decode_header from email.header import decode_header
from email.utils import parsedate_to_datetime from email.utils import parsedate_to_datetime
@ -42,6 +44,8 @@ class MailConnection:
self.mail.login(username, password) self.mail.login(username, password)
self.attachments_dir = attachments_dir.expanduser().absolute().resolve() self.attachments_dir = attachments_dir.expanduser().absolute().resolve()
self.folder_structure = {} self.folder_structure = {}
self.logger = logging.getLogger('iarchiver.mail')
self.logger.setLevel(logging.INFO)
def load_folders(self): def load_folders(self):
folders = [tuple(f.decode().split(' "/" ')[1].replace('"', '').split('/')) for f in self.mail.list()[1]] 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: if data[0] is None:
return return
raw_email_bytes = data[0][1] 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'] encoding = detected['encoding']
if not encoding: if not encoding:
encoding = 'utf-8' encoding = 'utf-8'