Skip to main content

scan_inline_uuencode

Function scan_inline_uuencode 

Source
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 to parse()).
  • part — a ParsedPart from the parsed tree. Only part.body_range is used to locate the relevant slice of raw.

§Return value

An empty Vec when:

  • the body contains no begin … end blocks,
  • part.body_range is out of bounds for raw.

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 of raw, matching the coordinate space of part.body_range.
  • For error items where InlineUUBlock::is_encoding_problem is true, begin_offset is the position of the offending begin or begin-base64 line within raw and begin_length is None.
  • 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);