diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-09-21 19:26:16 +0200 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-10-12 19:17:41 +0200 |
commit | 5825022e5d17fa52870c1889a2a0479e1d5a648b (patch) | |
tree | caa62fecd9443bfaccde7444ebe3dc9708ab481b /libimagmail | |
parent | 953f53767063194120e04bfecfa283e1ec088bb0 (diff) |
Impl Mail::get_field()
Diffstat (limited to 'libimagmail')
-rw-r--r-- | libimagmail/src/mail.rs | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/libimagmail/src/mail.rs b/libimagmail/src/mail.rs index dd98345d..62625b03 100644 --- a/libimagmail/src/mail.rs +++ b/libimagmail/src/mail.rs @@ -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>> { |