summaryrefslogtreecommitdiff
path: root/service/app/adapter/mail_converter.py
blob: cf793a7af35083d8dd142dd17ab7aa65331859f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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):

        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()


    def from_tag(self, imap_tag):
        raise NotImplementedError()


    def from_contact(self, imap_contact):
        raise NotImplementedError()