DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoImap
Variant vMailboxes
Handle hoMailboxes
Integer n
Integer i
String sTemp1
Move False To iSuccess
// 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.
Get Create (RefClass(cComChilkatImap)) To hoImap
If (Not(IsComObjectCreated(hoImap))) Begin
Send CreateComObject of hoImap
End
Set ComSsl Of hoImap To True
Set ComPort Of hoImap To 993
Get ComConnect Of hoImap "imap.example.com" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComLogin Of hoImap "user@example.com" "myPassword" To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
// List all mailboxes. The first argument False requests all (not subscribed-only); "*" matches any name.
Get Create (RefClass(cComChilkatMailboxes)) To hoMailboxes
If (Not(IsComObjectCreated(hoMailboxes))) Begin
Send CreateComObject of hoMailboxes
End
Get pvComObject of hoMailboxes to vMailboxes
Get ComMbxList Of hoImap False "" "*" vMailboxes To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoImap To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComCount Of hoMailboxes To n
Showln "Mailboxes: " n
For i From 0 To (n - 1)
Get ComGetName Of hoMailboxes i To sTemp1
Showln sTemp1
Loop
Get ComDisconnect Of hoImap To iSuccessERROR: ";" expected
End_Procedure