Swift
Swift
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 Swift Downloads
func chilkatTest() {
var success: Bool = false
// Demonstrates the Imap.Unsubscribe method, which removes the subscription to a mailbox.
// The mailbox itself and its messages are not deleted.
let imap = CkoImap()!
imap.ssl = true
imap.port = 993
success = imap.connect(hostname: "imap.example.com")
if success == false {
print("\(imap.lastErrorText!)")
return
}
success = imap.login(login: "user@example.com", password: "myPassword")
if success == false {
print("\(imap.lastErrorText!)")
return
}
// Remove the subscription to a mailbox (the mailbox is not deleted).
success = imap.unsubscribe(mailbox: "Archive2026")
if success == false {
print("\(imap.lastErrorText!)")
return
}
print("Unsubscribed from the mailbox.")
success = imap.disconnect()
if success == false {
print("\(imap.lastErrorText!)")
return
}
}