Skip to main content

MessageParser

Struct MessageParser 

Source
pub struct MessageParser { /* private fields */ }
Expand description

RFC5322/RFC822 message parser.

Implementations§

Source§

impl MessageParser

Source

pub fn new() -> Self

Create a new builder for a message parser using the default settings.

The default settings are:

  • IANA-registered headers defined in HeaderName are parsed with their corresponding parser.
  • Other headers (HeaderName::Other) are parsed as raw.
Source

pub fn with_mime_headers(self) -> Self

Parse all MIME headers:

  • Content-Type
  • Content-Disposition
  • Content-Id
  • Content-Description
  • Content-Location
  • Content-Transfer-Encoding

Adding these MIME headers is required in order to parse message bodies.

Source

pub fn with_date_headers(self) -> Self

Parse all Date headers:

  • Date
  • Resent-Date
Source

pub fn with_address_headers(self) -> Self

Parse all address headers:

  • From
  • Sender
  • Reply-To
  • To
  • Cc
  • Bcc
  • Resent-From
  • Resent-Sender
  • Resent-To
  • Resent-Cc
  • Resent-Bcc
Source

pub fn with_message_ids(self) -> Self

Parse all ID headers:

  • Message-Id
  • In-Reply-To
  • References
  • Resent-Message-Id
Source

pub fn with_minimal_headers(self) -> Self

Parse all MIME headers plus:

  • Date
  • From
  • Reply-To
  • To
  • Cc
  • Bcc
Source

pub fn without_header(self, header: impl Into<HeaderName<'static>>) -> Self

Remove a custom header parser.

Source

pub fn header_text(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as text decoding RFC 2047 encoded words.

Source

pub fn header_date(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as a RFC 5322 date.

Source

pub fn header_address(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as an address.

Source

pub fn header_id(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as an ID.

Source

pub fn header_content_type(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as a MIME Content-Type or Content-Disposition type.

Source

pub fn header_comma_separated( self, header: impl Into<HeaderName<'static>>, ) -> Self

Parse a header as a comma-separated list of values.

Source

pub fn header_received(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as a received header.

Source

pub fn header_raw(self, header: impl Into<HeaderName<'static>>) -> Self

Parse a header as a raw string, no RFC 2047 decoding is done.

Source

pub fn ignore_header(self, header: impl Into<HeaderName<'static>>) -> Self

Ignore and skip parsing a header.

Source

pub fn default_header_text(self) -> Self

Parse all other headers as text decoding RFC 2047 encoded words.

Source

pub fn default_header_raw(self) -> Self

Parse all other headers as raw strings, no RFC 2047 decoding is done.

Source

pub fn default_header_ignore(self) -> Self

Ignore and skip parsing all other headers.

Source§

impl MessageParser

Source

pub fn parse<'x>( &self, raw_message: &'x (impl AsRef<[u8]> + ?Sized), ) -> 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

pub fn parse_headers<'x>( &self, raw_message: &'x (impl AsRef<[u8]> + ?Sized), ) -> Option<Message<'x>>

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

Trait Implementations§

Source§

impl Clone for MessageParser

Source§

fn clone(&self) -> MessageParser

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 MessageParser

Source§

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

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

impl Default for MessageParser

Source§

fn default() -> Self

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

impl Eq for MessageParser

Source§

impl PartialEq for MessageParser

Source§

fn eq(&self, other: &MessageParser) -> 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 StructuralPartialEq for MessageParser

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> 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.