MailBee.NET Objects 4.0

Imap.Expunge Method ()

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

public bool Expunge();

Return Value

true if the command succeeded; otherwise, false.

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 overload.

To expunge deleted messages asynchronously, see the sample code in BeginExecuteCustomCommand topic.

Exceptions

Exception TypeCondition
MailBeeExceptionAn error occurred and ThrowExceptions is true.

Example

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.

[C#]
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();
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.ImapMail

Module Sample
    Sub Main(ByVal args As String())
        Dim imp As New Imap

        ' Connect to the server and log in the account.
        imp.Connect("imap4.company.com")
        imp.Login("jdoe@company.com", "secret")

        ' Select Sent folder.
        imp.SelectFolder("Sent")

        ' Mark last 10 messages as deleted.
        If (imp.MessageCount >= 10) Then
            Dim range As String = (imp.MessageCount - 9).ToString() & _
                ":" & imp.MessageCount.ToString()
            imp.SetMessageFlags(range, False, SystemMessageFlags.Deleted, _
                MessageFlagAction.Add)
        End If

        ' Expunge all messages marked as deleted.
        imp.Expunge()

        imp.Disconnect()
    End Sub
End Module

See Also

Imap Class | MailBee.ImapMail Namespace | Imap.Expunge Overload List | Close