Skip to main content

Crate email_message_wire

Crate email_message_wire 

Source
Expand description

RFC822/MIME wire parsing and rendering for email-message.

This crate focuses on wire format concerns and keeps email-message focused on outbound message representation.

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).unwrap();
let _bytes = render_rfc822(&message).unwrap();

Current rendering support:

  • Structured body rendering for text, html, text+html, and MIME trees.
  • Message::attachments rendered 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.

§Feature interaction with email-message

Depending on email-message-wire enables email-message’s mime feature for the calling crate as a side effect, MimePart becomes visible in email_message. The wire crate genuinely needs mime for full MIME-tree rendering, so this is unavoidable; downstream crates that want MimePart access have an alternative path through the wire dependency.

§Parser semantics

See parse_rfc822 for the full decoding contract. Highlights:

  • Body charsets outside utf-8/us-ascii/iso-8859-1/latin1 are decoded with String::from_utf8_lossy, invalid bytes become U+FFFD rather 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 Message has not been validated for outbound delivery, wrap via OutboundMessage::new if you intend to send it through a Transport.

Structs§

RenderOptions
Render-time options for render_rfc822_with.

Enums§

MessageParseError
MessageRenderError

Constants§

MAX_INPUT_BYTES
Maximum input byte length accepted by 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 Message as RFC822/MIME bytes.
render_rfc822_with
Render a structured Message as RFC822/MIME bytes with custom options.