Unable to delete message from IMAP folder view
Posted: 2022-11-24 18:18
I have a C# program using the COM API that looks at a "blocked" IMAP folder to automatically unsubscribe and create a rule to block the email sender in the future.
When a user moves the email into the folder and the script runs - I would like to deleted the email from the folder to indicated that it has been processed. I have tried setting the message flag to deleted and delete by ID, but the message still shows up in the IMAP folder. When I rerun the script it does not detect that there are any emails in that folder so the message is being deleted. So what does the client IMAP folder key off from that is it still showing the message as not deleted? As I can use two different IMAP clients and delete an email on one and it will "almost" immediately be deleted from the other client? (Also, when I restart the IMAP Client - the email is still there)
When a user moves the email into the folder and the script runs - I would like to deleted the email from the folder to indicated that it has been processed. I have tried setting the message flag to deleted and delete by ID, but the message still shows up in the IMAP folder. When I rerun the script it does not detect that there are any emails in that folder so the message is being deleted. So what does the client IMAP folder key off from that is it still showing the message as not deleted? As I can use two different IMAP clients and delete an email on one and it will "almost" immediately be deleted from the other client? (Also, when I restart the IMAP Client - the email is still there)
Code: Select all
hMailServer.IMAPFolder folder = account.IMAPFolders.ItemByName["block"];
Console.WriteLine(" => Messages: " + folder.Messages.Count.ToString());
for (int m = folder.Messages.Count - 1; m >= 0; m--)
{
hMailServer.Message message = folder.Messages[m];
records.Add(ProcessMessage(message));
Console.WriteLine(" Deleting message ID: " + message.ID.ToString() );
message.Flag[eMessageFlag.eMFDeleted] = true;
folder.Messages.DeleteByDBID(message.ID);
}