Sample code for 30+ languages & platforms
DataFlex

List IMAP Mailboxes

List the mailboxes available within an IMAP account.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sRefName
    String sWildcardedMailbox
    Boolean iSubscribed
    Variant vMboxes
    Handle hoMboxes
    Integer i
    String sTemp1

    Move False To iSuccess

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

    Get Create (RefClass(cComChilkatImap)) To hoImap
    If (Not(IsComObjectCreated(hoImap))) Begin
        Send CreateComObject of hoImap
    End

    // Connect to an IMAP server.
    // Use TLS
    Set ComSsl Of hoImap To True
    Set ComPort Of hoImap To 993
    Get ComConnect Of hoImap "MY-IMAP-DOMAIN" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    // Login
    Get ComLogin Of hoImap "MY-IMAP-LOGIN" "MY-IMAP-PASSWORD" To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move "" To sRefName
    // refName is usually set to an empty string.
    // A non-empty reference name argument is the name of a mailbox or a level of
    // mailbox hierarchy, and indicates the context in which the mailbox
    // name is interpreted.

    // Select all mailboxes matching this pattern:
    Move "*" To sWildcardedMailbox

    Move False To iSubscribed

    Get Create (RefClass(cComChilkatMailboxes)) To hoMboxes
    If (Not(IsComObjectCreated(hoMboxes))) Begin
        Send CreateComObject of hoMboxes
    End
    Get pvComObject of hoMboxes to vMboxes
    Get ComMbxList Of hoImap iSubscribed sRefName sWildcardedMailbox vMboxes To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Move 0 To i
    While (i < (ComCount(hoMboxes)))
        Get ComGetName Of hoMboxes i To sTemp1
        Showln sTemp1
        Move (i + 1) To i
    Loop

    // Sample output looks like this:
    // INBOX.vendors.shareit
    // INBOX.oldSupport
    // INBOX.vendors.paypal
    // INBOX.sales
    // INBOX.lists
    // INBOX.Drafts
    // INBOX.vendors.dell
    // INBOX.Trash
    // INBOX.invoiceRequests
    // INBOX.purchases
    // INBOX.vendors.inMotion
    // INBOX.oldEmail
    // INBOX.vendors
    // INBOX.lists.python
    // INBOX.vendors.myhosting
    // INBOX.Templates
    // INBOX.friends
    // INBOX.bounceSamples
    // INBOX.lists.ruby
    // INBOX.vendors.peer1
    // INBOX.Sent
    // INBOX.Junk
    // INBOX

    // Disconnect from the IMAP server.
    Get ComDisconnect Of hoImap To iSuccess


End_Procedure