Skip to main content

Headers

Struct Headers 

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

The header fields of one part, in the order they were written.

Accessors that return one field (Headers::get, Headers::value, Headers::subject, …) return the last occurrence of the name, as 0.11 did. Names compare ASCII case-insensitively.

use mail_parser::{HeaderName, MessageParser};

let raw = b"Subject: first\r\nX-Tag: a\r\nSubject: second\r\n\r\nbody";
let message = MessageParser::new().parse(raw).expect("message");
let headers = message.headers();
assert_eq!(headers.len(), 3);
assert_eq!(headers.subject(), Some("second"));
assert_eq!(headers.all(HeaderName::Subject).count(), 2);
assert_eq!(headers.get("x-tag").map(|header| header.raw_value()), Some(&b" a\r\n"[..]));

Implementations§

Source§

impl<'m> Headers<'m>

Source

pub fn len(&self) -> usize

Number of header fields.

Source

pub fn is_empty(&self) -> bool

Whether the part has no header field.

Source

pub fn iter(&self) -> HeaderIter<'m> ⓘ

Every header in document order. for header in headers does the same.

Source

pub fn get<'n>(&self, name: impl Into<HeaderName<'n>>) -> Option<Header<'m>>

The last header with this name. A HeaderName::Other spelled like a known name finds that name.

Source

pub fn get_key(&self, key: HeaderKey<'_>) -> Option<Header<'m>>

The last header with the name of this key; see HeaderName::key.

Source

pub fn all<'n>(&self, name: impl Into<HeaderName<'n>>) -> NamedHeaders<'m, 'n> ⓘ

Every header with this name, in document order. A HeaderName::Other spelled like a known name finds that name.

Source

pub fn all_key<'k>(&self, key: HeaderKey<'k>) -> NamedHeaders<'m, 'k> ⓘ

Every header with the name of this key, in document order; see HeaderName::key.

Source

pub fn contains<'n>(&self, name: impl Into<HeaderName<'n>>) -> bool

Whether a header with this name is present.

Source

pub fn has_known(&self) -> bool

Whether at least one header has a known name: a cheap test that the input looks like a message rather than arbitrary text.

Source

pub fn value<'n>( &self, name: impl Into<HeaderName<'n>>, ) -> Option<HeaderValue<'m>>

The value of the last header with this name.

Source

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

The Subject field, RFC 2047 encoded words decoded.

Source

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

The Comments field, decoded.

Source

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

The MIME-Version field, as written.

Source

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

The subject with reply and forward markers removed; see crate::thread_name.

Source

pub fn from(&self) -> Option<AddressList<'m>>

The From field.

Source

pub fn to(&self) -> Option<AddressList<'m>>

The To field.

Source

pub fn cc(&self) -> Option<AddressList<'m>>

The Cc field.

Source

pub fn bcc(&self) -> Option<AddressList<'m>>

The Bcc field.

Source

pub fn reply_to(&self) -> Option<AddressList<'m>>

The Reply-To field.

Source

pub fn sender(&self) -> Option<AddressList<'m>>

The Sender field.

Source

pub fn all_from(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>

Every From field, in document order.

Source

pub fn all_to(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>

Every To field, in document order.

Source

pub fn all_cc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>

Every Cc field, in document order.

Source

pub fn all_bcc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>

Every Bcc field, in document order.

Source

pub fn resent_to(&self) -> Option<AddressList<'m>>

The Resent-To field.

Source

pub fn resent_from(&self) -> Option<AddressList<'m>>

The Resent-From field.

Source

pub fn resent_cc(&self) -> Option<AddressList<'m>>

The Resent-Cc field.

Source

pub fn resent_bcc(&self) -> Option<AddressList<'m>>

The Resent-Bcc field.

Source

pub fn resent_sender(&self) -> Option<AddressList<'m>>

The Resent-Sender field.

Source

pub fn list_archive(&self) -> Option<AddressList<'m>>

The List-Archive field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

pub fn list_help(&self) -> Option<AddressList<'m>>

The List-Help field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

pub fn list_id(&self) -> Option<AddressList<'m>>

The List-ID field (RFC 2919): the description in crate::Mailbox::name, the identifier in crate::Mailbox::address.

Source

pub fn list_owner(&self) -> Option<AddressList<'m>>

The List-Owner field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

pub fn list_post(&self) -> Option<AddressList<'m>>

The List-Post field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

pub fn list_subscribe(&self) -> Option<AddressList<'m>>

The List-Subscribe field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

pub fn list_unsubscribe(&self) -> Option<AddressList<'m>>

The List-Unsubscribe field (RFC 2369); the URLs are in crate::Mailbox::address.

Source

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

The Date field.

Source

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

The Resent-Date field.

Source

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

The last identifier of the Message-ID field, without angle brackets.

Source

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

The identifiers of the In-Reply-To field.

Source

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

The identifiers of the References field.

Source

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

The identifiers of the Resent-Message-ID field.

Source

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

The Return-Path field, parsed as message identifiers (the address without angle brackets).

Source

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

The phrases of the Keywords field.

Source

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

The last address of Return-Path, or else the first address of From.

Source

pub fn received(&self) -> Option<Received<'m>>

The last Received field (the oldest hop).

Source

pub fn all_received(&self) -> impl Iterator<Item = Received<'m>> + use<'m>

Every Received field, in document order.

Trait Implementations§

Source§

impl<'m> Clone for Headers<'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 Headers<'m>

Source§

impl Debug for Headers<'_>

Source§

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

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

impl<'m> IntoIterator for Headers<'m>

Source§

type Item = Header<'m>

The type of the elements being iterated over.
Source§

type IntoIter = HeaderIter<'m>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> HeaderIter<'m> ⓘ

Creates an iterator from a value. Read more
Source§

impl<'m> IntoIterator for &Headers<'m>

Source§

type Item = Header<'m>

The type of the elements being iterated over.
Source§

type IntoIter = HeaderIter<'m>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> HeaderIter<'m> ⓘ

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<'m> Freeze for Headers<'m>

§

impl<'m> RefUnwindSafe for Headers<'m>

§

impl<'m> Send for Headers<'m>

§

impl<'m> Sync for Headers<'m>

§

impl<'m> Unpin for Headers<'m>

§

impl<'m> UnsafeUnpin for Headers<'m>

§

impl<'m> UnwindSafe for Headers<'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.