|
@@ -37,7 +37,8 @@ def decode_mail(msg: Message)-> dict:
|
37
|
37
|
mail_data['from'] = parseaddr(msg['From'])[1]
|
38
|
38
|
# Reply key
|
39
|
39
|
mail_data['to'] = parseaddr(msg['To'])[1]
|
40
|
|
-
|
|
40
|
+ # INFO - G.M - 2017-11-15
|
|
41
|
+ # We only need to save the first/oldest addr of references
|
41
|
42
|
mail_data['references'] = parseaddr(msg['References'])[1]
|
42
|
43
|
if TRACIM_SPECIAL_KEY_HEADER in msg:
|
43
|
44
|
mail_data[TRACIM_SPECIAL_KEY_HEADER] = str_header(msg[TRACIM_SPECIAL_KEY_HEADER]) # nopep8
|
|
@@ -50,11 +51,13 @@ def decode_mail(msg: Message)-> dict:
|
50
|
51
|
)
|
51
|
52
|
|
52
|
53
|
except Exception:
|
53
|
|
- # FIXME - G.M - 2017-15-11 - handle exceptions correctly
|
|
54
|
+ # FIXME - G.M - 2017-11-15 - handle exceptions correctly
|
54
|
55
|
return {}
|
55
|
|
- # FIXME - G.M - 2017-15-11 - get the best body candidate in MIME
|
|
56
|
+ # FIXME - G.M - 2017-11-15 - get the best body candidate in MIME
|
56
|
57
|
# msg.get_body() look like the best way to get body but it's a py3.6 feature
|
57
|
58
|
for part in msg.walk():
|
|
59
|
+ # TODO - G.M - 2017-11-15 - Handle HTML mail body
|
|
60
|
+ # TODO - G.M - 2017-11-15 - Parse properly HTML (and text ?) body
|
58
|
61
|
if not part.get_content_type() == "text/plain":
|
59
|
62
|
continue
|
60
|
63
|
else:
|
|
@@ -100,8 +103,22 @@ def find_key_from_mail_adress(mail_address: str) -> typing.Optional[str]:
|
100
|
103
|
|
101
|
104
|
class MailFetcher(object):
|
102
|
105
|
|
103
|
|
- def __init__(self, host, port, user, password, folder, delay, endpoint) \
|
|
106
|
+ def __init__(self,
|
|
107
|
+ host: str, port: str, user: str, password: str, folder: str,
|
|
108
|
+ delay: int, endpoint: str) \
|
104
|
109
|
-> None:
|
|
110
|
+ """
|
|
111
|
+ Fetch mail from a mailbox folder through IMAP and add their content to
|
|
112
|
+ Tracim through http according to mail Headers.
|
|
113
|
+ Fetch is regular.
|
|
114
|
+ :param host: imap server hostname
|
|
115
|
+ :param port: imap connection port
|
|
116
|
+ :param user: user login of mailbox
|
|
117
|
+ :param password: user password of mailbox
|
|
118
|
+ :param folder: mail folder where new mail are fetched
|
|
119
|
+ :param delay: seconds to wait before fetching new mail again
|
|
120
|
+ :param endpoint: tracim http endpoint where decoded mail are send.
|
|
121
|
+ """
|
105
|
122
|
self._connection = None
|
106
|
123
|
self._mails = []
|
107
|
124
|
self.host = host
|