Retrieves the mail message with the specified unique identifier (UID) while only fetching those parts of the message that satisfy the condition of the specified delegate.

Namespace: S22.Imap
Assembly: S22.Imap (in S22.Imap.dll) Version: 3.6.0.0 (3.6.0.0)

Syntax

C#
MailMessage GetMessage(
	uint uid,
	ExaminePartDelegate callback,
	bool seen = true,
	string mailbox = null
)

Parameters

uid
Type: System..::..UInt32
The unique identifier of the mail message to retrieve.
callback
Type: S22.Imap..::..ExaminePartDelegate
A delegate which will be invoked for every MIME body-part of the mail message to determine whether the part should be fetched from the server or skipped.
seen (Optional)
Type: System..::..Boolean
Set this to true to set the \Seen flag for this message on the server.
mailbox (Optional)
Type: System..::..String
The mailbox the message will be retrieved from. If this parameter is omitted, the value of the DefaultMailbox property is used to determine the mailbox to operate on.

Return Value

An initialized instance of the MailMessage class representing the fetched mail message.

Remarks

A unique identifier (UID) is a 32-bit value assigned to each message which uniquely identifies the message within the respective mailbox. No two messages in a mailbox share the same UID.

Examples

This example demonstrates how to use the ExaminePartDelegate with the GetMessage method to only download message parts with a size of 1 Megabyte or less.
CopyC#
ImapClient Client = new ImapClient("imap.gmail.com", 993, "My_UsernamMe",
"My_Password", true, AuthMethod.Login);

// Find all messages in the inbox.
IEnumerable<uint> uids = Client.Search( SearchCondition.All() );

// Download each message but skip message parts that are larger than 1 Megabyte.
foreach(uint uid in uids) {
    MailMessage msg = Client.GetMessage(uid, (Bodypart part) => {
            if(part.Size > (1024 * 1024))
                return false;
            else
                return true;
        }
    );
}

Client.Dispose();

Exceptions

ExceptionCondition
System..::..ArgumentNullExceptionThe callback parameter is null.
S22.Imap..::..BadServerResponseExceptionThe mail message could not be fetched. The message property of the exception contains the error message returned by the server.
System..::..ObjectDisposedExceptionThe ImapClient object has been disposed.
System.IO..::..IOExceptionThere was a failure writing to or reading from the network.
S22.Imap..::..NotAuthenticatedExceptionThe method was called in non-authenticated state, i.e. before logging in.

See Also