Skip to main content

Module multipart_scan

Module multipart_scan 

Source
Expand description

Line-based multipart scanner mirroring the extracted-value semantics of Python’s email feedparser for multipart/form-data bodies.

Source: guard_core/_utils/body_form_scan._multipart_text_parts, a direct port of the Go engine’s multipartscan.go.

  • preamble lines before the opening boundary are discarded, epilogue after the final boundary is discarded;
  • part headers keep their raw name case and wire order; a folded continuation line is appended to the previous value with its original line break preserved (compat32 keeps the raw fold);
  • the first colonless line inside a part ends the header block and that line and everything after it up to the next boundary is the payload (MissingHeaderBodySeparatorDefect);
  • the line terminator preceding a boundary line belongs to the delimiter, everything else (including bare newlines) stays in the payload;
  • a part whose Content-Type is multipart with a boundary parameter is a container: its leaf parts are walked in place (message.walk), the container itself produces no entries; a container without a boundary is an ordinary leaf.

No closing boundary is tolerated: the part parsed so far is kept, matching the email parser’s CloseBoundaryNotFoundDefect behavior. The scanner is line-based over the already-capped body string and part payloads are borrowed slices of it (the engine body is always valid UTF-8, decoded lossily at the adapter boundary).

Structs§

MimeHeaderEntry
One raw part header, in wire order and raw name case.
MultipartPart
One leaf part: raw headers plus the payload bytes as a slice of the body.

Functions§

parse_multipart_parts
Split a multipart body into its leaf parts (nested multipart containers expanded in place).