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>
impl<'m> MessagePart<'m>
Sourcepub fn id(&self) -> PartId
pub fn id(&self) -> PartId
The id of this part in crate::Message::parts: parts of every
message are numbered in document order.
Sourcepub fn message(&self) -> MessageRef<'m>
pub fn message(&self) -> MessageRef<'m>
The message this part belongs to.
Sourcepub fn parent(&self) -> Option<MessagePart<'m>>
pub fn parent(&self) -> Option<MessagePart<'m>>
The enclosing multipart; None for the root part of a message.
Sourcepub fn kind(&self) -> PartKind<'m>
pub fn kind(&self) -> PartKind<'m>
What the part contains, from its Content-Type (and
Content-Disposition for PartKind::InlineBinary).
Sourcepub fn is_text(&self) -> bool
pub fn is_text(&self) -> bool
Whether the part is PartKind::Text or PartKind::Html.
Sourcepub fn is_multipart(&self) -> bool
pub fn is_multipart(&self) -> bool
Whether the part is PartKind::Multipart.
Sourcepub fn is_message(&self) -> bool
pub fn is_message(&self) -> bool
Whether the part is PartKind::Message.
Sourcepub fn children(
&self,
) -> impl ExactSizeIterator<Item = MessagePart<'m>> + DoubleEndedIterator + use<'m>
pub fn children( &self, ) -> impl ExactSizeIterator<Item = MessagePart<'m>> + DoubleEndedIterator + use<'m>
Children of a multipart, in order.
Sourcepub fn nested(&self) -> Option<MessageRef<'m>>
pub fn nested(&self) -> Option<MessageRef<'m>>
The nested message of a message/rfc822 part.
Sourcepub fn content_type(&self) -> Option<ContentType<'m>>
pub fn content_type(&self) -> Option<ContentType<'m>>
The last Content-Type field, when it parsed.
Sourcepub fn content_disposition(&self) -> Option<ContentType<'m>>
pub fn content_disposition(&self) -> Option<ContentType<'m>>
The last Content-Disposition field, when it parsed.
Sourcepub fn attachment_name(&self) -> Option<&'m str>
pub fn attachment_name(&self) -> Option<&'m str>
The Content-Disposition filename, else the Content-Type name.
Sourcepub fn is_content_type(&self, type_: &str, subtype: &str) -> bool
pub fn is_content_type(&self, type_: &str, subtype: &str) -> bool
Whether the Content-Type is type_/subtype (ASCII case-insensitive).
Sourcepub fn content_id(&self) -> Option<&'m str>
pub fn content_id(&self) -> Option<&'m str>
The Content-ID field, without angle brackets.
Sourcepub fn content_description(&self) -> Option<&'m str>
pub fn content_description(&self) -> Option<&'m str>
The Content-Description field, decoded.
Sourcepub fn content_location(&self) -> Option<&'m str>
pub fn content_location(&self) -> Option<&'m str>
The Content-Location field.
Sourcepub fn content_language(&self) -> Option<TextList<'m>>
pub fn content_language(&self) -> Option<TextList<'m>>
The languages of the Content-Language field.
Sourcepub fn content_transfer_encoding(&self) -> Option<&'m str>
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.
Sourcepub fn encoding(&self) -> Encoding
pub fn encoding(&self) -> Encoding
The declared transfer encoding: base64, quoted-printable, or none
(7bit, 8bit, binary, no field, or an unknown value).
Sourcepub fn has_problems(&self) -> bool
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.
Sourcepub fn in_text_body(&self) -> bool
pub fn in_text_body(&self) -> bool
Whether the part is in the text body of its message
(MessageRef::text_body).
Sourcepub fn in_html_body(&self) -> bool
pub fn in_html_body(&self) -> bool
Whether the part is in the HTML body of its message
(MessageRef::html_body).
Sourcepub fn is_attachment(&self) -> bool
pub fn is_attachment(&self) -> bool
Whether the part is in the attachments of its message
(MessageRef::attachments).
Sourcepub fn is_inline(&self) -> bool
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.
Sourcepub fn role(&self) -> PartRole
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.
Sourcepub fn delimiter(&self) -> Option<&'m str>
pub fn delimiter(&self) -> Option<&'m str>
The boundary of the enclosing multipart, whose delimiter starts this part.
Sourcepub fn raw(&self) -> &'m [u8] ⓘ
pub fn raw(&self) -> &'m [u8] ⓘ
Headers and body, excluding the line break before the next delimiter.
Sourcepub fn raw_headers(&self) -> &'m [u8] ⓘ
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.
Sourcepub fn raw_body(&self) -> &'m [u8] ⓘ
pub fn raw_body(&self) -> &'m [u8] ⓘ
The body as written (still transfer-encoded), excluding the line break before the next delimiter.
Sourcepub fn offset_header(&self) -> u32
pub fn offset_header(&self) -> u32
Offset of the first header of this part in the source buffer of its
message (MessageRef::source).
Sourcepub fn offset_body(&self) -> u32
pub fn offset_body(&self) -> u32
Offset of the body of this part in the source buffer of its message.
Sourcepub fn offset_end(&self) -> u32
pub fn offset_end(&self) -> u32
Offset of the end of this part in the source buffer of its message.
Sourcepub fn decoded(&self) -> Cow<'m, [u8]>
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.
Sourcepub fn decode_into(&self, out: &mut Vec<u8>)
pub fn decode_into(&self, out: &mut Vec<u8>)
Appends the transfer-decoded body to out, for reusing a buffer in
a loop.
Sourcepub fn decoded_len(&self) -> usize
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.
Sourcepub fn decoded_checked(&self) -> (Cow<'m, [u8]>, DecodeProblems)
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.
Sourcepub fn has_known_transfer_encoding(&self) -> bool
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.
Sourcepub fn text(&self) -> Option<Cow<'m, str>>
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.
Sourcepub fn text_checked(&self) -> Option<(Cow<'m, str>, DecodeProblems)>
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().
Sourcepub fn text_prefix(&self, max_chars: usize) -> Option<Cow<'m, str>>
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.
Sourcepub fn text_prefix_bytes(&self, max_bytes: usize) -> Option<Cow<'m, str>>
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.