Skip to main content

MessagePart

Struct MessagePart 

Source
pub struct MessagePart<'m> { /* private fields */ }
Expand description

A MIME part: a header block and a body. Parts are numbered in document order across nested messages (MessagePart::id), and every message has a root part holding its own header fields.

Bodies are decoded on access: MessagePart::decoded for the transfer encoding, MessagePart::text for text parts (transfer encoding and charset), MessagePart::text_prefix and MessagePart::decoded_len to avoid decoding the whole body.

Implementations§

Source§

impl<'m> MessagePart<'m>

Source

pub fn id(&self) -> PartId

The id of this part in crate::Message::parts: parts of every message are numbered in document order.

Source

pub fn message(&self) -> MessageRef<'m>

The message this part belongs to.

Source

pub fn parent(&self) -> Option<MessagePart<'m>>

The enclosing multipart; None for the root part of a message.

Source

pub fn kind(&self) -> PartKind<'m>

What the part contains, from its Content-Type (and Content-Disposition for PartKind::InlineBinary).

Source

pub fn is_text(&self) -> bool

Whether the part is PartKind::Text or PartKind::Html.

Source

pub fn is_multipart(&self) -> bool

Whether the part is PartKind::Multipart.

Source

pub fn is_message(&self) -> bool

Whether the part is PartKind::Message.

Source

pub fn children( &self, ) -> impl ExactSizeIterator<Item = MessagePart<'m>> + DoubleEndedIterator + use<'m>

Children of a multipart, in order.

Source

pub fn nested(&self) -> Option<MessageRef<'m>>

The nested message of a message/rfc822 part.

Source

pub fn headers(&self) -> Headers<'m>

The header fields of this part.

Source

pub fn content_type(&self) -> Option<ContentType<'m>>

The last Content-Type field, when it parsed.

Source

pub fn content_disposition(&self) -> Option<ContentType<'m>>

The last Content-Disposition field, when it parsed.

Source

pub fn attachment_name(&self) -> Option<&'m str>

The Content-Disposition filename, else the Content-Type name.

Source

pub fn is_content_type(&self, type_: &str, subtype: &str) -> bool

Whether the Content-Type is type_/subtype (ASCII case-insensitive).

Source

pub fn content_id(&self) -> Option<&'m str>

The Content-ID field, without angle brackets.

Source

pub fn content_description(&self) -> Option<&'m str>

The Content-Description field, decoded.

Source

pub fn content_location(&self) -> Option<&'m str>

The Content-Location field.

Source

pub fn content_language(&self) -> Option<TextList<'m>>

The languages of the Content-Language field.

Source

pub fn content_transfer_encoding(&self) -> Option<&'m str>

The Content-Transfer-Encoding field as text: unfolded, trimmed, with encoded words decoded (the crate::HeaderForm::Text form), in the case it was written in. MessagePart::encoding gives the transfer encoding the body is decoded with.

Source

pub fn encoding(&self) -> Encoding

The declared transfer encoding: base64, quoted-printable, or none (7bit, 8bit, binary, no field, or an unknown value).

Source

pub fn flags(&self) -> PartFlags

What happened while the part was parsed.

Source

pub fn has_problems(&self) -> bool

Whether the structure of this part was damaged: any of its PartFlags is set (this replaces 0.11’s is_encoding_problem). Problems found while decoding the body are reported by MessagePart::decoded_checked and MessagePart::text_checked.

Source

pub fn in_text_body(&self) -> bool

Whether the part is in the text body of its message (MessageRef::text_body).

Source

pub fn in_html_body(&self) -> bool

Whether the part is in the HTML body of its message (MessageRef::html_body).

Source

pub fn is_attachment(&self) -> bool

Whether the part is in the attachments of its message (MessageRef::attachments).

Source

pub fn is_inline(&self) -> bool

