tags:

views:

1331

answers:

3

(using the IMAP commands, not with the assistance of any other mail package)

+1  A: 

I guess you COPY the message to the new folder and then delete (EXPUNGE) it in the old one.

RFC351

HINT There's no DELETE command that does what you mean, you have to flag the message as deleted and then EXPUNGE the mailbox. Have a look at the RFC. Be careful with DELETE, as it deletes whole mailboxes, not single mails.

jkramer
+3  A: 

I'm not sure how well-versed you are in imap-speak, but basically after login, "SELECT" the source mailbox, "COPY" the messages, and "EXPUNGE" the messages (or "DELETE" the old mailbox if it is empty now :-).

a login a s
b select source
c copy 1 othermbox
d store 1 +flags (\Deleted)
e expunge

would be an example of messages to send. (Note: imap messages require a uniqe prefix before each command, thus the "a b c" in front)

See RFC 2060 for details.

Sec
A: 
* i suppose one has a uid of the email which is going to be moved.

    import imaplib
    obj = imaplib.IMAP4_SSL('imap.gmail.com', 993)
    obj.login('username', 'password')
    obj.select(src_folder_name)
    apply_lbl_msg = obj.uid('COPY', msg_uid, desti_folder_name)
    if apply_lbl_msg[0] == 'OK':
        mov, data = obj.uid('STORE', msg_uid , '+FLAGS', '(\Deleted)')
        obj.expunge()
Avadhesh