Sample code for 30+ languages & platforms
Visual FoxPro

List IMAP Mailboxes

See more IMAP Examples

Demonstrates the Chilkat Imap.MbxList method, which lists matching mailboxes and appends them to a Mailboxes object. The first argument selects subscribed-only, the second is a reference name, the third is the mailbox name pattern, and the fourth is the Mailboxes object. This example lists all mailboxes and prints each name. (The object is not cleared on success, so avoid reusing one across calls to prevent duplicates.)

Background: This corresponds to the IMAP LIST command (or LSUB when subscribed-only is requested). The pattern uses IMAP wildcards: * matches across hierarchy levels while % matches within a single level, so Archive/% lists just the direct children of Archive. Each returned mailbox also carries flags you can inspect — for example HasInferiors (has sub-folders) and IsSelectable — which is how a client renders a folder tree.

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loImap
LOCAL loMailboxes
LOCAL n
LOCAL i

lnSuccess = 0

*  Demonstrates the Imap.MbxList method, which lists matching mailboxes and appends them to a
*  Mailboxes object.  The 1st argument selects subscribed-only, the 2nd is a reference name,
*  the 3rd is the mailbox pattern, and the 4th is the Mailboxes object.

loImap = CreateObject('Chilkat.Imap')

loImap.Ssl = 1
loImap.Port = 993

lnSuccess = loImap.Connect("imap.example.com")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

lnSuccess = loImap.Login("user@example.com","myPassword")
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    CANCEL
ENDIF

*  List all mailboxes.  The first argument 0 requests all (not subscribed-only); "*" matches any name.
loMailboxes = CreateObject('Chilkat.Mailboxes')
lnSuccess = loImap.MbxList(0,"","*",loMailboxes)
IF (lnSuccess = 0) THEN
    ? loImap.LastErrorText
    RELEASE loImap
    RELEASE loMailboxes
    CANCEL
ENDIF

n = loMailboxes.Count
? "Mailboxes: " + STR(n)

FOR i = 0 TO n - 1
    ? loMailboxes.GetName(i)
NEXT

lnSuccess = loImap.DisconnectERROR: ";" expected

RELEASE loImap
RELEASE loMailboxes