0 votes
by (8.6k points)
edited

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

Applies to: Rebex Secure Mail

2 Answers

0 votes
by (147k points)
edited
 
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
by (140 points)
edited

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

by (147k 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.
by (13.3k points)
edited

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.

...