Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMAP: how to move a message from one folder to another

Tags:

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

like image 636
Mark Harrison Avatar asked Sep 23 '08 16:09

Mark Harrison


People also ask

How do you move a message to a folder?

Move messages into a folderDrag and drop it into a folder. Note: To move more than one email, select an email, hold down the Shift key and select other messages, and then click, drag, and drop them into a folder.

How do I move emails from one folder to another in Outlook?

1. To move an email from your Inbox to another folder, right-click on the email and select Move > Other Folder… 2. Now select the folder you want to move email to from the folder list shown.

How do I move emails from one folder to another in Office 365?

You can click the box to the left of the first one, scroll to the bottom, hold Shift, and click the box to the left of the last one to select all messages in your Inbox. You can then click Move to>Move to a different folder (or Move to>New folder) to move them all to another folder.

Can IMAP send messages?

Simply put, IMAP (Internet Access Message Protocol) is an email protocol that deals with managing and retrieving email messages from the receiving server. Since IMAP deals with message retrieval, you will not be able to use the IMAP protocol to send email. Instead, IMAP will be used for receiving messages.


2 Answers

There are multiple ways to do that. The best one is the UID MOVE command defined in RFC 6851 from early 2013:

C: a UID MOVE 42:69 foo S: * OK [COPYUID 432432 42:69 1202:1229] S: * 22 EXPUNGE S: (more expunges) S: a OK Done 

Presence of this extension is indicated by the MOVE capability.

If it isn't available, but UIDPLUS (RFC 4315) is, the second best option is to use the combination of UID STORE, UID COPY and UID EXPUNGE:

C: a01 UID COPY 42:69 foo S: a01 OK [COPYUID 432432 42:69 1202:1229] Copied C: a02 UID STORE 42:69 +FLAGS.SILENT (\Deleted) S: a02 OK Stored C: a03 UID EXPUNGE 42:69 S: * 10 EXPUNGE S: * 10 EXPUNGE S: * 10 EXPUNGE S: a03 Expunged 

If the UIDPLUS is missing, there is nothing reasonable that you can do -- the EXPUNGE command permanently removes all messages which are marked for deletion, including those which you have not touched. The best this is to just use the UID COPY and UID STORE in that case.

like image 127
Jan Kundrát Avatar answered Sep 28 '22 18:09

Jan Kundrát


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.

like image 37
Sec Avatar answered Sep 28 '22 18:09

Sec