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>
impl<'m> Headers<'m>
Sourcepub fn iter(&self) -> HeaderIter<'m> ⓘ
pub fn iter(&self) -> HeaderIter<'m> ⓘ
Every header in document order. for header in headers does the
same.
Sourcepub fn get<'n>(&self, name: impl Into<HeaderName<'n>>) -> Option<Header<'m>>
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.
Sourcepub fn get_key(&self, key: HeaderKey<'_>) -> Option<Header<'m>>
pub fn get_key(&self, key: HeaderKey<'_>) -> Option<Header<'m>>
The last header with the name of this key; see HeaderName::key.
Sourcepub fn all<'n>(&self, name: impl Into<HeaderName<'n>>) -> NamedHeaders<'m, 'n> ⓘ
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.
Sourcepub fn all_key<'k>(&self, key: HeaderKey<'k>) -> NamedHeaders<'m, 'k> ⓘ
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.
Sourcepub fn contains<'n>(&self, name: impl Into<HeaderName<'n>>) -> bool
pub fn contains<'n>(&self, name: impl Into<HeaderName<'n>>) -> bool
Whether a header with this name is present.
Sourcepub fn has_known(&self) -> bool
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.
Sourcepub fn value<'n>(
&self,
name: impl Into<HeaderName<'n>>,
) -> Option<HeaderValue<'m>>
pub fn value<'n>( &self, name: impl Into<HeaderName<'n>>, ) -> Option<HeaderValue<'m>>
The value of the last header with this name.
Sourcepub fn mime_version(&self) -> Option<&'m str>
pub fn mime_version(&self) -> Option<&'m str>
The MIME-Version field, as written.
Sourcepub fn thread_name(&self) -> Option<&'m str>
pub fn thread_name(&self) -> Option<&'m str>
The subject with reply and forward markers removed; see
crate::thread_name.
Sourcepub fn from(&self) -> Option<AddressList<'m>>
pub fn from(&self) -> Option<AddressList<'m>>
The From field.
Sourcepub fn to(&self) -> Option<AddressList<'m>>
pub fn to(&self) -> Option<AddressList<'m>>
The To field.
Sourcepub fn cc(&self) -> Option<AddressList<'m>>
pub fn cc(&self) -> Option<AddressList<'m>>
The Cc field.
Sourcepub fn bcc(&self) -> Option<AddressList<'m>>
pub fn bcc(&self) -> Option<AddressList<'m>>
The Bcc field.
Sourcepub fn reply_to(&self) -> Option<AddressList<'m>>
pub fn reply_to(&self) -> Option<AddressList<'m>>
The Reply-To field.
Sourcepub fn sender(&self) -> Option<AddressList<'m>>
pub fn sender(&self) -> Option<AddressList<'m>>
The Sender field.
Sourcepub fn all_from(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
pub fn all_from(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
Every From field, in document order.
Sourcepub fn all_to(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
pub fn all_to(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
Every To field, in document order.
Sourcepub fn all_cc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
pub fn all_cc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
Every Cc field, in document order.
Sourcepub fn all_bcc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
pub fn all_bcc(&self) -> impl Iterator<Item = AddressList<'m>> + use<'m>
Every Bcc field, in document order.
Sourcepub fn resent_to(&self) -> Option<AddressList<'m>>
pub fn resent_to(&self) -> Option<AddressList<'m>>
The Resent-To field.
Sourcepub fn resent_from(&self) -> Option<AddressList<'m>>
pub fn resent_from(&self) -> Option<AddressList<'m>>
The Resent-From field.
Sourcepub fn resent_cc(&self) -> Option<AddressList<'m>>
pub fn resent_cc(&self) -> Option<AddressList<'m>>
The Resent-Cc field.
Sourcepub fn resent_bcc(&self) -> Option<AddressList<'m>>
pub fn resent_bcc(&self) -> Option<AddressList<'m>>
The Resent-Bcc field.
Sourcepub fn resent_sender(&self) -> Option<AddressList<'m>>
pub fn resent_sender(&self) -> Option<AddressList<'m>>
The Resent-Sender field.
Sourcepub fn list_archive(&self) -> Option<AddressList<'m>>
pub fn list_archive(&self) -> Option<AddressList<'m>>
The List-Archive field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn list_help(&self) -> Option<AddressList<'m>>
pub fn list_help(&self) -> Option<AddressList<'m>>
The List-Help field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn list_id(&self) -> Option<AddressList<'m>>
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.
Sourcepub fn list_owner(&self) -> Option<AddressList<'m>>
pub fn list_owner(&self) -> Option<AddressList<'m>>
The List-Owner field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn list_post(&self) -> Option<AddressList<'m>>
pub fn list_post(&self) -> Option<AddressList<'m>>
The List-Post field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn list_subscribe(&self) -> Option<AddressList<'m>>
pub fn list_subscribe(&self) -> Option<AddressList<'m>>
The List-Subscribe field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn list_unsubscribe(&self) -> Option<AddressList<'m>>
pub fn list_unsubscribe(&self) -> Option<AddressList<'m>>
The List-Unsubscribe field (RFC 2369); the URLs are in
crate::Mailbox::address.
Sourcepub fn resent_date(&self) -> Option<DateTime>
pub fn resent_date(&self) -> Option<DateTime>
The Resent-Date field.
Sourcepub fn message_id(&self) -> Option<&'m str>
pub fn message_id(&self) -> Option<&'m str>
The last identifier of the Message-ID field, without angle brackets.
Sourcepub fn in_reply_to(&self) -> Option<TextList<'m>>
pub fn in_reply_to(&self) -> Option<TextList<'m>>
The identifiers of the In-Reply-To field.
Sourcepub fn references(&self) -> Option<TextList<'m>>
pub fn references(&self) -> Option<TextList<'m>>
The identifiers of the References field.
Sourcepub fn resent_message_id(&self) -> Option<TextList<'m>>
pub fn resent_message_id(&self) -> Option<TextList<'m>>
The identifiers of the Resent-Message-ID field.
Sourcepub fn return_path(&self) -> Option<TextList<'m>>
pub fn return_path(&self) -> Option<TextList<'m>>
The Return-Path field, parsed as message identifiers (the address without angle brackets).
Sourcepub fn return_address(&self) -> Option<&'m str>
pub fn return_address(&self) -> Option<&'m str>
The last address of Return-Path, or else the first address of From.
Sourcepub fn all_received(&self) -> impl Iterator<Item = Received<'m>> + use<'m>
pub fn all_received(&self) -> impl Iterator<Item = Received<'m>> + use<'m>
Every Received field, in document order.