2 releases

0.2.1 Feb 21, 2023
0.2.0 Feb 21, 2023

#10 in #pop3

Download history 19/week @ 2024-02-26 52/week @ 2024-03-04 10/week @ 2024-03-11

81 downloads per month

MPL-2.0 license

16KB
245 lines

rust-pop3-client

POP3 client for rust using rutls.

Features

  • provides all mandatory POP3 commands
  • provides most optional POP3 commands
    (APOP is not provided, since it is not used often)
  • allow to specify own certificates
    (a rustls::RootCertStore instance can be provided, if not system certificates will be used)

Depedency

Cargo.toml:

[dependencies]
rust-pop3-client = "0.2.1"

Example

use std::error::Error;
use std::io::{self, Write};

extern crate rust_pop3_client;

use rust_pop3_client::Pop3Connection;

fn read_value(prompt: &str) -> Result<String, Box<dyn Error>> {
    print!("{}: ", prompt);
    io::stdout().flush()?;
    let mut value = String::new();
    io::stdin().read_line(&mut value)?;
    Ok(String::from(value.trim()))
}

fn read_password(prompt: &str) -> Result<String, Box<dyn Error>> {
    print!("{}: ", prompt);
    io::stdout().flush()?;
    Ok(rpassword::read_password()?)
}

fn main() -> Result<(), Box<dyn Error>> {
    let host = read_value("host (e.g. pop.gmail.com)")?;
    let port = read_value("port (e.g. 995)")?.parse::<u16>()?;
    let user = read_value("user (e-mail address)")?;
    let password = read_password("password")?;

    let mut connection = Pop3Connection::new(&host, port)?;
    connection.login(&user, &password)?;

    println!("id\tsize");
    let infos = connection.list()?;
    for info in infos {
        println!("{}\t{}", info.message_id, info.message_size);
    }

    Ok(())
}

Similar projects

  • rust-pop3
    (Seems promising, but is based on an outdated version of OpenSSL.)

References

Dependencies

~7–18MB
~303K SLoC