| Crates.io | imap_session |
| lib.rs | imap_session |
| version | 0.1.0 |
| created_at | 2025-11-25 16:23:51.064571+00 |
| updated_at | 2025-11-25 16:23:51.064571+00 |
| description | A wrapper around async_imap offering a simpler way to deal with common IMAP operations |
| homepage | https://github.com/primait/imap.rs |
| repository | https://github.com/primait/imap.rs |
| max_upload_size | |
| id | 1950035 |
| size | 69,350 |
imap_session is the core library of the imap.rs workspace. It provides a robust, idiomatic Rust wrapper built on top of async_imap for managing and performing operations on a single, secure IMAP session.
This crate handles the complexities of connection configuration, TLS handshake, and authentication, making it suitable for short-lived or singular IMAP tasks.
To use imap_session in your project, add the following to your Cargo.toml:
[dependencies]
imap_session = "0.1"
tokio = { version = "1", features = ["full"] }
async-native-tls = { version = "0.5.0", default-features = false, features = [
"tokio",
"runtime-tokio",
"futures-util",
] }
Use imap_session when you only need to open, use, and close a single connection, typically for short-lived tasks like fetching a single piece of data or running a simple command.
use async_native_tls::TlsConnector;
use imap_session::{ConnectionConfig, Credentials, Query, Flag};
use tokio::net::TcpStream;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = ConnectionConfig {
domain: std::env::var("IMAP__HOST").unwrap(),
port: std::env::var("IMAP__PORT").unwrap().parse().unwrap(),
credentials: Credentials {
user: "test".to_string(),
password: "test".to_string(),
},
};
// Do not use `danger_accept_invalid_certs(true)` in production
let tls_connector = TlsConnector::new().danger_accept_invalid_certs(true);
// The connect function handles the TCP connection, TLS upgrade, and login.
let mut session = imap_session::connect(&config, tls_connector).await?;
println!("Successfully connected and logged in.");
// Perform an IMAP search operation
// Search for messages that are NOT yet marked as Seen
let uids = session.search("INBOX", !Query::flag(Flag::Seen)).await?;
println!("INBOX contains {} unseen messages.", uids.len());
// Consumes the session and sends the LOGOUT command
session.logout().await?;
Ok(())
}
This project is licensed under: