0

I have a python script that connects to an IMAP server. The script downloads the mails from the server in a certain format. The second time the script is run, rather than downloading all the mails, it should download new mails (synchronize) to avoid time overhead.

I have an issue. How to detect if a certain mail has been dragged from one directory to another directory (or mailbox). E.g. if I move a mail from mailbox A to mailbox B, is there any such flag like 'MOVED' to identify such mails. So the next time the script runs I am able to fetch RECENT or UNSEEN mails but not the one whose path on the server has been changed.

Rishik Mani
  • 490
  • 8
  • 27

1 Answers1

0

No. There's not. IMAP considers a moved message to be deleted from one folder and created in a new folder. There is no continuity between folders in general.

Max
  • 10,701
  • 2
  • 24
  • 48
  • Note: some specific implementations have permanent ids (eg, Gmail has an internal gmail-uid) – Max Feb 28 '18 at 15:05
  • So how can I trace such a mail if it has been deleted from one folder and added to another, considering the mail has more than 70000 mails. Checking every mail would rather slow down my application. Do you have any suggestion for it? – Rishik Mani Mar 02 '18 at 12:49
  • 1
    Short answer: you don't. IMAP clients don't track moves, they just see a delete in one folder, and an add in another. The end result is the same. If your object is to prevent processing a message you've already seen, you could store a hash in your database, or use a custom flag to mark it. Most servers support custom flags, and they are generally preserved on moves. – Max Mar 02 '18 at 16:54