Trait mailparse::MailHeaderMap
[−]
[src]
pub trait MailHeaderMap { fn get_first_value(&self, key: &str) -> Result<Option<String>, MailParseError>; fn get_first_value_ci(&self, key: &str) -> Result<Option<String>, MailParseError>; fn get_all_values(&self, key: &str) -> Result<Vec<String>, MailParseError>; fn get_all_values_ci(&self, key: &str) -> Result<Vec<String>, MailParseError>; }
A trait that is implemented by the Vec
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.
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_first_value_ci(&self, key: &str) -> Result<Option<String>, MailParseError>
Same as get_first_value, but does a case-insensitive search for the header. According to the spec the mail headers are supposed to be case-sensitive, but in real-world scenarios that's not always the case.
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.
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()]);
fn get_all_values_ci(&self, key: &str) -> Result<Vec<String>, MailParseError>
Same as get_all_values, but does a case-insensitive search for the header. According to the spec the mail headers are supposed to be case-sensitive, but in real-world scenarios that's not always the case.
Implementors
impl<'a> MailHeaderMap for Vec<MailHeader<'a>>