Click or drag to resize
MimeKit

ImapFolderExpunge(IListUniqueId, CancellationToken) Method

Expunge the specified uids, permanently removing them from the folder.

Namespace: MailKit.Net.Imap
Assembly: MailKit (in MailKit.dll) Version: 4.3.0
Syntax
C#
public override void Expunge(
	IList<UniqueId> uids,
	CancellationToken cancellationToken = default
)

Parameters

uids  IListUniqueId
The message uids.
cancellationToken  CancellationToken  (Optional)
The cancellation token.

Implements

IMailFolderExpunge(IListUniqueId, CancellationToken)
IMailFolderExpunge(IListUniqueId, CancellationToken)
Exceptions
ExceptionCondition
ArgumentNullExceptionuids is null.
ArgumentException One or more of the uids is invalid.
ObjectDisposedException The ImapClient has been disposed.
ServiceNotConnectedException The ImapClient is not connected.
ServiceNotAuthenticatedException The ImapClient is not authenticated.
FolderNotOpenException The ImapFolder is not currently open in read-write mode.
OperationCanceledException The operation was canceled via the cancellation token.
IOException An I/O error occurred.
ImapProtocolException The server's response contained unexpected tokens.
ImapCommandException The server replied with a NO or BAD response.
Remarks

Expunges the specified uids, permanently removing them from the folder.

If the IMAP server supports the UIDPLUS extension (check the Capabilities for the UidPlus flag), then this operation is atomic. Otherwise, MailKit implements this operation by first searching for the full list of message uids in the folder that are marked for deletion, unmarking the set of message uids that are not within the specified list of uids to be be expunged, expunging the folder (thus expunging the requested uids), and finally restoring the deleted flag on the collection of message uids that were originally marked for deletion that were not included in the list of uids provided. For this reason, it is advisable for clients that wish to maintain state to implement this themselves when the IMAP server does not support the UIDPLUS extension.

For more information about the UID EXPUNGE command, see rfc4315.

Note  Note
Normally, a MessageExpunged event will be emitted for each message that is expunged. However, if the IMAP server supports the QRESYNC extension and it has been enabled via the EnableQuickResync(CancellationToken) method, then the MessagesVanished event will be emitted rather than the MessageExpunged event.
See Also