Whether the part is marked to be rendered inside the message rather than offered as a download (issue #70): Content-Disposition: inline, or no disposition on a child of multipart/related other than the first (the target of a cid: reference). Content-Disposition: attachment is never inline.

This answers the disposition question only. It does not say whether the part is shown in a body list or offered as an attachment; see MessagePart::role and the list membership accessors for that.

Source

pub fn role(&self) -> PartRole

The classifier’s decision for this part. A part copied into the other body list of a multipart/alternative is reported as PartRole::CopiedBody, although it is also in its own list.

Source

pub fn boundary(&self) -> Option<&'m str>

The boundary parameter of a multipart part.

Source

pub fn delimiter(&self) -> Option<&'m str>

The boundary of the enclosing multipart, whose delimiter starts this part.

Source

pub fn raw(&self) -> &'m [u8] ⓘ

Headers and body, excluding the line break before the next delimiter.

Source

pub fn raw_headers(&self) -> &'m [u8] ⓘ

The header block, from the first header to the start of the body (the blank line included). The part ends, like any part, before the line break that precedes its delimiter; when that delimiter cuts the header block (PartFlags::NO_BLANK_LINE), or ends the part and its container right after the blank line, the header block stops there too and excludes that line break, which the last header field (crate::Header::offset_end) or the blank line still covers.

Source

pub fn raw_body(&self) -> &'m [u8] ⓘ

The body as written (still transfer-encoded), excluding the line break before the next delimiter.

Source

pub fn offset_header(&self) -> u32

Offset of the first header of this part in the source buffer of its message (MessageRef::source).

Source

pub fn offset_body(&self) -> u32

Offset of the body of this part in the source buffer of its message.

Source

pub fn offset_end(&self) -> u32

Offset of the end of this part in the source buffer of its message.

Source

pub fn decoded(&self) -> Cow<'m, [u8]>

The transfer-decoded body; borrowed when nothing needs decoding. Malformed input is decoded on a best-effort basis: bytes outside the base64 alphabet are skipped, malformed quoted-printable escapes are kept as written. MessagePart::decoded_checked also reports those problems.

Source

pub fn decode_into(&self, out: &mut Vec<u8>)

Appends the transfer-decoded body to out, for reusing a buffer in a loop.

Source

pub fn decoded_len(&self) -> usize

Length of the transfer-decoded body. Base64 and quoted-printable bodies are measured without being decoded, except base64 with bytes outside the alphabet.

Source

pub fn decoded_checked(&self) -> (Cow<'m, [u8]>, DecodeProblems)

MessagePart::decoded together with the problems found while decoding: malformed base64 or quoted-printable, or an unknown Content-Transfer-Encoding. The bytes are the ones decoded() returns; decoded() stays the faster call when the problems are not needed.

Source

pub fn has_known_transfer_encoding(&self) -> bool

False when the part declares a Content-Transfer-Encoding other than 7bit, 8bit, binary, base64 or quoted-printable, the condition DecodeProblems::UNKNOWN_TRANSFER_ENCODING reports, without decoding the body. True when the field is absent.

Source

pub fn text(&self) -> Option<Cow<'m, str>>

The text of a text or HTML part: transfer-decoded, then converted from its charset (UTF-8 when the charset is missing or unknown; byte sequences that are not valid in the charset become U+FFFD). Borrowed when the body needs no conversion. None for other parts. MessagePart::text_checked also reports decoding problems.

Source

pub fn text_checked(&self) -> Option<(Cow<'m, str>, DecodeProblems)>

MessagePart::text together with the problems found while decoding it: those of MessagePart::decoded_checked, an unknown charset, and byte sequences that are not valid in the charset. The text is the one text() returns. None for parts that are not text.

For JMAP, isEncodingProblem is !problems.is_empty().

Source

pub fn text_prefix(&self, max_chars: usize) -> Option<Cow<'m, str>>

The first max_chars characters of MessagePart::text, decoding only as much of the body as they need. None for other parts.

Source

pub fn text_prefix_bytes(&self, max_bytes: usize) -> Option<Cow<'m, str>>

MessagePart::text cut at str::floor_char_boundary of max_bytes: the longest prefix that is at most max_bytes bytes long and ends on a character boundary. None for other parts.

Source

pub fn text_into(&self, out: &mut String) -> bool

Appends the text of a text or HTML part to out; returns false for other parts.

Source

pub fn html_utf8(&self) -> Option<Cow<'m, str>>

The HTML of an HTML part with its <meta> charset declarations rewritten to UTF-8 (issue #109), so that a browser reading the decoded text does not apply the original charset a second time. None for other parts.

Trait Implementations§

Source§

impl<'m> Clone for MessagePart<'m>

Source§

fn clone(&self) -> Self

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<'m> Copy for MessagePart<'m>

Source§

impl Debug for MessagePart<'_>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'m> Freeze for MessagePart<'m>

§

impl<'m> RefUnwindSafe for MessagePart<'m>

§

impl<'m> Send for MessagePart<'m>

§

impl<'m> Sync for MessagePart<'m>

§

impl<'m> Unpin for MessagePart<'m>

§

impl<'m> UnsafeUnpin for MessagePart<'m>

§

impl<'m> UnwindSafe for MessagePart<'m>

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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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.