Sample code for 30+ languages & platforms
Xbase++ Requires Chilkat v11.0.0+

List IMAP Mailboxes with Reference

Demonstrates how to list all sub-mailboxes within a specified context. In this case, we list all mailboxes under "INBOX.vendors".

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap
LOCAL cRefName
LOCAL cWildcardedMailbox
LOCAL nSubscribed
LOCAL oMboxes
LOCAL i

nSuccess := 0

//  This example assumes the Chilkat API to have been previously unlocked.
//  See Global Unlock Sample for sample code.

oImap := CreateObject("Chilkat.Imap")

//  Connect to an IMAP server.
//  Use TLS
oImap:Ssl := 1
oImap:Port := 993
nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Login
nSuccess := oImap:Login("admin@chilkatsoft.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Get the list of mailboxes.
cRefName := ""
cWildcardedMailbox := "*"
nSubscribed := 0

oMboxes := CreateObject("Chilkat.Mailboxes")
nSuccess := oImap:MbxList(nSubscribed, cRefName, cWildcardedMailbox, oMboxes)
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    oMboxes:destroy()
    RETURN
ENDIF

i := 0
DO WHILE i < oMboxes:Count
    ? oMboxes:GetName(i)
    i := i + 1
ENDDO

//  Sample output looks like this:
//  INBOX.vendors.shareit
//  INBOX.vendors.paypal
//  INBOX.vendors.dell
//  INBOX.vendors.inMotion
//  INBOX.vendors.myhosting
//  INBOX.vendors.peer1

//  Disconnect from the IMAP server.
nSuccess := oImap:Disconnect()

oImap:destroy()
oMboxes:destroy()