|
@@ -87,7 +87,7 @@ class DecodedMail(object):
|
87
|
87
|
|
88
|
88
|
@classmethod
|
89
|
89
|
def _parse_html_body(cls, html_body: str):
|
90
|
|
- soup = BeautifulSoup(html_body,'html.parser')
|
|
90
|
+ soup = BeautifulSoup(html_body, 'html.parser')
|
91
|
91
|
config = BEAUTIFULSOUP_HTML_BODY_PARSE_CONFIG
|
92
|
92
|
for tag in soup.findAll():
|
93
|
93
|
if DecodedMail._tag_to_extract(tag):
|
|
@@ -130,8 +130,8 @@ class DecodedMail(object):
|
130
|
130
|
for part in self._message.walk():
|
131
|
131
|
content_type = part.get_content_type()
|
132
|
132
|
content_dispo = str(part.get('Content-Disposition'))
|
133
|
|
- if content_type == CONTENT_TYPE_TEXT_PLAIN and 'attachment' \
|
134
|
|
- not in content_dispo:
|
|
133
|
+ if content_type == CONTENT_TYPE_TEXT_PLAIN \
|
|
134
|
+ and 'attachment' not in content_dispo:
|
135
|
135
|
return part
|
136
|
136
|
return part
|
137
|
137
|
|
|
@@ -214,11 +214,12 @@ class MailFetcher(object):
|
214
|
214
|
time.sleep(self.delay)
|
215
|
215
|
try:
|
216
|
216
|
self._connect()
|
217
|
|
- mails = self._fetch()
|
|
217
|
+ messages = self._fetch()
|
218
|
218
|
# TODO - G.M - 2017-11-22 retry sending unsended mail
|
219
|
219
|
# These mails are return by _notify_tracim, flag them with "unseen"
|
220
|
220
|
# or store them until new _notify_tracim call
|
221
|
|
- self._notify_tracim(mails)
|
|
221
|
+ cleaned_mails = [DecodedMail(msg) for msg in messages]
|
|
222
|
+ self._notify_tracim(cleaned_mails)
|
222
|
223
|
self._disconnect()
|
223
|
224
|
except Exception as e:
|
224
|
225
|
# TODO - G.M - 2017-11-23 - Identify possible exceptions
|
|
@@ -258,7 +259,7 @@ class MailFetcher(object):
|
258
|
259
|
Get news message from mailbox
|
259
|
260
|
:return: list of new mails
|
260
|
261
|
"""
|
261
|
|
- mails = []
|
|
262
|
+ messages = []
|
262
|
263
|
# select mailbox
|
263
|
264
|
rv, data = self._connection.select(self.folder)
|
264
|
265
|
if rv == 'OK':
|
|
@@ -277,8 +278,7 @@ class MailFetcher(object):
|
277
|
278
|
rv, data = self._connection.fetch(num, '(RFC822)')
|
278
|
279
|
if rv == 'OK':
|
279
|
280
|
msg = message_from_bytes(data[0][1])
|
280
|
|
- decodedmsg = DecodedMail(msg)
|
281
|
|
- mails.append(decodedmsg)
|
|
281
|
+ messages.append(msg)
|
282
|
282
|
else:
|
283
|
283
|
log = 'IMAP : Unable to get mail : {}'
|
284
|
284
|
logger.debug(self, log.format(str(rv)))
|
|
@@ -288,7 +288,7 @@ class MailFetcher(object):
|
288
|
288
|
else:
|
289
|
289
|
log = 'IMAP : Unable to open mailbox : {}'
|
290
|
290
|
logger.debug(self, log.format(str(rv)))
|
291
|
|
- return mails
|
|
291
|
+ return messages
|
292
|
292
|
|
293
|
293
|
def _notify_tracim(self, mails: list) -> list:
|
294
|
294
|
"""
|