Skip to main content

MimePart

Enum MimePart 

Source
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: ContentType
§content_transfer_encoding: Option<ContentTransferEncoding>
§content_disposition: Option<ContentDisposition>
§body: Vec<u8>
§

Multipart

Fields

§content_type: ContentType
§boundary: Option<String>
§parts: Vec<Self>

Trait Implementations§

Source§

impl<'arbitrary> Arbitrary<'arbitrary> for MimePart

Source§

fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the given unstructured data. Read more
Source§

fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>

Generate an arbitrary value of Self from the entirety of the given unstructured data. Read more
Source§

fn size_hint(depth: usize) -> (usize, Option<usize>)

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

fn try_size_hint( depth: usize, ) -> Result<(usize, Option<usize>), MaxRecursionReached>

Get a size hint for how many bytes out of an Unstructured this type needs to construct itself. Read more
Source§

impl Clone for MimePart

Source§

fn clone(&self) -> MimePart

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MimePart

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MimePart

Available on crate features mime and serde only.
Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl JsonSchema for MimePart

Available on crate features mime and schemars only.
Source§

fn json_schema(generator: &mut SchemaGenerator) -> Schema

MIME parts have no RFC 5322 string form, so this schema is not wrapped in an rfc5322-string-compat oneOf: [object, string] the way Mailbox / Group / Address are. The asymmetry is deliberate: there is no producer-side wire shape for “MIME part as a header-like string” to migrate from.

Source§

fn schema_name() -> Cow<'static, str>

The name of the generated JSON Schema. Read more
Source§

fn schema_id() -> Cow<'static, str>

Returns a string that uniquely identifies the schema produced by this type. Read more
Source§

fn inline_schema() -> bool

Whether JSON Schemas generated for this type should be included directly in parent schemas, rather than being re-used where possible using the $ref keyword. Read more
Source§

impl PartialEq for MimePart

Source§

fn eq(&self, other: &MimePart) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MimePart

Available on crate features mime and serde only.
Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for MimePart

Source§

impl StructuralPartialEq for MimePart

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,