Rust Requires Chilkat v11.0.0+
Rust
List IMAP Mailboxes
List the mailboxes available within an IMAP account.Chilkat Rust Downloads
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let imap = chilkat::Imap::new();
// Connect to an IMAP server.
// Use TLS
imap.set_ssl(true);
imap.set_port(993);
if imap.connect("MY-IMAP-DOMAIN").is_err() {
println!("{}", imap.last_error_text());
return;
}
// Login
if imap.login("MY-IMAP-LOGIN", "MY-IMAP-PASSWORD").is_err() {
println!("{}", imap.last_error_text());
return;
}
let ref_name = String::new();
// refName is usually set to an empty string.
// A non-empty reference name argument is the name of a mailbox or a level of
// mailbox hierarchy, and indicates the context in which the mailbox
// name is interpreted.
// Select all mailboxes matching this pattern:
let wildcarded_mailbox = "*".to_string();
let subscribed = false;
let mboxes = chilkat::Mailboxes::new();
if imap.mbx_list(subscribed, &ref_name, &wildcarded_mailbox, &mboxes).is_err() {
println!("{}", imap.last_error_text());
return;
}
let mut i = 0;
while i < mboxes.count() {
println!("{}", mboxes.get_name(i).unwrap_or_default());
i = i + 1;
}
// Sample output looks like this:
// INBOX.vendors.shareit
// INBOX.oldSupport
// INBOX.vendors.paypal
// INBOX.sales
// INBOX.lists
// INBOX.Drafts
// INBOX.vendors.dell
// INBOX.Trash
// INBOX.invoiceRequests
// INBOX.purchases
// INBOX.vendors.inMotion
// INBOX.oldEmail
// INBOX.vendors
// INBOX.lists.python
// INBOX.vendors.myhosting
// INBOX.Templates
// INBOX.friends
// INBOX.bounceSamples
// INBOX.lists.ruby
// INBOX.vendors.peer1
// INBOX.Sent
// INBOX.Junk
// INBOX
// Disconnect from the IMAP server.
let _ = imap.disconnect().is_ok();