diff options
| author | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-10-15 22:13:32 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2018-10-15 22:13:32 +0200 |
| commit | 9fc489fcf484a5a643d34cbdd9ccd9403f6acd66 (patch) | |
| tree | 63251bfba78be1041bea19851d6aecd45cf47e32 | |
| parent | 6804f1d38c587638b9cd47ca37d8dbb7815cf954 (diff) | |
| parent | 971e42d7ce8981ef145e02dc99bbcb6d0559eebf (diff) | |
| download | mail-9fc489fcf484a5a643d34cbdd9ccd9403f6acd66.tar.gz | |
Merge pull request #4 from rhn/master
Add Message::header
| -rw-r--r-- | src/error.rs | 3 | ||||
| -rw-r--r-- | src/message.rs | 15 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/error.rs b/src/error.rs index b1e5cdc..6434ee3 100644 --- a/src/error.rs +++ b/src/error.rs @@ -14,6 +14,7 @@ pub type Result<T> = result::Result<T, Error>; pub enum Error { IoError(io::Error), NotmuchError(ffi::Status), + UnspecifiedError, } impl fmt::Display for Error { @@ -27,6 +28,7 @@ impl std::error::Error for Error { match *self { Error::IoError(ref e) => error::Error::description(e), Error::NotmuchError(ref e) => e.description(), + Error::UnspecifiedError => "Generic notmuch error", } } @@ -34,6 +36,7 @@ impl std::error::Error for Error { match *self { Error::IoError(ref e) => Some(e), Error::NotmuchError(ref e) => Some(e), + Error::UnspecifiedError => None } } } diff --git a/src/message.rs b/src/message.rs index 81d2417..094f5dc 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,6 +1,9 @@ use std::ops::Drop; use std::marker::PhantomData; use std::path::PathBuf; +use std::ffi::CString; + +use error::{Error, Result}; use ffi; use utils::{ @@ -63,6 +66,18 @@ impl<'d, 'q> Message<'d, 'q>{ ffi::notmuch_message_get_filename(self.0) }.to_str().unwrap()) } + + pub fn header(&self, name: &str) -> Result<&str> { + let ret = unsafe { + ffi::notmuch_message_get_header(self.0, + CString::new(name).unwrap().as_ptr()) + }; + if ret.is_null() { + Err(Error::UnspecifiedError) + } else { + Ok(ret.to_str().unwrap()) + } + } } |
