How can I move messages on IMAP?

0 votes
asked Feb 19, 2010 by Rebex KB (8,190 points)
edited Mar 12, 2012

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

Applies to: Rebex Secure Mail

2 Answers

0 votes
answered Feb 19, 2010 by Lukas Pokorny (102,210 points)
edited Mar 30, 2010
 
Best answer

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()
0 votes
answered Jul 9, 2010 by Jiri Hotovec (140 points)
edited Mar 12, 2012

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

commented Jul 9, 2010 by Lukas Pokorny (102,210 points)
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.
commented Mar 12, 2012 by Martin Vobr (12,940 points)
edited Mar 12, 2012

One of new features introduced in Release 2012 R1 - http://blog.rebex.net/news/archive/2012/03/08/version-2012-r1.aspx will make it a lot easier: Imap.CopyMessage and Imap.Purge methods return a list of affected messages if the server supports UIDPLUS extension.

...