|
@@ -56,7 +56,10 @@ class DecodedMail(object):
|
56
|
56
|
def get_special_key(self) -> typing.Optional[str]:
|
57
|
57
|
return self._decode_header(TRACIM_SPECIAL_KEY_HEADER)
|
58
|
58
|
|
59
|
|
- def get_body(self) -> typing.Optional[str]:
|
|
59
|
+ def get_body(
|
|
60
|
+ self,
|
|
61
|
+ use_html_parsing=True
|
|
62
|
+ ) -> typing.Optional[str]:
|
60
|
63
|
body_part = self._get_mime_body_message()
|
61
|
64
|
body = None
|
62
|
65
|
if body_part:
|
|
@@ -70,13 +73,15 @@ class DecodedMail(object):
|
70
|
73
|
elif content_type == CONTENT_TYPE_TEXT_HTML:
|
71
|
74
|
html_body = body_part.get_payload(decode=True).decode(
|
72
|
75
|
charset)
|
73
|
|
- html_body = str(ParsedHTMLMail(html_body))
|
|
76
|
+ if use_html_parsing:
|
|
77
|
+ html_body = str(ParsedHTMLMail(html_body))
|
74
|
78
|
body = DecodedMail._sanitize_html_body(html_body)
|
75
|
79
|
|
76
|
80
|
return body
|
77
|
81
|
|
78
|
82
|
@classmethod
|
79
|
83
|
def _parse_txt_body(cls, txt_body: str) -> str:
|
|
84
|
+ # TODO - G.M - 2017-11-30 - Add option to disable parsing
|
80
|
85
|
txt_body = EmailReplyParser.parse_reply(txt_body)
|
81
|
86
|
html_body = markdown.markdown(txt_body)
|
82
|
87
|
body = DecodedMail._sanitize_html_body(html_body)
|
|
@@ -182,6 +187,7 @@ class MailFetcher(object):
|
182
|
187
|
delay: int,
|
183
|
188
|
endpoint: str,
|
184
|
189
|
token: str,
|
|
190
|
+ use_html_parsing: bool
|
185
|
191
|
) -> None:
|
186
|
192
|
"""
|
187
|
193
|
Fetch mail from a mailbox folder through IMAP and add their content to
|
|
@@ -196,6 +202,7 @@ class MailFetcher(object):
|
196
|
202
|
:param delay: seconds to wait before fetching new mail again
|
197
|
203
|
:param endpoint: tracim http endpoint where decoded mail are send.
|
198
|
204
|
:param token: token to authenticate http connexion
|
|
205
|
+ :param use_html_parsing: parse html mail
|
199
|
206
|
"""
|
200
|
207
|
self._connection = None
|
201
|
208
|
self.host = host
|
|
@@ -207,6 +214,7 @@ class MailFetcher(object):
|
207
|
214
|
self.delay = delay
|
208
|
215
|
self.endpoint = endpoint
|
209
|
216
|
self.token = token
|
|
217
|
+ self.use_html_parsing = use_html_parsing
|
210
|
218
|
|
211
|
219
|
self._is_active = True
|
212
|
220
|
|
|
@@ -217,7 +225,7 @@ class MailFetcher(object):
|
217
|
225
|
self._connect()
|
218
|
226
|
messages = self._fetch()
|
219
|
227
|
# TODO - G.M - 2017-11-22 retry sending unsended mail
|
220
|
|
- # These mails are return by _notify_tracim, flag them with "unseen"
|
|
228
|
+ # These mails are return by _notify_tracim, flag them with "unseen" # nopep8
|
221
|
229
|
# or store them until new _notify_tracim call
|
222
|
230
|
cleaned_mails = [DecodedMail(msg) for msg in messages]
|
223
|
231
|
self._notify_tracim(cleaned_mails)
|
|
@@ -311,7 +319,8 @@ class MailFetcher(object):
|
311
|
319
|
'user_mail': mail.get_from_address(),
|
312
|
320
|
'content_id': mail.get_key(),
|
313
|
321
|
'payload': {
|
314
|
|
- 'content': mail.get_body(),
|
|
322
|
+ 'content': mail.get_body(
|
|
323
|
+ use_html_parsing=self.use_html_parsing),
|
315
|
324
|
}}
|
316
|
325
|
try:
|
317
|
326
|
r = requests.post(self.endpoint, json=msg)
|