Sample code for 30+ languages & platforms
Perl

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

Perl
use chilkat();

$success = 0;

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

$imap = chilkat::CkImap->new();

$imap->put_Ssl(1);
$imap->put_Port(993);

$success = $imap->Connect("imap.example.com");
if ($success == 0) {
    print $imap->lastErrorText() . "\r\n";
    exit;
}

$success = $imap->Login('user@example.com',"myPassword");
if ($success == 0) {
    print $imap->lastErrorText() . "\r\n";
    exit;
}

#  Remove the subscription to a mailbox (the mailbox is not deleted).
$success = $imap->Unsubscribe("Archive2026");
if ($success == 0) {
    print $imap->lastErrorText() . "\r\n";
    exit;
}

print "Unsubscribed from the mailbox." . "\r\n";

$success = $imap->Disconnect();
if ($success == 0) {
    print $imap->lastErrorText() . "\r\n";
    exit;
}