diff options
| author | eaon <eaon@mit.edu> | 2018-11-02 23:02:37 +0100 |
|---|---|---|
| committer | Dirk Van Haerenborgh <vhdirk@gmail.com> | 2018-11-02 23:02:37 +0100 |
| commit | 361e1a8f12590c49b969fc4c01ede1454ec69776 (patch) | |
| tree | becfe68fc5111f7670c0ace44257e31d6bc7312a | |
| parent | 9d7bb8e01a7ec9fea02b31334822a95e10d5a7e4 (diff) | |
| download | mail-361e1a8f12590c49b969fc4c01ede1454ec69776.tar.gz | |
Add Message::{date,add_tag,remove_tag,remove_all_tags} and make clippy usable (#6)
* Removing unnecessary lifetimes and borrows
* Add Message::{date,add_tag,remove_tag,remove_all_tags}
* Make sure clippy doesn't error out
| -rw-r--r-- | src/ffi.rs | 6 | ||||
| -rw-r--r-- | src/message.rs | 34 | ||||
| -rw-r--r-- | src/thread.rs | 2 |
3 files changed, 35 insertions, 7 deletions
@@ -47,14 +47,14 @@ notmuch_enum! { } impl notmuch_status_t { - pub fn is_ok(&self) -> bool { - match *self { + pub fn is_ok(self) -> bool { + match self { notmuch_status_t::NOTMUCH_STATUS_SUCCESS => true, _ => false, } } - pub fn is_err(&self) -> bool { + pub fn is_err(self) -> bool { !self.is_ok() } diff --git a/src/message.rs b/src/message.rs index 624817d..ed72997 100644 --- a/src/message.rs +++ b/src/message.rs @@ -5,6 +5,7 @@ use supercow::Phantomcow; use error::{Error, Result}; use ffi; +use ffi::Status; use utils::ToStr; use Filenames; use FilenamesOwner; @@ -57,7 +58,7 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { tid.to_str().unwrap().to_string() } - pub fn replies<'s>(self: &'s Self) -> Messages<'s, Self> { + pub fn replies(self: &Self) -> Messages<Self> { Messages::from_ptr( unsafe { ffi::notmuch_message_get_replies(self.handle.ptr) }, self, @@ -84,9 +85,16 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { ) } + pub fn date(&self) -> i64 { + unsafe { + ffi::notmuch_message_get_date(self.handle.ptr) + } + } + pub fn header(&self, name: &str) -> Result<&str> { + let name = CString::new(name).unwrap(); let ret = unsafe { - ffi::notmuch_message_get_header(self.handle.ptr, CString::new(name).unwrap().as_ptr()) + ffi::notmuch_message_get_header(self.handle.ptr, name.as_ptr()) }; if ret.is_null() { Err(Error::UnspecifiedError) @@ -95,12 +103,32 @@ impl<'o, Owner: MessageOwner + 'o> Message<'o, Owner> { } } - pub fn tags<'m>(&'m self) -> Tags<'m, Self> { + pub fn tags(&self) -> Tags<Self> { Tags::from_ptr( unsafe { ffi::notmuch_message_get_tags(self.handle.ptr) }, self, ) } + + pub fn add_tag(self: &Self, tag: &str) -> Status { + let tag = CString::new(tag).unwrap(); + Status::from(unsafe { + ffi::notmuch_message_add_tag(self.handle.ptr, tag.as_ptr()) + }) + } + + pub fn remove_tag(self: &Self, tag: &str) -> Status { + let tag = CString::new(tag).unwrap(); + Status::from(unsafe { + ffi::notmuch_message_remove_tag(self.handle.ptr, tag.as_ptr()) + }) + } + + pub fn remove_all_tags(self: &Self) -> Status { + Status::from(unsafe { + ffi::notmuch_message_remove_all_tags(self.handle.ptr) + }) + } } unsafe impl<'o, Owner: MessageOwner + 'o> Send for Message<'o, Owner> {} diff --git a/src/thread.rs b/src/thread.rs index 9a63c94..c112e06 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -71,7 +71,7 @@ impl<'o, Owner: ThreadOwner + 'o> Thread<'o, Owner> { ) } - pub fn tags<'t>(&'t self) -> Tags<'t, Self> { + pub fn tags(&self) -> Tags<Self> { Tags::from_ptr( unsafe { ffi::notmuch_thread_get_tags(self.handle.ptr) }, self, |
