Rust
Rust
Get the Number of IMAP Attachments
See more IMAP Examples
Demonstrates the Chilkat Imap.GetMailNumAttach method, which returns the number of ordinary attachments on a message. The only argument is the Email. This example fetches only the headers and reports the attachment count.
Background: A header-only fetch downloads no attachment bodies, so the
Email object's own downloaded-attachment count can be 0. GetMailNumAttach instead reads the ckx-imap-numAttach metadata, giving the true count — which is what you want when building a message list that shows whether each message has attachments.Chilkat Rust Downloads
// Demonstrates the Imap.GetMailNumAttach method, which returns the number of ordinary
// attachments on a message. The only argument is the Email.
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;
}
if imap.select_mailbox("Inbox").is_err() {
println!("{}", imap.last_error_text());
return;
}
// Fetch only the message headers. Attachment bodies are NOT downloaded, but the ckx-imap-*
// metadata describing the attachments is present, so the attachment info methods still work.
let headers_only = true;
let use_uid = false;
let seq_num = 1;
let email = chilkat::Email::new();
if imap.fetch_email(headers_only, seq_num as u32, use_uid, &email).is_err() {
println!("{}", imap.last_error_text());
return;
}
let num_attach = imap.get_mail_num_attach(&email);
println!("This message has {} attachment(s).", num_attach);
if imap.disconnect().is_err() {
println!("{}", imap.last_error_text());
return;
}