Browse Source

Explicit Exception when fetch return events unrelated to the mail fetcher request

Guénaël Muller 6 years ago
parent
commit
a3c0102659
1 changed files with 21 additions and 1 deletions
  1. 21 1
      tracim/tracim/lib/email_fetcher.py

+ 21 - 1
tracim/tracim/lib/email_fetcher.py View File

151
         return None
151
         return None
152
 
152
 
153
 
153
 
154
+class BadIMAPFetchResponse(Exception):
155
+    pass
156
+
157
+
154
 class MailFetcher(object):
158
 class MailFetcher(object):
155
     def __init__(
159
     def __init__(
156
         self,
160
         self,
290
             # TODO - G.M - 10-01-2017 - Support imapclient exceptions
294
             # TODO - G.M - 10-01-2017 - Support imapclient exceptions
291
             # when Imapclient stable will be 2.0+
295
             # when Imapclient stable will be 2.0+
292
 
296
 
297
+            except BadIMAPFetchResponse as e:
298
+                log = 'Imap Fetch command return bad response.' \
299
+                      'Is someone else connected to the mailbox ?'
300
+                logger.error(self, log.format(e.__str__()))
293
             # Others
301
             # Others
294
             except Exception as e:
302
             except Exception as e:
295
                 log = 'Mail Fetcher error {}'
303
                 log = 'Mail Fetcher error {}'
354
             logger.debug(self, 'Fetch mail "{}"'.format(
362
             logger.debug(self, 'Fetch mail "{}"'.format(
355
                 msgid,
363
                 msgid,
356
             ))
364
             ))
357
-            msg = message_from_bytes(data[b'BODY[]'])
365
+
366
+            try:
367
+                msg = message_from_bytes(data[b'BODY[]'])
368
+            except KeyError as e:
369
+                # INFO - G.M - 12-01-2018 - Fetch may return events response
370
+                # In some specific case, fetch command may return events
371
+                # response unrelated to fetch request.
372
+                # This should happen only when someone-else use the mailbox
373
+                # at the same time of the fetcher.
374
+                # see https://github.com/mjs/imapclient/issues/334
375
+                raise BadIMAPFetchResponse from e
376
+
358
             msg_container = MessageContainer(msg, msgid)
377
             msg_container = MessageContainer(msg, msgid)
359
             messages.append(msg_container)
378
             messages.append(msg_container)
379
+
360
         return messages
380
         return messages
361
 
381
 
362
     def _notify_tracim(
382
     def _notify_tracim(