How can I move a message from an IMAP folder to another one?

asked 19 Feb '10, 18:00

Rebex%20KB's gravatar image

Rebex KB ♦♦
256312
accept rate: 78%


IMAP protocol doesn't support this directly, but it can be done this way:

  1. Call Imap.CopyMessage to copy a message to another IMAP folder.
  2. Then call Imap.DeleteMessage to mark the message in the original folder as deleted.
  3. To actually remove the original message, call Imap.Purge (be careful, this will purge any other messages marked as "deleted" as well)

Sample code:

C#:

// initialize an IMAP session
Imap client = new Imap();
...

// select the source folder
client.SelectFolder("Inbox");

// copy the message to the target folder
client.CopyMessage(uniqueId, "Archive");

// mark the original message as "deleted"
client.DeleteMessage(uniqueId);

// purge deleted messages (be careful, this will purge
// any other messages marked as "deleted" as well)
client.Purge();

VB.NET:

''# initialize an IMAP session
Dim client As New Imap
...

''# select the source folder
client.SelectFolder("Inbox")

''# copy the message to the target folder
client.CopyMessage(uniqueId, "Archive")

''# mark the original message as "deleted"
client.DeleteMessage(uniqueId)

''# purge deleted messages (be careful, this will purge
''# any other messages marked as "deleted" as well)
client.Purge()
link

answered 19 Feb '10, 18:09

Lukas%20Pokorny's gravatar image

Lukas Pokorny ♦♦
2.2k18
accept rate: 32%

edited 30 Mar '10, 10:08

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310

Dobrý den, měl bych otázku k vašemu způsobu přesunutí zprávy. Vidím zde řešení přes CopyMessage, ale nevím kde zjistit nové Unique ID té přesunuté zprávy. Mnohokrát děkuji za odpověď,

Jiří Hotovec

link

answered 09 Jul '10, 12:34

Jiri%20Hotovec's gravatar image

Jiri Hotovec
16
accept rate: 0%

Dobrý den, autoři protokoli IMAP na tuto možnost moc nemysleli a zjištění nového unique ID proto může být dost komplikované. Více informací jsem právě poslal v e-mailu.

(09 Jul '10, 14:11) Lukas Pokorny ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×71
×1

Asked: 19 Feb '10, 18:00

Seen: 927 times

Last updated: 09 Jul '10, 12:34