Skip to main content

Crate mime_tree

Crate mime_tree 

Source
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 a ParsedMessage with the MIME part tree and RFC 8621 text_body / html_body / attachments part-ID lists.
  • Each ParsedPart carries (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 via encoding_rs.
  • Parsing is best-effort: malformed input yields a partial result plus ParsedMessage::warnings. Only empty input or no-headers returns Err.
  • No JMAP dependency. No async. No unsafe.

Structs§

AddressGroup
A group of EmailAddress values, optionally named.
DecodedBodyValue
Result of decode_body_value().
EmailAddress
A single RFC 5322 mailbox parsed from an address-list.
HeaderDateTime
An RFC 5322 §3.3 date-time value parsed from a header.
InlineUUBlock
A single UU-encoded binary block found inside a part body.
InlineYEncBlock
A single yEnc-encoded block found inside a part body.
ParsedHeader
A decoded RFC 5322 / MIME header field.
ParsedMessage
The result of parse().
ParsedPart
A single MIME part in the parsed tree.
UnknownHeaderForm
Error returned by HeaderForm’s FromStr impl when the input is not a recognised JMAP form-token.

Enums§

HeaderForm
Selector for the RFC 8621 parsed-form of a header value.
HeaderValueTyped
A header field value rendered in one of the RFC 8621 parsed forms.
ParseError
Error returned when parse() cannot produce any result from the input bytes.
TransferEncoding
Transfer encoding of a MIME body part.
TzSign
Sign of a date-time timezone 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 None on 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.