Discuss this help topic in SecureBlackbox Forum

IMAP: Get the list of messages in the mailbox

To obtain information about messages in the mailbox, use Fetch() method.

The first and second parameters define either the numbers or UIDs of the first and last message, whose information is to be retrieved. If the values are equal, information about one message is retrieved. The SBIMAPClient.Unit.imapLastMessage constant can be passed instead of the last message number to denote the last message available in the mailbox.

Whether the are numbers or UIDs are passed in the first and second parameters, is determined by the third parameter, named UID. Setting it to true means that the UIDs are passed, while setting it to false means that the numbers are passed. The difference is that the numbers can change (eg. due to deletion of the message) while UIDs are permanent at least during the session.

The DataItemNames parameter contains the list of elements that you need to retrieve. The syntax and the list of elements are described in details in the corresponding RFC.

Fetch() message returns TSBIMAPFetchResponse object, used to access individual response lines.

The sample below shows how to retrieve the list of all messages with UID, size, date, state and some header fields included.

Examples:

C#:


TSBIMAPFetchResponse response = client.Fetch(1, SBIMAPClient.Unit.imapLastMessage,
	false, "UID RFC822.SIZE INTERNALDATE FLAGS BODY[HEADER.FIELDS (SUBJECT FROM)]");
for (int i = 0; i < response.Count; i++)
{
	TSBIMAPFetchResponseLine line = response.Get(i);
	long uid = line["UID"].Number;
	int size = line["RFC822.SIZE"].Number;
}
Delphi:

var
	I: Integer;
	UID, Size: Int64;
	Response: TSBIMAPFetchResponse;
	ResponseLine: TSBIMAPFetchResponseLine;
begin
	Response := Client.Fetch(1, imapLastMessage, False,
		'UID RFC822.SIZE INTERNALDATE FLAGS BODY[HEADER.FIELDS (SUBJECT FROM)]');
	try
		for I := 0 to Response.Count - 1 do
	    begin
			ResponseLine := Response.Get(I);
			UID := ResponseLine['UID'].Number;
			Size := ResponseLine['RFC822.SIZE'].Number;
		end;
	finally
		FreeAndNil(Response);
	end;
end;

How To articles about IMAP client

Discuss this help topic in SecureBlackbox Forum