Skip to main content

Crate mailrs_smtp_proto

Crate mailrs_smtp_proto 

Source
Expand description

SMTP protocol parser, formatter, and session state machine.

mailrs-smtp-proto is a zero-I/O implementation of RFC 5321 (SMTP) and its common extensions: STARTTLS (RFC 3207), AUTH PLAIN / LOGIN (RFC 4954), and SMTPUTF8 (RFC 6531). It parses incoming command lines into typed Command enums, formats outgoing responses, and drives the SMTP session state machine — but it never touches the network. The caller owns all I/O.

This crate underpins the inbound SMTP server in mailrs, a Rust mail server, and is published independently so other Rust projects can reuse the parsing + state-machine layer without pulling in a full server.

§Quick start

use mailrs_smtp_proto::{parse_command, Command, Session, SessionConfig, Event};

// parse a wire-format command line
let cmd = parse_command("EHLO mail.example.com").unwrap();
assert!(matches!(cmd, Command::Ehlo("mail.example.com")));

// drive the session state machine
let mut session = Session::new("smtp.example.com", SessionConfig::default());
let event = session.handle_command(&cmd);
assert!(matches!(event, Event::Reply(_)));

§What this crate does

§What this crate does NOT do

  • No I/O. No TCP, no TLS, no async runtime. The caller wires it.
  • No content scanning, no message storage, no DKIM/SPF/DMARC.
  • No outbound SMTP client. See mailrs-smtp-client for that.

Re-exports§

pub use command::AuthMechanism;
pub use command::Command;
pub use command::ForwardPath;
pub use command::Param;
pub use command::ReversePath;
pub use data::unstuff_data;
pub use data::unstuff_line;
pub use parse::ParseError;
pub use parse::parse_command;
pub use response::EnhancedCode;
pub use response::Response;
pub use response::format_ehlo_response;
pub use session::AuthStep;
pub use session::Event;
pub use session::MAX_MESSAGE_SIZE;
pub use session::MAX_RECIPIENTS;
pub use session::Session;
pub use session::SessionConfig;
pub use session::State;

Modules§

address
Minimal email address helpers (validation and local/domain split).
auth
SASL helpers for AUTH PLAIN (RFC 4616) and AUTH LOGIN.
command
Typed SMTP command representation.
data
DATA-stage helpers: remove SMTP dot-stuffing from message bodies.
parse
Wire-format command-line parser for SMTP.
response
SMTP response codes, enhanced status codes, and well-known reply constructors.
session
SMTP session state machine.