diff options
Diffstat (limited to 'service/app/adapter/mail_converter.py')
-rw-r--r-- | service/app/adapter/mail_converter.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/service/app/adapter/mail_converter.py b/service/app/adapter/mail_converter.py index a77fcdb7..cf793a7a 100644 --- a/service/app/adapter/mail_converter.py +++ b/service/app/adapter/mail_converter.py @@ -1,11 +1,33 @@ +import dateutil.parser as dateparser + class MailConverter: def __init__(self, mail_service): pass + def date_to_iso(self, date): + return dateparser.parse(date).isoformat() + def from_mail(self, imap_mail): - return inbox_mail + headers = imap_mail.hdoc.content['headers'] + body = imap_mail.bdoc.content + + return { + 'header': { + 'from': [headers['From']], + 'to': [headers['To']], + 'cc': headers.get('CC', []), + 'bcc': headers.get('BCC', []), + 'date': self.date_to_iso(headers['Date']), + 'subject': headers['Subject'] + }, + 'ident': imap_mail.getUID(), + 'tags': imap_mail.getFlags(), + 'status': [], + 'security_casing': {}, + 'body': body['raw'] + } def to_mail(self, pixelated_mail, account): raise NotImplementedError() |