Expand description
RFC 5322 / MIME parser producing a byte-range-indexed part tree.
§Quick start
use mime_tree::{parse, decode_body_value};
let raw = b"From: alice@example.com\r\n\
Content-Type: text/plain; charset=utf-8\r\n\
\r\n\
Hello, world!\r\n";
let msg = parse(raw).expect("parse failed");
// text_body / html_body / attachments follow RFC 8621 §4.1.4.
assert_eq!(msg.text_body, vec!["1"]);
assert_eq!(msg.html_body, vec!["1"]); // mirrors text_body for non-multipart
// Decode a body part on demand (transfer-decode + charset-convert).
let part = msg.part_index.find_by_id("1").unwrap();
let decoded = decode_body_value(raw, part, None).unwrap();
assert_eq!(decoded.value, "Hello, world!\r\n");§Design
parse()returns aParsedMessagewith the MIME part tree and RFC 8621text_body/html_body/attachmentspart-ID lists.- Each
ParsedPartcarries(offset, length)byte ranges into the original&[u8]— no raw bytes are stored internally. decode_body_value()decodes a part’s body on demand: transfer-encoding decode (Base64, QP, identity) followed by charset conversion viaencoding_rs.- Parsing is best-effort: malformed input yields a partial result plus
ParsedMessage::warnings. Only empty input or no-headers returnsErr. - No JMAP dependency. No async. No
unsafe.
Structs§
- Address
Group - A group of
EmailAddressvalues, optionally named. - Decoded
Body Value - Result of
decode_body_value(). - Email
Address - A single RFC 5322
mailboxparsed from anaddress-list. - Header
Date Time - An RFC 5322 §3.3
date-timevalue parsed from a header. - InlineUU
Block - A single UU-encoded binary block found inside a part body.
- InlineY
EncBlock - A single yEnc-encoded block found inside a part body.
- Parsed
Header - A decoded RFC 5322 / MIME header field.
- Parsed
Message - The result of
parse(). - Parsed
Part - A single MIME part in the parsed tree.
- Unknown
Header Form - Error returned by
HeaderForm’sFromStrimpl when the input is not a recognised JMAP form-token.
Enums§
- Header
Form - Selector for the RFC 8621 parsed-form of a header value.
- Header
Value Typed - A header field value rendered in one of the RFC 8621 parsed forms.
- Parse
Error - Error returned when
parse()cannot produce any result from the input bytes. - Transfer
Encoding - Transfer encoding of a MIME body part.
- TzSign
- Sign of a
date-timetimezone offset from GMT (RFC 5322 §3.3).
Functions§
- decode_
body_ value - Decode the body of a parsed part.
- parse
- Parse raw RFC 5322 bytes into a
ParsedMessage. - parse_
addresses - Parse the header field value as an RFC 8621 §4.1.2.3 Addresses form: a flat list of mailboxes with group structure discarded.
- parse_
date - Parse the header field value as an RFC 8621 §4.1.2.6 Date form: an
RFC 5322 §3.3 date-time, or
Noneon parse failure. - parse_
grouped_ addresses - Parse the header field value as an RFC 8621 §4.1.2.4 GroupedAddresses form: preserves group structure; a flat mailbox-list is wrapped in a single anonymous group.
- parse_
header_ typed - Parse a header field value into the requested RFC 8621 parsed form.
- parse_
header_ typed_ from - Parse an existing
ParsedHeader’s value into the requested RFC 8621 parsed form. - parse_
message_ ids - Parse the header field value as an RFC 8621 §4.1.2.5 MessageIds form:
<...>-stripped msg-id strings. - parse_
raw - Parse the header field value as an RFC 8621 §4.1.2.1 Raw form: trim surrounding whitespace, decode bytes as UTF-8 (lossy with U+FFFD on invalid sequences).
- parse_
text - Parse the header field value as an RFC 8621 §4.1.2.2 Text form: whitespace unfolded, RFC 2047 encoded-words decoded, Unicode normalised to NFC.
- parse_
urls - Parse the header field value as an RFC 8621 §4.1.2.7 URLs form: bare URL strings with surrounding angle brackets stripped (RFC 2369).
- scan_
inline_ uuencode - Scan a MIME part’s body for inline UU-encoded blocks.
- scan_
inline_ yencode - Scan a MIME part’s body for inline yEnc-encoded blocks.