From cc6896cca0839f5d97c5daee8ffba824c3c0d229 Mon Sep 17 00:00:00 2001 From: Dirk Van Haerenborgh Date: Thu, 14 Nov 2019 19:22:38 +0100 Subject: add more tests --- src/message.rs | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) (limited to 'src/message.rs') 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 { >::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 + { + 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 + { + 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> -- cgit v1.2.1