Search code examples
pythonimapimaplib

How can I uniquely identify an IMAP message after copying it?


I want to move an IMAP message from INBOX to INBOX/Archive using python's imapclient library, which I'm doing basically like this:

def archive_message(imap, message_id):
    imap.copy([message_id], getOptions().imap_archive_folder)
    imap.delete_messages([message_id])

However, this loses my reference to the message. What I want to do is to store an identifier for the message that will allow me to look up the message later, using something like this:

def retrieve_message(imap, MYSTICAL_STORED_ID):
    imap.select_folder(getOptions().imap_archive_folder)
    return imap.fetch([MYSTICAL_STORED_ID], parts=["RFC822"])

What ID should I / can I use for this, and how would I do the lookup part of this?


Solution

  • The value in the Message-Id header is supposed to be unique per email message.