|
@@ -151,6 +151,10 @@ class DecodedMail(object):
|
151
|
151
|
return None
|
152
|
152
|
|
153
|
153
|
|
|
154
|
+class BadIMAPFetchResponse(Exception):
|
|
155
|
+ pass
|
|
156
|
+
|
|
157
|
+
|
154
|
158
|
class MailFetcher(object):
|
155
|
159
|
def __init__(
|
156
|
160
|
self,
|
|
@@ -290,6 +294,10 @@ class MailFetcher(object):
|
290
|
294
|
# TODO - G.M - 10-01-2017 - Support imapclient exceptions
|
291
|
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
|
301
|
# Others
|
294
|
302
|
except Exception as e:
|
295
|
303
|
log = 'Mail Fetcher error {}'
|
|
@@ -354,9 +362,21 @@ class MailFetcher(object):
|
354
|
362
|
logger.debug(self, 'Fetch mail "{}"'.format(
|
355
|
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
|
377
|
msg_container = MessageContainer(msg, msgid)
|
359
|
378
|
messages.append(msg_container)
|
|
379
|
+
|
360
|
380
|
return messages
|
361
|
381
|
|
362
|
382
|
def _notify_tracim(
|