Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

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

let imap = chilkat::Imap::new();

imap.set_ssl(true);
imap.set_port(993);

if imap.connect("imap.example.com").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

if imap.login("user@example.com", "myPassword").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

// Remove the subscription to a mailbox (the mailbox is not deleted).
if imap.unsubscribe("Archive2026").is_err() {
    println!("{}", imap.last_error_text());
    return;
}

println!("Unsubscribed from the mailbox.");

if imap.disconnect().is_err() {
    println!("{}", imap.last_error_text());
    return;
}