PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Imap
oleobject loo_Mailboxes
integer n
integer i
li_Success = 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.
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
loo_Imap.Ssl = 1
loo_Imap.Port = 993
li_Success = loo_Imap.Connect("imap.example.com")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
li_Success = loo_Imap.Login("user@example.com","myPassword")
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
return
end if
// List all mailboxes. The first argument 0 requests all (not subscribed-only); "*" matches any name.
loo_Mailboxes = create oleobject
li_rc = loo_Mailboxes.ConnectToNewObject("Chilkat.Mailboxes")
li_Success = loo_Imap.MbxList(0,"","*",loo_Mailboxes)
if li_Success = 0 then
Write-Debug loo_Imap.LastErrorText
destroy loo_Imap
destroy loo_Mailboxes
return
end if
n = loo_Mailboxes.Count
Write-Debug "Mailboxes: " + string(n)
for i = 0 to n - 1
Write-Debug loo_Mailboxes.GetName(i)
next
li_Success = loo_Imap.DisconnectERROR: ";" expected
destroy loo_Imap
destroy loo_Mailboxes