Discuss this help topic in SecureBlackbox Forum

IMAP: Get the list of mailboxes or news groups

List() method lets you get the list of folders (mailboxes) available to the account. LSub() method lets you get the list of newsgroups available on the server.

The first parameter of the methods denotes the starting point in the hierarchy to be retrieved. It can be empty or contain the hierarchy delimiter (such as slash '/') depending on server requirements.

The second parameter is the name or a mask (which can include '*' and '%' substitution characters, where '*' can substitute the hierarchy delimiter and '%' doesn't do such substitution). To retrieve the list of folders in one level, you can pass the mask of "%" in the second parameter. To recursively retrieve the list of folders, use "*" as the mask.

As the third parameter you pass the TSBIMAPMailBoxesList list to be filled by the results of the listing, each being of TSBIMAPMailBoxInfo type.

Parameters of these methods are described in details in the corresponding RFC.

Examples:

C#:


TSBIMAPMailBoxesList list = new TSBIMAPMailBoxesList();
client.List("", "*", list);
if (list.Count == 0)
	client.List("/", "*", list);
for (int i = 0; i < list.Count; i++)
{
	TSBIMAPMailBoxInfo box = list.Get(i);
	if ((box.Attributes & SBIMAPClient.Unit.imapNoSelect) == 0)
		cbMailBoxes.Items.Add(box.Name);
}
Delphi:

var
  I: Integer;
  Box: TSBIMAPMailBoxInfo;
  List: TSBIMAPMailBoxesList;
begin
  List := TSBIMAPMailBoxesList.Create;
  Client.List('', '*', List);
  if List.Count = 0 then
    Client.List('/', '*', List);
  for I := 0 to List.Count - 1 do
  begin
    Box := List.Get(I);
    if not (imapNoSelect in Box.Attributes) then
      cbMailBox.Items.Add(Box.Name);
  end;
end;

How To articles about IMAP client

Discuss this help topic in SecureBlackbox Forum