|
@@ -58,7 +58,8 @@ class DecodedMail(object):
|
58
|
58
|
|
59
|
59
|
def get_body(
|
60
|
60
|
self,
|
61
|
|
- use_html_parsing=True
|
|
61
|
+ use_html_parsing=True,
|
|
62
|
+ use_txt_parsing=True,
|
62
|
63
|
) -> typing.Optional[str]:
|
63
|
64
|
body_part = self._get_mime_body_message()
|
64
|
65
|
body = None
|
|
@@ -68,7 +69,10 @@ class DecodedMail(object):
|
68
|
69
|
if content_type == CONTENT_TYPE_TEXT_PLAIN:
|
69
|
70
|
txt_body = body_part.get_payload(decode=True).decode(
|
70
|
71
|
charset)
|
71
|
|
- body = DecodedMail._parse_txt_body(txt_body)
|
|
72
|
+ if use_txt_parsing:
|
|
73
|
+ txt_body = EmailReplyParser.parse_reply(txt_body)
|
|
74
|
+ html_body = markdown.markdown(txt_body)
|
|
75
|
+ body = DecodedMail._sanitize_html_body(html_body)
|
72
|
76
|
|
73
|
77
|
elif content_type == CONTENT_TYPE_TEXT_HTML:
|
74
|
78
|
html_body = body_part.get_payload(decode=True).decode(
|
|
@@ -80,14 +84,6 @@ class DecodedMail(object):
|
80
|
84
|
return body
|
81
|
85
|
|
82
|
86
|
@classmethod
|
83
|
|
- def _parse_txt_body(cls, txt_body: str) -> str:
|
84
|
|
- # TODO - G.M - 2017-11-30 - Add option to disable parsing
|
85
|
|
- txt_body = EmailReplyParser.parse_reply(txt_body)
|
86
|
|
- html_body = markdown.markdown(txt_body)
|
87
|
|
- body = DecodedMail._sanitize_html_body(html_body)
|
88
|
|
- return body
|
89
|
|
-
|
90
|
|
- @classmethod
|
91
|
87
|
def _sanitize_html_body(cls, html_body: str) -> str:
|
92
|
88
|
soup = BeautifulSoup(html_body, 'html.parser')
|
93
|
89
|
config = BEAUTIFULSOUP_HTML_BODY_SANITIZE_CONFIG
|
|
@@ -187,7 +183,8 @@ class MailFetcher(object):
|
187
|
183
|
delay: int,
|
188
|
184
|
endpoint: str,
|
189
|
185
|
token: str,
|
190
|
|
- use_html_parsing: bool
|
|
186
|
+ use_html_parsing: bool,
|
|
187
|
+ use_txt_parsing: bool,
|
191
|
188
|
) -> None:
|
192
|
189
|
"""
|
193
|
190
|
Fetch mail from a mailbox folder through IMAP and add their content to
|
|
@@ -215,6 +212,7 @@ class MailFetcher(object):
|
215
|
212
|
self.endpoint = endpoint
|
216
|
213
|
self.token = token
|
217
|
214
|
self.use_html_parsing = use_html_parsing
|
|
215
|
+ self.use_txt_parsing = use_txt_parsing
|
218
|
216
|
|
219
|
217
|
self._is_active = True
|
220
|
218
|
|
|
@@ -320,7 +318,8 @@ class MailFetcher(object):
|
320
|
318
|
'content_id': mail.get_key(),
|
321
|
319
|
'payload': {
|
322
|
320
|
'content': mail.get_body(
|
323
|
|
- use_html_parsing=self.use_html_parsing),
|
|
321
|
+ use_html_parsing=self.use_html_parsing,
|
|
322
|
+ use_txt_parsing=self.use_txt_parsing),
|
324
|
323
|
}}
|
325
|
324
|
try:
|
326
|
325
|
r = requests.post(self.endpoint, json=msg)
|