django-mailbox icon indicating copy to clipboard operation
django-mailbox copied to clipboard

IMAP: Crash can cause Message to be duplicated and processed multiple times.

Open ses4j opened this issue 5 years ago • 2 comments

The IMAP transport protocol mailbox fetch works like this:

  1. Get all message IDs (even ones marked \Deleted.)
  2. For each message ID: a. fetch the email b. call the receive signal c. mark it \Deleted
  3. expunge all \Deleted.

We are experiencing the same message being downloaded multiple times, in situations where our polling mechanism crashes in the middle of looping (in our case, due to many messages taking too long and Celery sigkilling the process).

This seems unnecessary. I am no IMAP expert, but from reviewing the IMAP RFC, it seems we could either move the expunge into the loop so it happens after each \Deleted mark, or else change the _get_all_message_ids from:

response, message_ids = self.server.uid('search', None, 'ALL')

to

response, message_ids = self.server.uid('search', None, 'UNDELETED')

Or both... thoughts?

ses4j avatar Sep 03 '19 16:09 ses4j

Any update on this? I have also experienced the same issue.

acmisiti avatar Sep 13 '19 15:09 acmisiti

Every <email.message.Message object> have ['message-id'] header. And it store in model Message. I think setting to avoid duplicate can be added. For example add this validation to django_mailbox/models/process_incoming_message

Rokfordchez avatar Jan 29 '20 05:01 Rokfordchez