Skip to main content

ParsedPart

Struct ParsedPart 

Source
#[non_exhaustive]
pub struct ParsedPart { pub part_id: String, pub content_type: String, pub charset: Option<String>, pub transfer_encoding: TransferEncoding, pub disposition: Option<String>, pub filename: Option<String>, pub cid: Option<String>, pub header_range: (u32, u32), pub body_range: (u32, u32), pub children: Vec<ParsedPart>, pub is_encoding_problem: bool, }
Expand description

A single MIME part in the parsed tree.

Byte ranges (header_range, body_range) are (offset, length) indices into the caller’s original &[u8]. The crate never stores raw bytes.

Both fields use u32 to guarantee identical serialized representation on 32-bit and 64-bit hosts. RFC 5321 recommends a 10 MB message size limit; the 4 GiB u32 range covers all realistic messages. Callers processing raw input exceeding 4 GiB MUST reject it before calling parsemail-parser uses usize offsets internally and parse truncates them to u32 via saturating_sub, which would produce incorrect byte ranges without error on oversized input.

For multipart/* parts, children is non-empty and body_range covers the entire multipart body including boundaries.

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§part_id: String

IMAP dotted-path part ID: "1", "1.1", "1.2", etc.

§content_type: String

Content-Type media type/subtype (e.g. "text/plain").

§charset: Option<String>

Charset parameter from Content-Type, if present.

None means no explicit charset= parameter was present on the Content-Type header. Per RFC 2045 §5.2 the default is US-ASCII, but decode_body_value() defaults to UTF-8 instead (a strict superset) for better handling of the modern email corpus.

§transfer_encoding: TransferEncoding

Content-Transfer-Encoding.

§disposition: Option<String>

Content-Disposition value (e.g. "attachment", "inline").

§filename: Option<String>

Filename from Content-Disposition or Content-Type.

§cid: Option<String>

Content-ID header value, if present.

§header_range: (u32, u32)

(offset, length) of this part’s headers in the original bytes.

To access individual typed headers for a part, slice raw[offset..offset+length] and pass the result to parse_header_typed.

§body_range: (u32, u32)

(offset, length) of this part’s body (pre-decode) in the original bytes.

§children: Vec<ParsedPart>

Child parts. Non-empty only for multipart/* content types.

§is_encoding_problem: bool

True if mail-parser flagged this part as having a structural encoding problem (e.g., invalid base64 padding in the raw transfer encoding).

This is a parse-time flag, distinct from [DecodedBodyValue::is_encoding_problem] which is set during charset conversion in decode_body_value().

Implementations§

Source§

impl ParsedPart

Source

pub fn find_by_id(&self, id: &str) -> Option<&ParsedPart>

Find a descendant part by its dotted IMAP part ID.

Searches this part and all descendants depth-first. Returns None if no part with the given ID exists in the tree.

§Part ID conventions
  • Non-multipart root: the root part has part_id = "1".
  • Multipart root: the root part has part_id = "" (empty string); its children are "1", "2", etc.
  • Nested multipart: children use dotted paths like "1.1", "1.2".
// Non-multipart: root is "1"
let raw = b"Content-Type: text/plain\r\n\r\nHello\r\n";
let msg = parse(raw).unwrap();
let part = msg.part_index.find_by_id("1").unwrap();
assert_eq!(part.content_type, "text/plain");

Trait Implementations§

Source§

impl Clone for ParsedPart

Source§

fn clone(&self) -> ParsedPart

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for ParsedPart

Source§

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

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

impl<'de> Deserialize<'de> for ParsedPart

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 Eq for ParsedPart

Source§

impl PartialEq for ParsedPart

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 ParsedPart

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 StructuralPartialEq for ParsedPart

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.