copying or moving the mail message using imaplib

Tony Meyer tameyer at ihug.co.nz
Mon Feb 21 23:10:50 EST 2005


> My problem is I want to move the mail message to other folder in 
> the mail using imaplib (E.g) I want to move a message from 
> the inbox to the Draft folder in my account using python 
> code. Can any one help me by giving a sample code to do this?

IMAP is a terrible terrible protocol.  It is not possible to move messages,
whatever language you're using to interact with the IMAP server.

You can copy the message to the new folder (copy() function) and then mark
the old copy as deleted (store() function) but you then either have lots of
/Deleted messages in the original folder, or need to purge/expunge it and
remove any other messages that are /Deleted as well.

The python imaplib is a very thin wrapper over the IMAP protocol.  If you
want to use it, then I highly recommend that you do so with a copy of the
IMAP RFC handy (it's really just simple translation from the raw IMAP codes
to Python code).

=Tony.Meyer




More information about the Python-list mailing list