Struct mailparse::MailHeader

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

A struct that represents a single header in the message. It holds slices into the raw byte array passed to parse_mail, and so the lifetime of this struct must be contained within the lifetime of the raw input. There are additional accessor functions on this struct to extract the data as Rust strings.

Implementations§

source§

impl<'a> MailHeader<'a>

source

pub fn get_key(&self) -> String

Get the name of the header. Note that header names are case-insensitive. Prefer using get_key_ref where possible for better performance.

source

pub fn get_key_ref(&self) -> Cow<'_, str>

Get the name of the header, borrowing if it’s ASCII-only. Note that header names are case-insensitive.

source

pub fn get_value(&self) -> String

Get the value of the header. Any sequences of newlines characters followed by whitespace are collapsed into a single space. In effect, header values wrapped across multiple lines are compacted back into one line, while discarding the extra whitespace required by the MIME format. Additionally, any quoted-printable words in the value are decoded. Note that this function attempts to decode the header value bytes as UTF-8 first, and falls back to Latin-1 if the UTF-8 decoding fails. This attempts to be compliant with both RFC 6532 as well as older versions of this library. To avoid the Latin-1 fallback decoding, which may end up returning “garbage”, prefer using the get_value_utf8 function instead, which will fail and return an error instead of falling back to Latin-1.

Examples
    use mailparse::parse_header;
    let (parsed, _) = parse_header(b"Subject: =?iso-8859-1?Q?=A1Hola,_se=F1or!?=").unwrap();
    assert_eq!(parsed.get_key(), "Subject");
    assert_eq!(parsed.get_value(), "\u{a1}Hola, se\u{f1}or!");
source

pub fn get_value_utf8(&self) -> Result<String, MailParseError>

Get the value of the header. Any sequences of newlines characters followed by whitespace are collapsed into a single space. In effect, header values wrapped across multiple lines are compacted back into one line, while discarding the extra whitespace required by the MIME format. Additionally, any quoted-printable words in the value are decoded. As per RFC 6532, this function assumes the raw header value is encoded as UTF-8, and does that decoding prior to tokenization and other processing. An EncodingError is returned if the raw header value cannot be decoded as UTF-8.

Examples
    use mailparse::parse_header;
    let (parsed, _) = parse_header(b"Subject: \xC2\xA1Hola, se\xC3\xB1or!").unwrap();
    assert_eq!(parsed.get_key(), "Subject");
    assert_eq!(parsed.get_value(), "\u{a1}Hola, se\u{f1}or!");
source

pub fn get_key_raw(&self) -> &[u8]

Get the raw, unparsed value of the header key.

Examples
    use mailparse::parse_header;
    let (parsed, _) = parse_header(b"SuBJect : =?iso-8859-1?Q?=A1Hola,_se=F1or!?=").unwrap();
    assert_eq!(parsed.get_key_raw(), "SuBJect ".as_bytes());
source

pub fn get_value_raw(&self) -> &[u8]

Get the raw, unparsed value of the header value.

Examples
    use mailparse::parse_header;
    let (parsed, _) = parse_header(b"Subject: =?iso-8859-1?Q?=A1Hola,_se=F1or!?=").unwrap();
    assert_eq!(parsed.get_key(), "Subject");
    assert_eq!(parsed.get_value_raw(), "=?iso-8859-1?Q?=A1Hola,_se=F1or!?=".as_bytes());

Trait Implementations§

source§

impl<'a> Debug for MailHeader<'a>

Custom Debug trait for better formatting and printing of MailHeader items.

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for MailHeader<'a>

§

impl<'a> Send for MailHeader<'a>

§

impl<'a> Sync for MailHeader<'a>

§

impl<'a> Unpin for MailHeader<'a>

§

impl<'a> UnwindSafe for MailHeader<'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.