[][src]Trait mailparse::MailHeaderMap

pub trait MailHeaderMap {
    fn get_first_value(
        &self,
        key: &str
    ) -> Result<Option<String>, MailParseError>;
fn get_all_values(&self, key: &str) -> Result<Vec<String>, MailParseError>; }

A trait that is implemented by the MailHeader slice. These functions are also available on Vec which is returned by the parse_headers function. It provides a map-like interface to look up header values by their name.

Required methods

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

Look through the list of headers and return the value of the first one that matches the provided key. It returns Ok(None) if the no matching header was found. Header names are matched case-insensitively.

Examples

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

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

Look through the list of headers and return the values of all headers matching the provided key. Returns an empty vector if no matching headers were found. The order of the returned values is the same as the order of the matching headers in the message. Header names are matched case-insensitively.

Examples

    use mailparse::{parse_mail, MailHeaderMap};
    let headers = parse_mail(concat!(
            "Key: Value1\n",
            "Key: Value2").as_bytes())
        .unwrap().headers;
    assert_eq!(headers.get_all_values("Key").unwrap(),
        vec!["Value1".to_string(), "Value2".to_string()]);
Loading content...

Implementations on Foreign Types

impl<'a> MailHeaderMap for [MailHeader<'a>][src]

Loading content...

Implementors

Loading content...