Perl Requires Chilkat v11.0.0+
Perl
List IMAP Mailboxes with Reference
Demonstrates how to list all sub-mailboxes within a specified context. In this case, we list all mailboxes under "INBOX.vendors".Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $imap = Chilkat2::Imap->new;
# Connect to an IMAP server.
# Use TLS
$imap->Ssl(1);
$imap->Port(993);
my $success = $imap->Connect('imap.example.com');
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
# Login
$success = $imap->Login('admin@chilkatsoft.com', 'myPassword');
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
# Get the list of mailboxes.
my $refName = '';
my $wildcardedMailbox = '*';
my $subscribed = 0;
my $mboxes = Chilkat2::Mailboxes->new;
$success = $imap->MbxList($subscribed, $refName, $wildcardedMailbox, $mboxes);
if (!$success) {
print $imap->LastErrorText, "\n";
exit;
}
my $i = 0;
while ($i < $mboxes->Count) {
print $mboxes->GetName($i), "\n";
$i = $i + 1;
}
# Sample output looks like this:
# INBOX.vendors.shareit
# INBOX.vendors.paypal
# INBOX.vendors.dell
# INBOX.vendors.inMotion
# INBOX.vendors.myhosting
# INBOX.vendors.peer1
# Disconnect from the IMAP server.
$success = $imap->Disconnect();