diff --git a/iarchiver/mail.py b/iarchiver/mail.py index 7935b93..37a2965 100644 --- a/iarchiver/mail.py +++ b/iarchiver/mail.py @@ -44,7 +44,7 @@ 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 = logging.getLogger('iarchiver.mail_conn') self.logger.setLevel(logging.INFO) def load_folders(self): @@ -77,10 +77,21 @@ class MailConnection: date = parsedate_to_datetime(date_header) unix_timestamp = int(time.mktime(date.timetuple())) - from_header = ', '.join(extract_emails(email_message['From'])) - to_header = ', '.join(extract_emails(email_message['To'])) + from_addr = email_message['From'] + to_addr = email_message['To'] + if not from_addr and not to_addr: + return + if not from_addr: + from_addr = '' + if not to_addr: + to_addr = '' + + from_header = ', '.join(extract_emails(from_addr)) + to_header = ', '.join(extract_emails(to_addr)) + if '@' not in from_header: + from_header = from_addr if '@' not in to_header: - to_header = email_message['To'] + to_header = to_addr subject_header = email_message['Subject'] if subject_header: