diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/ffi.rs | 17 | ||||
| -rw-r--r-- | src/message.rs | 55 |
2 files changed, 60 insertions, 12 deletions
@@ -1445,6 +1445,23 @@ extern "C" { key: *const c_char, ) -> notmuch_status_t; + /// Remove all (prefix*,value) pairs from the given message + /// + /// @param[in,out] message message to operate on. + /// @param[in] prefix delete properties with keys that start with prefix. + /// If NULL, delete all properties + /// @returns + /// - NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in + /// read-only mode so message cannot be modified. + /// - NOTMUCH_STATUS_SUCCESS: No error occurred. + /// + /// @since libnotmuch 5.1 (notmuch 0.26) + /// + pub fn notmuch_message_remove_all_properties_with_prefix( + message: *mut notmuch_message_t, + prefix: *const c_char, + ) -> notmuch_status_t; + /// Get the properties for *message*, returning a /// `notmuch_message_properties_t` object which can be used to iterate over /// all properties. diff --git a/src/message.rs b/src/message.rs index 03623a1..8263908 100644 --- a/src/message.rs +++ b/src/message.rs @@ -144,19 +144,47 @@ where unsafe { ffi::notmuch_message_thaw(self.ptr) }.as_result() } - pub fn properties<'m>(&'m self, key: &str, exact: bool) -> MessageProperties<'m, 'o, O> - { + pub fn properties<'m>(&'m self, key: &str, exact: bool) -> MessageProperties<'m, 'o, O> { <Self as MessageExt<'o, O>>::properties(self, key, exact) } - pub fn remove_all_properties(&self, key: &str) -> Result<()> + pub fn remove_all_properties(&self, key: Option<&str>) -> Result<()> { - let key_str = CString::new(key).unwrap(); - unsafe { - ffi::notmuch_message_remove_all_properties(self.ptr, key_str.as_ptr()) - }.as_result() + match key { + Some(k) => { + let key_str = CString::new(k).unwrap(); + unsafe { + ffi::notmuch_message_remove_all_properties(self.ptr, key_str.as_ptr()) + }.as_result() + }, + None => { + let p = ptr::null(); + unsafe { + ffi::notmuch_message_remove_all_properties(self.ptr, p) + }.as_result() + } + } + } + + pub fn remove_all_properties_with_prefix(&self, prefix: Option<&str>) -> Result<()> + { + match prefix { + Some(k) => { + let key_str = CString::new(k).unwrap(); + unsafe { + ffi::notmuch_message_remove_all_properties_with_prefix(self.ptr, key_str.as_ptr()) + }.as_result() + }, + None => { + let p = ptr::null(); + unsafe { + ffi::notmuch_message_remove_all_properties_with_prefix(self.ptr, p) + }.as_result() + } + } } + pub fn count_properties(&self, key: &str) -> Result<u32> { let key_str = CString::new(key).unwrap(); @@ -176,10 +204,14 @@ where 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()) + if prop.is_null() { + Err(Error::UnspecifiedError) + } else { + // 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<()> @@ -199,7 +231,6 @@ where ffi::notmuch_message_remove_property(self.ptr, key_str.as_ptr(), value_str.as_ptr()) }.as_result() } - } pub trait MessageExt<'o, O> |
