Crates.io | pop3-mail-client |
lib.rs | pop3-mail-client |
version | 0.1.0 |
source | src |
created_at | 2024-01-11 19:31:50.877896 |
updated_at | 2024-01-11 19:31:50.877896 |
description | Pop3 Email Client |
homepage | https://github.com/VanOvermeire/pop3-mail-client |
repository | https://github.com/VanOvermeire/pop3-mail-client |
max_upload_size | |
id | 1096581 |
size | 34,106 |
One of many Pop3 clients for Rust.
This one differs from others in some additional safeties (can't compile when you've not connected and/or logged in yet) using type-state. It also offers some convenience methods.
Despite this, based on very limited testing, performance is about the same as that of the other projects mentioned below.
cargo install pop3_mail_client
Or add this to Cargo.toml
:
[dependencies]
pop3_mail_client = "0.1.0"
Create the client using its builder and starting calling the client methods.
use pop3_mail_client::{Pop3Connection, Pop3Client, Pop3Error};
fn main() -> Result<(), Pop3Error> {
let mut connection = Pop3Client::builder()
.username("test@gmail.com")
.password("some-pass")
.connect(Pop3Connection::outlook())?;
// retrieve stats
let stats = connection.stat()?;
println!("{stats:?}");
// or list messages and print their ids
let lists = connection.list()?;
lists.messages.iter().for_each(|m| println!("{}", m.message_id));
// retrieve a message as a string
let res = connection.retrieve_as_string(9999);
println!("{:?}", res);
Ok(())
}
Pop3Error
is a union of all possible errors.
Alternatively, you can also match on the specific errors returned by each method:
use pop3_mail_client::{Pop3Connection, Pop3Client, Pop3Error, ListError};
fn main() -> Result<(), Pop3Error> {
let mut connection = Pop3Client::builder()
.username("test@gmail.com")
.password("some-pass")
.connect(Pop3Connection::outlook())?;
match connection.list() {
// we got back a list of messages
Ok(list) => {
list.messages.iter().for_each(|m| println!("{}", m.message_id));
}
// list might return a ListError
Err(ListError { message }) => {
println!("An error: {}", message);
}
}
Ok(())
}
Pop3Error
is a union (enum) of the following errors:
Name of the command, plus the name in this implementation.
list
and list_id
)retrieve
or retrieve_as_string
)reset
)delete
)uidl
and uidl_with_id
)list_last
(list last x message ids and sizes)retrieve_last_as_string
(retrieve the last email as a string)retrieve_last
(retrieve the last email and pass it to a writer)https://www.ietf.org/rfc/rfc1939.txt