Trait mailparse::MailHeaderMap
source · pub trait MailHeaderMap {
// Required methods
fn get_first_value(&self, key: &str) -> Option<String>;
fn get_first_header(&self, key: &str) -> Option<&MailHeader<'_>>;
fn get_all_values(&self, key: &str) -> Vec<String>;
fn get_all_headers(&self, key: &str) -> Vec<&MailHeader<'_>>;
}
Expand description
A trait that is implemented by the MailHeader slice. These functions are
also available on Vec
Required Methods§
sourcefn get_first_value(&self, key: &str) -> Option<String>
fn get_first_value(&self, key: &str) -> Option<String>
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"), Some("Test".to_string()));
sourcefn get_first_header(&self, key: &str) -> Option<&MailHeader<'_>>
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.
sourcefn get_all_values(&self, key: &str) -> Vec<String>
fn get_all_values(&self, key: &str) -> Vec<String>
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"),
vec!["Value1".to_string(), "Value2".to_string()]);
sourcefn get_all_headers(&self, key: &str) -> Vec<&MailHeader<'_>>
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.