pub fn scan_inline_uuencode(raw: &[u8], part: &ParsedPart) -> Vec<InlineUUBlock>Expand description
Scan a MIME part’s body for inline UU-encoded blocks.
Slices raw using part.body_range to obtain the body bytes, then scans
for one or more begin NNN filename / end UU blocks embedded anywhere
in the body text. Returns one InlineUUBlock per block found.
Delegates to uuencoding::scan() for all parsing and decoding, so all
real-world tolerance built into that crate (CRLF line endings, space/backtick
zero-value handling, begin-base64 detection, data-after-terminator
discarding, etc.) applies automatically.
§Parameters
raw— the full raw message bytes (same buffer you passed toparse()).part— aParsedPartfrom the parsed tree. Onlypart.body_rangeis used to locate the relevant slice ofraw.
§Return value
An empty Vec when:
- the body contains no
begin … endblocks, part.body_rangeis out of bounds forraw.
Otherwise, one entry per block found, in the order they appear in the body.
§Notes
- This function does not call
decode_body_value()internally. It works directly on the raw bytes of the body without any transfer-encoding decode or charset conversion. - Byte offsets in the returned
InlineUUBlocks are absolute — they are relative to the start ofraw, matching the coordinate space ofpart.body_range. - For error items where
InlineUUBlock::is_encoding_problemistrue,begin_offsetis the position of the offendingbeginorbegin-base64line withinrawandbegin_lengthisNone. - No panic occurs on any input (malformed, truncated, or adversarial).
§Example
use mime_tree::{parse, scan_inline_uuencode};
// A text/plain message with an inline UU block.
// Oracle (Python 3.12 `uu` module):
// uu.encode(b"Hello", ...) → b'begin 644 hello.txt\n%2&5L;&\\ \n \nend\n'
let raw: &[u8] = b"Content-Type: text/plain\r\n\r\nbegin 644 hello.txt\n%2&5L;&\\ \n \nend\n";
let msg = parse(raw).unwrap();
let part = msg.part_index.find_by_id("1").unwrap();
let blocks = scan_inline_uuencode(raw, part);
assert_eq!(blocks.len(), 1);
assert_eq!(blocks[0].mode, 0o644);
assert_eq!(blocks[0].filename, "hello.txt");
assert_eq!(blocks[0].data, b"Hello");
assert!(!blocks[0].is_encoding_problem);