Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oImap

nSuccess := 0

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

oImap := CreateObject("Chilkat.Imap")

oImap:Ssl := 1
oImap:Port := 993

nSuccess := oImap:Connect("imap.example.com")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

nSuccess := oImap:Login("user@example.com", "myPassword")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

//  Remove the subscription to a mailbox (the mailbox is not deleted).
nSuccess := oImap:Unsubscribe("Archive2026")
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

? "Unsubscribed from the mailbox."

nSuccess := oImap:Disconnect()
IF (nSuccess == 0)
    ? oImap:LastErrorText
    oImap:destroy()
    RETURN
ENDIF

oImap:destroy()