ImapExpunge Method
Permanently removes all the messages marked as deleted from the currently selected folder.

Namespace: MailBee.ImapMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
Syntax
public bool Expunge()

Return Value

Type: Boolean
true if the command succeeded; otherwise, false.
Exceptions
ExceptionCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.
Remarks

This overload can be used to expunge all messages marked as deleted from the current folder without closing it.

To expunge only certain messages (so that some messages having \Deleted flag set would remain), the developer should use Expunge(String, Boolean) overload.

To expunge deleted messages asynchronously, see the sample code in BeginExecuteCustomCommand(String, String, AsyncCallback, Object) topic.

Examples
This sample removes last 10 messages from Sent folder. If there were another messages marked as deleted in this folder, they will be removed as well.
using System;
using MailBee;
using MailBee.ImapMail;

class Sample
{
    static void Main(string[] args)
    {
        Imap imp = new Imap();

        // Connect to the server and log in the account.
        imp.Connect("imap.domain.com");
        imp.Login("jdoe@domain.com", "secret");

        // Select Sent folder.
        imp.SelectFolder("Sent");

        // Mark last 10 messages as deleted.
        if (imp.MessageCount >= 10)
        {
            string range = (imp.MessageCount - 9).ToString() + ":" + imp.MessageCount.ToString();
            imp.SetMessageFlags(range, false, SystemMessageFlags.Deleted, MessageFlagAction.Add);
        }

        // Expunge all messages marked as deleted.
        imp.Expunge();

        imp.Disconnect();
    }
}
See Also