Browse Source

Refactoring email_fetcher

Guénaël Muller 7 years ago
parent
commit
5c9218168a
1 changed files with 9 additions and 9 deletions
  1. 9 9
      tracim/tracim/lib/email_fetcher.py

+ 9 - 9
tracim/tracim/lib/email_fetcher.py View File

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