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 the Fetch() method.

The first two parameters define the first and the last messages to be retrieved. They can either be message sequence numbers or message UIDs, as defined by the third parameter, UID, of the call (set it to true if you provide UIDs and to false if you provide the sequence numbers). If the values of the first and the last messages 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.

The difference between UIDs and message sequence numbers is that the latter can change (e.g. 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