pub enum MimePart {
Leaf {
content_type: ContentType,
content_transfer_encoding: Option<ContentTransferEncoding>,
content_disposition: Option<ContentDisposition>,
body: Vec<u8>,
},
Multipart {
content_type: ContentType,
boundary: Option<String>,
parts: Vec<Self>,
},
}Expand description
Low-level MIME tree node, gated behind the mime Cargo feature.
MimePart is the kernel’s escape hatch for callers building exotic
MIME structures (custom multipart shapes, hand-rolled
transfer-encoding choices, etc.). High-level paths through
Body::Text / Body::Html / Body::TextAndHtml cover
the common cases and apply byte-discipline (auto-promote non-ASCII
text to base64, etc.) on the caller’s behalf.
§Body byte-discipline is the caller’s responsibility
Constructing MimePart::Leaf directly bypasses the kernel’s
auto-promotion path. The wire renderer enforces header invariants
strictly (rejects raw CR / LF / NUL / non-tab control chars in any
header value, regardless of Content-Transfer-Encoding), but it
trusts the caller’s bytes for body content under any transfer
encoding other than base64 / quoted-printable. That includes
7bit, 8bit, binary, and any Other(...) value: the renderer
emits the body verbatim. RFC 2045 §6.2 forbids bytes > 127 under
7bit and forbids bare CR / LF under both 7bit and 8bit;
callers building MimePart::Leaf with a non-base64 / non-QP
encoding must satisfy those invariants themselves, or downstream
MTAs may reject the message.
§Variant set
Deliberately not #[non_exhaustive]. RFC 2046 closes MIME
parts to exactly discrete (Leaf) and composite (Multipart);
the kernel cannot honestly add a third variant without an RFC
update. The exhaustive match shape lets downstream callers
type-cover both arms without an _ => clause.
§Untrusted-deserialize caveat
MimePart::Multipart { parts: Vec<Self> } is recursive: any
caller deserializing a MimePart (or a Body containing one)
from untrusted input must pre-bound the input length and the
recursion depth. serde_json defaults to a 128-frame recursion
limit which is safe; other formats (e.g. serde_yaml,
bincode, rmp-serde, serde_cbor) may not, and a deeply
nested attacker payload yields a MimePart value of arbitrary
depth. The wire renderer (email_message_wire::render_rfc822)
enforces a MAX_MULTIPART_DEPTH cap on outbound trees, including
up to two frames of attachment-wrapping when inline and/or regular
attachments are present, but other consumers of a deserialized
MimePart (e.g. arbitrary caller code that walks the tree) must
defend themselves.
Variants§
Leaf
Fields
content_type: ContentTypecontent_transfer_encoding: Option<ContentTransferEncoding>content_disposition: Option<ContentDisposition>Multipart
Trait Implementations§
Source§impl<'arbitrary> Arbitrary<'arbitrary> for MimePart
impl<'arbitrary> Arbitrary<'arbitrary> for MimePart
Source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self from the given unstructured data. Read moreSource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self from the entirety of the given
unstructured data. Read moreSource§fn size_hint(depth: usize) -> (usize, Option<usize>)
fn size_hint(depth: usize) -> (usize, Option<usize>)
Unstructured this type
needs to construct itself. Read moreSource§fn try_size_hint(
depth: usize,
) -> Result<(usize, Option<usize>), MaxRecursionReached>
fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>
Unstructured this type
needs to construct itself. Read moreSource§impl<'de> Deserialize<'de> for MimePart
impl<'de> Deserialize<'de> for MimePart
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl JsonSchema for MimePart
impl JsonSchema for MimePart
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Source§fn inline_schema() -> bool
fn inline_schema() -> bool
$ref keyword. Read more