mail_parser

Struct Message

Source
pub struct Message<'x> {
    pub html_body: Vec<MessagePartId>,
    pub text_body: Vec<MessagePartId>,
    pub attachments: Vec<MessagePartId>,
    pub parts: Vec<MessagePart<'x>>,
    pub raw_message: Cow<'x, [u8]>,
}
Expand description

An RFC5322/RFC822 message.

Fields§

§html_body: Vec<MessagePartId>§text_body: Vec<MessagePartId>§attachments: Vec<MessagePartId>§parts: Vec<MessagePart<'x>>§raw_message: Cow<'x, [u8]>

Implementations§

Source§

impl<'x> Message<'x>

Source

pub fn is_empty(&self) -> bool

Returns false if at least one header field was successfully parsed.

Source

pub fn parse(raw_message: &'x [u8]) -> Option<Message<'x>>

Parses a byte slice containing the RFC5322 raw message and returns a Message struct.

This function never panics, a best-effort is made to parse the message and if no headers are found None is returned.

Source§

impl<'x> Message<'x>

Source

pub fn get_root_part(&self) -> &MessagePart<'x>

Returns the root message part

Source

pub fn get_header(&self, header: &str) -> Option<&HeaderValue<'_>>

Returns a parsed header.

Source

pub fn remove_header(&mut self, header: &str) -> Option<HeaderValue<'_>>

Removed a parsed header and returns its value.

Source

pub fn remove_header_rfc( &mut self, header: RfcHeader, ) -> Option<HeaderValue<'_>>

Removed a parsed RFC heade and returns its value.

Source

pub fn get_header_raw(&self, header: &str) -> Option<&str>

Returns the raw header.

Source

pub fn get_headers(&self) -> &[Header<'_>]

Returns an iterator over the RFC headers of this message.

Source

pub fn get_header_values<'y: 'x>( &'y self, name: RfcHeader, ) -> impl Iterator<Item = &HeaderValue<'x>>

Returns an iterator over the matching RFC headers of this message.

Source

pub fn get_headers_raw(&self) -> impl Iterator<Item = (&str, &str)>

Returns all headers in raw format

Source

pub fn get_bcc(&self) -> &HeaderValue<'_>

Returns the BCC header field

Source

pub fn get_cc(&self) -> &HeaderValue<'_>

Returns the CC header field

Source

pub fn get_comments(&self) -> &HeaderValue<'_>

Returns all Comments header fields

Source

pub fn get_date(&self) -> Option<&DateTime>

Returns the Date header field

Source

pub fn get_from(&self) -> &HeaderValue<'_>

Returns the From header field

Source

pub fn get_in_reply_to(&self) -> &HeaderValue<'_>

Returns all In-Reply-To header fields

Source

pub fn get_keywords(&self) -> &HeaderValue<'_>

Returns all Keywords header fields

Source

pub fn get_list_archive(&self) -> &HeaderValue<'_>

Returns the List-Archive header field

Source

pub fn get_list_help(&self) -> &HeaderValue<'_>

Returns the List-Help header field

Source

pub fn get_list_id(&self) -> &HeaderValue<'_>

Returns the List-ID header field

Source

pub fn get_list_owner(&self) -> &HeaderValue<'_>

Returns the List-Owner header field

Source

pub fn get_list_post(&self) -> &HeaderValue<'_>

Returns the List-Post header field

Source

pub fn get_list_subscribe(&self) -> &HeaderValue<'_>

Returns the List-Subscribe header field

Source

pub fn get_list_unsubscribe(&self) -> &HeaderValue<'_>

Returns the List-Unsubscribe header field

Source

pub fn get_message_id(&self) -> Option<&str>

Returns the Message-ID header field

Source

pub fn get_mime_version(&self) -> &HeaderValue<'_>

Returns the MIME-Version header field

Source

pub fn get_received(&self) -> &HeaderValue<'_>

Returns all Received header fields

Source

pub fn get_references(&self) -> &HeaderValue<'_>

Returns all References header fields

Source

pub fn get_reply_to(&self) -> &HeaderValue<'_>

Returns the Reply-To header field

Source

pub fn get_resent_bcc(&self) -> &HeaderValue<'_>

Returns the Resent-BCC header field

Source

pub fn get_resent_cc(&self) -> &HeaderValue<'_>

Returns the Resent-CC header field

Source

pub fn get_resent_date(&self) -> &HeaderValue<'_>

Returns all Resent-Date header fields

Source

pub fn get_resent_from(&self) -> &HeaderValue<'_>

Returns the Resent-From header field

Source

pub fn get_resent_message_id(&self) -> &HeaderValue<'_>

Returns all Resent-Message-ID header fields

Source

pub fn get_resent_sender(&self) -> &HeaderValue<'_>

Returns the Sender header field

Source

pub fn get_resent_to(&self) -> &HeaderValue<'_>

Returns the Resent-To header field

Source

pub fn get_return_path(&self) -> &HeaderValue<'_>

Returns all Return-Path header fields

Source

pub fn get_return_address(&self) -> Option<&str>

Returns the return address from either the Return-Path or From header fields

Source

pub fn get_sender(&self) -> &HeaderValue<'_>

Returns the Sender header field

Source

pub fn get_subject(&self) -> Option<&str>

Returns the Subject header field

Source

pub fn get_thread_name(&self) -> Option<&str>

Returns the message thread name or ‘base subject’ as defined in RFC 5957 - Internet Message Access Protocol - SORT and THREAD Extensions (Section 2.1)

Source

pub fn get_to(&self) -> &HeaderValue<'_>

Returns the To header field

Source

pub fn get_body_preview(&self, preview_len: usize) -> Option<Cow<'x, str>>

Returns a preview of the message body

Source

pub fn get_html_body(&'x self, pos: usize) -> Option<Cow<'x, str>>

Returns the transformed contents an inline HTML body part by position

Source

pub fn get_text_body(&'x self, pos: usize) -> Option<Cow<'x, str>>

Returns the transformed contents an inline text body part by position

Source

pub fn get_part(&self, pos: usize) -> Option<&MessagePart<'_>>

Returns a message part by position

Source

pub fn get_html_part(&self, pos: usize) -> Option<&MessagePart<'_>>

Returns an inline HTML body part by position

Source

pub fn get_text_part(&self, pos: usize) -> Option<&MessagePart<'_>>

Returns an inline text body part by position

Source

pub fn get_attachment(&self, pos: usize) -> Option<&MessagePart<'x>>

Returns an attacment by position

Source

pub fn get_text_body_count(&self) -> usize

Returns the number of plain text body parts

Source

pub fn get_html_body_count(&self) -> usize

Returns the number of HTML body parts

Source

pub fn get_attachment_count(&self) -> usize

Returns the number of attachments

Source

pub fn get_text_bodies(&'x self) -> BodyPartIterator<'x>

Returns an Interator over the text body parts

Source

pub fn get_html_bodies(&'x self) -> BodyPartIterator<'x>

Returns an Interator over the HTML body parts

Source

pub fn get_attachments(&'x self) -> AttachmentIterator<'x>

Returns an Interator over the attachments

Trait Implementations§

Source§

impl<'x> Clone for Message<'x>

Source§

fn clone(&self) -> Message<'x>

Returns a copy 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<'x> Debug for Message<'x>

Source§

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

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

impl<'x> Default for Message<'x>

Source§

fn default() -> Message<'x>

Returns the “default value” for a type. Read more
Source§

impl<'de: 'x, 'x> Deserialize<'de> for Message<'x>

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<'x> MimeHeaders<'x> for Message<'x>

Source§

fn get_content_description(&self) -> Option<&str>

Returns the Content-Description field
Source§

fn get_content_disposition(&self) -> Option<&ContentType<'_>>

Returns the Content-Disposition field
Source§

fn get_content_id(&self) -> Option<&str>

Returns the Content-ID field
Source§

fn get_content_transfer_encoding(&self) -> Option<&str>

Returns the Content-Encoding field
Source§

fn get_content_type(&self) -> Option<&ContentType<'_>>

Returns the Content-Type field
Source§

fn get_content_language(&self) -> &HeaderValue<'_>

Returns the Content-Language field
Source§

fn get_content_location(&self) -> Option<&str>

Returns the Content-Location field
Source§

fn get_attachment_name(&self) -> Option<&str>

Returns the attachment name, if any.
Source§

impl<'x> PartialEq for Message<'x>

Source§

fn eq(&self, other: &Message<'x>) -> 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<'x> Serialize for Message<'x>

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<'x> StructuralPartialEq for Message<'x>

Auto Trait Implementations§

§

impl<'x> Freeze for Message<'x>

§

impl<'x> RefUnwindSafe for Message<'x>

§

impl<'x> Send for Message<'x>

§

impl<'x> Sync for Message<'x>

§

impl<'x> Unpin for Message<'x>

§

impl<'x> UnwindSafe for Message<'x>

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 = 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>,