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

List IMAP Mailboxes

List the mailboxes available within an IMAP account.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Imap
string ls_RefName
string ls_WildcardedMailbox
integer li_Subscribed
oleobject loo_Mboxes
integer i

li_Success = 0

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

loo_Imap = create oleobject
li_rc = loo_Imap.ConnectToNewObject("Chilkat.Imap")
if li_rc < 0 then
    destroy loo_Imap
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Connect to an IMAP server.
//  Use TLS
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("MY-IMAP-DOMAIN")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

//  Login
li_Success = loo_Imap.Login("MY-IMAP-LOGIN","MY-IMAP-PASSWORD")
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    return
end if

ls_RefName = ""
//  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:
ls_WildcardedMailbox = "*"

li_Subscribed = 0

loo_Mboxes = create oleobject
li_rc = loo_Mboxes.ConnectToNewObject("Chilkat.Mailboxes")

li_Success = loo_Imap.MbxList(li_Subscribed,ls_RefName,ls_WildcardedMailbox,loo_Mboxes)
if li_Success = 0 then
    Write-Debug loo_Imap.LastErrorText
    destroy loo_Imap
    destroy loo_Mboxes
    return
end if

i = 0
do while i < loo_Mboxes.Count
    Write-Debug loo_Mboxes.GetName(i)
    i = i + 1
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.
li_Success = loo_Imap.Disconnect()


destroy loo_Imap
destroy loo_Mboxes