diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ffi.rs | 18 | ||||
| -rw-r--r-- | src/message.rs | 65 | ||||
| -rw-r--r-- | src/thread.rs | 4 |
3 files changed, 86 insertions, 1 deletions
@@ -1484,6 +1484,24 @@ extern "C" { exact: notmuch_bool_t, ) -> *mut notmuch_message_properties_t; + + /// Return the number of properties named "key" belonging to the specific message. + /// + /// @param[in] message The message to examine + /// @param[in] key key to count + /// @param[out] count The number of matching properties associated with this message. + /// + /// @returns + /// + /// NOTMUCH_STATUS_SUCCESS: successful count, possibly some other error. + /// + /// @since libnotmuch 5.2 (notmuch 0.27) + pub fn notmuch_message_count_properties( + message: *mut notmuch_message_t, + key: *const c_char, + count: *mut c_uint, + ) -> notmuch_status_t; + /// Is the given *properties* iterator pointing at a valid `(key,value)` pair. /// /// When this function returns TRUE, `notmuch_message_properties_{key,value}` diff --git a/src/message.rs b/src/message.rs index feafcb3..03623a1 100644 --- a/src/message.rs +++ b/src/message.rs @@ -1,6 +1,7 @@ -use std::ffi::CString; +use std::ffi::{CString, CStr}; use std::path::PathBuf; use std::cell::RefCell; +use std::ptr; use supercow::{Supercow}; use error::{Error, Result}; @@ -29,6 +30,16 @@ impl<'o, O> MessageOwner for Message<'o, O> where O: MessageOwner + 'o {} impl<'o, O> FilenamesOwner for Message<'o, O> where O: MessageOwner + 'o {} impl<'o, O> TagsOwner for Message<'o, O> where O: MessageOwner + 'o {} + +// impl<'o, O> PartialEq for Message<'o, O> +// where +// O: MessageOwner + 'o +// { +// fn eq(self: &Self, other: &Message<'o, O>) -> bool{ +// self.id() == other.id() +// } +// } + impl<'o, O> Message<'o, O> where O: MessageOwner + 'o, @@ -137,6 +148,58 @@ where { <Self as MessageExt<'o, O>>::properties(self, key, exact) } + + pub fn remove_all_properties(&self, key: &str) -> Result<()> + { + let key_str = CString::new(key).unwrap(); + unsafe { + ffi::notmuch_message_remove_all_properties(self.ptr, key_str.as_ptr()) + }.as_result() + } + + pub fn count_properties(&self, key: &str) -> Result<u32> + { + let key_str = CString::new(key).unwrap(); + let mut cnt = 0; + unsafe { + ffi::notmuch_message_count_properties(self.ptr, key_str.as_ptr(), &mut cnt) + }.as_result()?; + + Ok(cnt) + } + + pub fn property(&self, key: &str, exact: bool) -> Result<String> + { + let key_str = CString::new(key).unwrap(); + let mut prop = ptr::null(); + unsafe { + ffi::notmuch_message_get_property(self.ptr, key_str.as_ptr(), &mut prop) + }.as_result()?; + + // TODO: the unwrap here is not good + Ok(unsafe{ + CStr::from_ptr(prop) + }.to_str().unwrap().to_string()) + } + + pub fn add_property(&self, key: &str, value: &str) -> Result<()> + { + let key_str = CString::new(key).unwrap(); + let value_str = CString::new(value).unwrap(); + unsafe { + ffi::notmuch_message_add_property(self.ptr, key_str.as_ptr(), value_str.as_ptr()) + }.as_result() + } + + pub fn remove_property(&self, key: &str, value: &str) -> Result<()> + { + let key_str = CString::new(key).unwrap(); + let value_str = CString::new(value).unwrap(); + unsafe { + ffi::notmuch_message_remove_property(self.ptr, key_str.as_ptr(), value_str.as_ptr()) + }.as_result() + } + } pub trait MessageExt<'o, O> diff --git a/src/thread.rs b/src/thread.rs index 34cebd3..1ebcc24 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -61,6 +61,10 @@ where <Self as ThreadExt<'d, 'q>>::toplevel_messages(self) } + pub fn matched_messages(self: &Self) -> i32 { + unsafe { ffi::notmuch_thread_get_matched_messages(self.ptr) } + } + /// Get a `Messages` iterator for all messages in 'thread' in /// oldest-first order. pub fn messages(self: &Self) -> Messages<'_, Self> { |
