Expand description
Parses and renders email-message values as RFC 822/MIME bytes.
Use this crate at wire-format boundaries such as SMTP submission, .eml
import and export, and MIME processing. The email-message crate remains
responsible for the provider-independent model and outbound validation.
§Quick start
use email_message_wire::{parse_rfc822, render_rfc822};
let raw = b"From: from@example.com\r\nTo: to@example.com\r\n\r\nHello";
let message = parse_rfc822(raw)?;
let _bytes = render_rfc822(&message)?;§Rendering support
- Structured body rendering for text, html, text+html, and MIME trees.
Message::attachmentsrendered as MIME parts with multipart nesting, base64 transfer encoding, Content-Disposition, and optional Content-ID.- RFC2231
filename*=parameter emitted for non-ASCII attachment filenames. - Attachment references are model-level values and must be resolved to bytes before rendering.
§Cargo features
This crate has no optional features, and its default feature set is empty;
default and all-feature builds are therefore equivalent. Its required
email-message dependency always enables that crate’s mime feature, so
email_message::MimePart is also available when both crates occur in the
same dependency graph. Other email-message features remain independent.
§Platform support
This is a std crate with no operating-system APIs or target-specific
implementation. Parsing and rendering operate entirely on in-memory bytes
and support Rust targets that provide the standard library.
§Parser semantics
See parse_rfc822 for the full decoding contract. Highlights:
- Body charsets outside
utf-8/us-ascii/iso-8859-1/latin1are decoded withString::from_utf8_lossy, invalid bytes becomeU+FFFDrather than producing an error. - Encoded words in unsupported charsets pass through as the raw
=?…?=literal. - Duplicate
To:/Cc:/Bcc:/Reply-To:lines are merged. - RFC 6532 (SMTPUTF8) inbound is not supported; non-ASCII header lines fail.
- The returned
Messagehas not been validated for outbound delivery, wrap viaOutboundMessage::newif you intend to send it through aTransport.
Structs§
- Render
Options - Render-time options for
render_rfc822_with.
Enums§
- Message
Parse Error - Errors returned while parsing RFC 822/MIME bytes.
- Message
Render Error - Errors returned while rendering an RFC 822/MIME message.
Constants§
- MAX_
INPUT_ BYTES - Maximum input byte length accepted by
super::parse_rfc822. 16 MiB is far above any practical RFC 5322 message including base64-inflated attachments; anything larger is treated as adversarial and rejected before allocation. - MAX_
MULTIPART_ DEPTH - Maximum nesting depth for
multipart/*parts during inbound parse. Real-world archive formats nest at most ~10 levels; 100 leaves generous headroom while preventing stack-overflow on adversarial input with deeply-nested multipart parts. - MAX_
MULTIPART_ PARTS - Maximum number of sibling parts inside a single multipart body during inbound parse. Adversarial input could otherwise produce millions of empty parts (a “fan-out bomb”) at one level deep.
Functions§
- decode_
rfc2047_ phrase - Opt-in RFC 2047 decoder for header values that the parser preserved as
raw
=?charset?encoding?text?=tokens. - parse_
rfc822 - Parse RFC822/MIME bytes into a structured
Message. - render_
rfc822 - Render a structured
Messageas RFC822/MIME bytes. - render_
rfc822_ with - Render a structured
Messageas RFC822/MIME bytes with custom options.