Sample code for 30+ languages & platforms
Rust Requires Chilkat v11.0.0+

POP3 Verify Signed (S/MIME) Email

Demonstrates how to download and verify digitally signed S/MIME email.

Chilkat Rust Downloads

Rust

// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let mailman = chilkat::MailMan::new();

// Set the POP3 server's hostname
mailman.set_mail_host("pop.example.com");

// Set the POP3 login/password.
mailman.set_pop_username("myLogin");
mailman.set_pop_password("myPassword");

let st_uidls = chilkat::StringTable::new();
if mailman.fetch_uidls(&st_uidls).is_err() {
    println!("{}", mailman.last_error_text());
    return;
}

let email = chilkat::Email::new();
let cert = chilkat::Cert::new();

let count = st_uidls.count();
let mut i = 0;
while i < count {
    // Download the full email.
    if mailman.fetch_by_uidl(&st_uidls.string_at(i).unwrap_or_default(), false, 0, &email).is_err() {
        println!("{}", mailman.last_error_text());
        return;
    }

    println!("{}", i);
    println!("From: {}", email.from());
    println!("Subject: {}", email.subject());

    // The security layers of signed and/or encrypted emails
    // are automatically "unwrapped" when loaded into
    // a Chilkat email object.
    // An application only needs to check to see if an email
    // was received signed or encrypted, and then examine
    // the success/failure.  For example:
    if email.received_signed() {

        println!("This email was signed.");

        // Check to see if the signatures were verified.
        if email.signatures_valid() {
            println!("Digital signature(s) verified.");
            println!("Signer: {}", email.signed_by());

            if email.last_signer_cert(0, &cert).is_err() {
                println!("{}", email.last_error_text());
                return;
            }

            println!("Signing cert: {}", cert.subject_cn());
        }

    } else {
        println!("Digital signature verification failed.");
    }

    i = i + 1;
}

let _ = mailman.pop3_end_session();