Skip to main content

email_message_wire/
lib.rs

1//! Parses and renders `email-message` values as RFC 822/MIME bytes.
2//!
3//! Use this crate at wire-format boundaries such as SMTP submission, `.eml`
4//! import and export, and MIME processing. The `email-message` crate remains
5//! responsible for the provider-independent model and outbound validation.
6//!
7//! # Quick start
8//!
9//! ```rust
10//! use email_message_wire::{parse_rfc822, render_rfc822};
11//!
12//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
13//! let raw = b"From: from@example.com\r\nTo: to@example.com\r\n\r\nHello";
14//! let message = parse_rfc822(raw)?;
15//! let _bytes = render_rfc822(&message)?;
16//! # Ok(())
17//! # }
18//! ```
19//!
20//! # Rendering support
21//!
22//! - Structured body rendering for text, html, text+html, and MIME trees.
23//! - `Message::attachments` rendered as MIME parts with multipart nesting, base64 transfer
24//!   encoding, Content-Disposition, and optional Content-ID.
25//! - RFC2231 `filename*=` parameter emitted for non-ASCII attachment filenames.
26//! - Attachment references are model-level values and must be resolved to bytes before
27//!   rendering.
28//!
29//! # Cargo features
30//!
31//! This crate has no optional features, and its default feature set is empty;
32//! default and all-feature builds are therefore equivalent. Its required
33//! `email-message` dependency always enables that crate's `mime` feature, so
34//! [`email_message::MimePart`] is also available when both crates occur in the
35//! same dependency graph. Other `email-message` features remain independent.
36//!
37//! # Platform support
38//!
39//! This is a `std` crate with no operating-system APIs or target-specific
40//! implementation. Parsing and rendering operate entirely on in-memory bytes
41//! and support Rust targets that provide the standard library.
42//!
43//! # Parser semantics
44//!
45//! See [`parse_rfc822`] for the full decoding contract. Highlights:
46//! - Body charsets outside `utf-8`/`us-ascii`/`iso-8859-1`/`latin1` are
47//!   decoded with `String::from_utf8_lossy`, invalid bytes become
48//!   `U+FFFD` rather than producing an error.
49//! - Encoded words in unsupported charsets pass through as the raw
50//!   `=?…?=` literal.
51//! - Duplicate `To:`/`Cc:`/`Bcc:`/`Reply-To:` lines are merged.
52//! - RFC 6532 (SMTPUTF8) inbound is not supported; non-ASCII header
53//!   lines fail.
54//! - The returned `Message` has not been validated for outbound
55//!   delivery, wrap via `OutboundMessage::new` if you intend to send
56//!   it through a `Transport`.
57
58mod rfc822;
59
60pub use rfc822::{
61    MAX_INPUT_BYTES, MAX_MULTIPART_DEPTH, MAX_MULTIPART_PARTS, MessageParseError,
62    MessageRenderError, RenderOptions, decode_rfc2047_phrase, parse_rfc822, render_rfc822,
63    render_rfc822_with,
64};