Sample code for 30+ languages & platforms
DataFlex

Get IMAP Mailbox Status

See more IMAP Examples

Demonstrates the Chilkat Imap.GetMailboxStatus method, which sends the IMAP STATUS command for a mailbox and returns the reported values as XML attributes — including messages (total count), recent, uidnext, uidvalidity, and unseen. This example gets the Inbox status.

Tip: XML parsing code for this result can be generated at Chilkat Tools.

Background: STATUS queries a mailbox's summary counts without selecting it — ideal for showing unread counts across many folders in a UI, or checking whether a folder has new mail before deciding to open it. Two values are especially useful for sync: uidvalidity (if it changes, previously stored UIDs are no longer valid) and uidnext (the UID the next new message will get, so anything at or above a remembered value is new).

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoImap
    String sStatusXml
    String sTemp1
    Boolean bTemp1

    Move False To iSuccess

    //  Demonstrates the Imap.GetMailboxStatus method, which sends the IMAP STATUS command for a
    //  mailbox and returns the reported values as XML attributes (such as messages, recent,
    //  uidnext, uidvalidity, and unseen).

    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

    //  Get the status of a mailbox (without selecting it).
    Get ComGetMailboxStatus Of hoImap "Inbox" To sStatusXml
    Get ComLastMethodSuccess Of hoImap To bTemp1
    If (bTemp1 = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Showln sStatusXml

    //  XML parsing code for this result can be generated at Chilkat's online tool:
    //  https://tools.chilkat.io/xmlParse

    Get ComDisconnect Of hoImap To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoImap To sTemp1
        Showln sTemp1
        Procedure_Return
    End



End_Procedure