Hi there,
I am just starting with this great library. I am working on an open-source daemon that can simply move all messages from an E-Mail Account A to E-Mail Account B using IMAP.
I've been using such a tool a long day ago which was not open source and I would like to auto-move several old obsole accounts to one.
What's the best way to achieve that scenario when iterating the messages and how do I put the message to another client instance inbox?
Probably something like:
void MoveAllMessages (IMailFolder src, IMailFolder dest)
{
// Fetch the FLAGS and INTERNALDATE metadata for all messages in the `src`
// folder because we'll want to clone them over to the `dest` folder when we
// append the messages to it. We'll also want the UniqueId so that we can
// delete the message from the `src` folder when we are done moving it over
// to the `dest` folder.
var items = src.Fetch (0, -1, MessageSummaryItems.UniqueId | MessageSummaryItems.InternalDate | MessageSummaryItems.Flags);
foreach (var item in items) {
// ignore deleted messages
if (item.Flags.Value.HasFlag (MessageFlags.Deleted))
continue;
// get the message from the src folder
var message = src.GetMessage (items.UniqueId);
// append the message to the dest folder, keeping the flags and internal arrival date of the message as well
dest.Append (message, item.Flags.Value, item.InternalDate.Value);
// mark the message for deletion on the src folder
src.AddFlags (item.UniqueId, MessageFlags.Deleted, true);
}
// expunge the src folder of deleted messages
src.Expunge ();
}
Note that you don't necessarily need to or want to clone the INTERNALDATE metadata - this timestamp just represents the arrival timestamp of the message. If you don't pass that along to the destination IMAP server, then the destination IMAP server will use the current date/time as the INTERNALDATE for the message(s) that you append.