Struct mailparse::headers::Headers

source ·
pub struct Headers<'a> { /* private fields */ }
Expand description

A struct that wrapps the header portion of a message and provides utility functions to look up specific headers.

Implementations§

source§

impl<'a> Headers<'a>

source

pub fn get_raw_bytes(&self) -> &'a [u8]

Returns the raw, unparsed bytes that make up the header block of the message. This includes everything up to and including the empty line at the end of the header block.

§Examples
    use mailparse::{parse_mail, headers::Headers};
    let mail = parse_mail(concat!(
            "SubJECT : foo\n",
            "\n",
            "Body starts here").as_bytes())
        .unwrap();
    assert_eq!(mail.get_headers().get_raw_bytes(), b"SubJECT : foo\n\n");

Trait Implementations§

source§

impl<'a> Debug for Headers<'a>

Allows formatting and printing the Headers struct items.

§Examples

    use mailparse::parse_mail;
    let mail = parse_mail(concat!(
            "Subject: foo\n",
            "Another header: bar\n",
            "\n",
            "Body starts here").as_bytes())
        .unwrap();
    let mut headers = mail.get_headers();
    assert_eq!(format!("{:?}", headers), "Headers { \
               headers: [MailHeader { key: \"Subject\", value: \"foo\" }, \
               MailHeader { key: \"Another header\", value: \"bar\" }] }");
source§

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

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

impl<'a> IntoIterator for Headers<'a>

Allows iterating over the individual MailHeader items in this block of headers.

§Examples

    use mailparse::{parse_mail, headers::Headers};
    let mail = parse_mail(concat!(
            "Subject: foo\n",
            "Another header: bar\n",
            "\n",
            "Body starts here").as_bytes())
        .unwrap();
    let mut iter = mail.get_headers().into_iter();
    assert_eq!(iter.next().unwrap().get_key(), "Subject");
    assert_eq!(iter.next().unwrap().get_key(), "Another header");
§

type Item = &'a MailHeader<'a>

The type of the elements being iterated over.
§

type IntoIter = Iter<'a, MailHeader<'a>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<'a> MailHeaderMap for Headers<'a>

source§

fn get_first_value(&self, key: &str) -> Option<String>

§Examples
    use mailparse::{parse_mail, MailHeaderMap, headers::Headers};
    let mail = parse_mail(concat!(
            "Subject: Test\n",
            "\n",
            "This is a test message").as_bytes())
        .unwrap();
    assert_eq!(mail.get_headers().get_first_value("Subject"), Some("Test".to_string()));
source§

fn get_all_values(&self, key: &str) -> Vec<String>

§Examples
    use mailparse::{parse_mail, MailHeaderMap, headers::Headers};
    let mail = parse_mail(concat!(
            "Key: Value1\n",
            "Key: Value2").as_bytes())
        .unwrap();
    assert_eq!(mail.get_headers().get_all_values("Key"),
        vec!["Value1".to_string(), "Value2".to_string()]);
source§

fn get_first_header(&self, key: &str) -> Option<&MailHeader<'_>>

Similar to get_first_value, except it returns a reference to the MailHeader struct instead of just extracting the value.
source§

fn get_all_headers(&self, key: &str) -> Vec<&MailHeader<'_>>

Similar to get_all_values, except it returns references to the MailHeader structs instead of just extracting the values.

Auto Trait Implementations§

§

impl<'a> Freeze for Headers<'a>

§

impl<'a> RefUnwindSafe for Headers<'a>

§

impl<'a> Send for Headers<'a>

§

impl<'a> Sync for Headers<'a>

§

impl<'a> Unpin for Headers<'a>

§

impl<'a> UnwindSafe for Headers<'a>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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.