Sample code for 30+ languages & platforms
PureBasic

Unsubscribe from an IMAP Mailbox

See more IMAP Examples

Demonstrates the Chilkat Imap.Unsubscribe method, which removes the subscription to a mailbox. The mailbox itself and its messages are not deleted. This example unsubscribes from a mailbox.

Background: Unsubscribing simply drops a mailbox from the account's subscription list, so clients that show only subscribed folders will stop displaying it — the folder and everything in it remain on the server untouched. This is the counterpart to Subscribe, and is how you declutter a mailbox listing without deleting anything (deleting a folder is DeleteMailbox).

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkImap.pb"

Procedure ChilkatExample()

    success.i = 0

    ;  Demonstrates the Imap.Unsubscribe method, which removes the subscription to a mailbox.
    ;  The mailbox itself and its messages are not deleted.

    imap.i = CkImap::ckCreate()
    If imap.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkImap::setCkSsl(imap, 1)
    CkImap::setCkPort(imap, 993)

    success = CkImap::ckConnect(imap,"imap.example.com")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    success = CkImap::ckLogin(imap,"user@example.com","myPassword")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    ;  Remove the subscription to a mailbox (the mailbox is not deleted).
    success = CkImap::ckUnsubscribe(imap,"Archive2026")
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf

    Debug "Unsubscribed from the mailbox."

    success = CkImap::ckDisconnect(imap)
    If success = 0
        Debug CkImap::ckLastErrorText(imap)
        CkImap::ckDispose(imap)
        ProcedureReturn
    EndIf



    CkImap::ckDispose(imap)


    ProcedureReturn
EndProcedure