IMAP MoveToMailbox Requires Expunge to Remove Messages
When using the IPWorks IMAP component, moving a message with MoveToMailbox does not immediately delete it from the source mailbox. Instead, the message is marked for deletion and only removed after the mailbox is expunged.
The MoveToMailbox method performs a copy operation to the target mailbox and applies the "\Deleted" flag to the original message. At this stage, the message is no longer active for most operations but still physically exists in the mailbox.
Removal depends on server behavior. Some IMAP servers automatically expunge deleted messages during logout or at scheduled intervals, while others require manual cleanup.
To ensure immediate deletion, use ExpungeMailbox after moving the message. This forces the server to permanently remove all messages marked with the "\Deleted" flag.
imap1.Mailbox = "\"INBOX\"";
imap1.SelectMailbox();
imap1.MessageSet = messageIndex.ToString();
imap1.Mailbox = "\"NewMailbox\"";
imap1.MoveToMailbox();
// Remove all message marked with "\Deleted" flag
imap1.ExpungeMailbox();
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.