Impl Mail::get_field()
This commit is contained in:
parent
953f537670
commit
5825022e5d
1 changed files with 13 additions and 2 deletions
|
@ -79,8 +79,19 @@ impl<'a> Mail<'a> {
|
|||
.map(|buffer| Some(Mail(r, buffer)))
|
||||
}
|
||||
|
||||
pub fn get_field<S: AsRef<str>>(&self, field: S) -> Result<Option<&str>> {
|
||||
unimplemented!()
|
||||
pub fn get_field(&self, field: &str) -> Result<Option<String>> {
|
||||
use mailparse::MailHeader;
|
||||
|
||||
self.1
|
||||
.parsed()
|
||||
.map_err_into(MEK::MailParsingError)
|
||||
.map(|parsed| {
|
||||
parsed.headers
|
||||
.iter()
|
||||
.filter(|hdr| hdr.get_key().map(|n| n == field).unwrap_or(false))
|
||||
.next()
|
||||
.and_then(|field| field.get_value().ok())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_from(&self) -> Result<Option<&str>> {
|
||||
|
|
Loading…
Reference in a new issue