I'm working with MailKit lib and have a problem.
My application is read specify email in Inbox (Gmail), and delete them.
IList<UniqueId> listUid = inbox.Search(query);
for (int i = 0; i < listUid.Count; i++)
{
var message = inbox.GetMessage(listUid[i]);
inbox.AddFlags(msg.Uid, MessageFlags.Deleted, true);
inbox.Expunge();
}
It run OK, But when Gmail setting Conversation View = Conversation view on, the message that marked as deletion will comback in Inbox if have same email subject and same sender. In next-time I count message, all of deletion message will be re-count. How to avoid it? (save Uid of deletion message is one way but when message number increase, processing will be slow)
Thanks very much.
GMail unfortunately does not behave the same way most other IMAP servers behave and so when you mark a message as \Deleted, it gets moved to the Trash folder automatically and so the Expunge does nothing.
What you need to do is go to your GMail settings and change the behavior of your IMAP account so that it doesn't move the messages to Trash.
Either that or MoveTo() the message to the Trash folder yourself so you can get the UID of the message in the Trash folder (hint: use the return value of the MoveTo() method) and then open the Trash folder and expunge the message from there.
Note: this code is untested, but it should look something like this:
var trash = client.GetFolder (SpecialFolder.Trash);
var moved = client.Inbox.MoveTo (uid, trash);
if (moved.HasValue) {
trash.Open (FolderAccess.ReadWrite);
trash.AddFlags (moved.Value, MessageFlags.Deleted, true);
trash.Expunge (new [] { moved.Value });
}