aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDirk Van Haerenborgh <vhdirk@gmail.com>2019-10-18 14:12:28 +0200
committerDirk Van Haerenborgh <vhdirk@gmail.com>2019-10-18 14:12:28 +0200
commit24936ad1d0a3489c766c819f2f824962c770cce0 (patch)
tree48832280477a85c7fc7392379884a8d7a6a5eb25
parentcab95623832c0473228f5ad12272f2438620aa68 (diff)
downloadmail-24936ad1d0a3489c766c819f2f824962c770cce0.tar.gz
implement: database_index_message
-rw-r--r--src/database.rs57
-rw-r--r--src/directory.rs2
-rw-r--r--src/ffi.rs60
-rw-r--r--src/index.rs46
-rw-r--r--src/lib.rs4
5 files changed, 164 insertions, 5 deletions
diff --git a/src/database.rs b/src/database.rs
index d591575..b6f68a0 100644
--- a/src/database.rs
+++ b/src/database.rs
@@ -17,6 +17,7 @@ use Tags;
use TagsOwner;
use Message;
use MessageOwner;
+use IndexOpts;
use utils::ScopedSupercow;
@@ -225,8 +226,7 @@ impl Database {
<Self as DatabaseExt>::all_tags(self)
}
- pub fn find_message<'d, P>(&'d self, message_id: &str) -> Result<Option<Message<'d, Self>>>
- {
+ pub fn find_message<'d>(&'d self, message_id: &str) -> Result<Option<Message<'d, Self>>> {
<Self as DatabaseExt>::find_message(self, message_id)
}
@@ -236,6 +236,18 @@ impl Database {
{
<Self as DatabaseExt>::remove_message(self, path)
}
+
+ pub fn get_default_indexopts<'d, P>(&'d self) -> Result<IndexOpts<'d>>
+ {
+ <Self as DatabaseExt>::get_default_indexopts(self)
+ }
+
+ pub fn index_file<'d, P>(&'d self, path: &P, indexopts: Option<IndexOpts<'d>>) -> Result<Option<Message<'d, Self>>>
+ where
+ P: AsRef<Path>,
+ {
+ <Self as DatabaseExt>::index_file(self, path, indexopts)
+ }
}
pub trait DatabaseExt {
@@ -304,7 +316,7 @@ pub trait DatabaseExt {
fn remove_message<'d, D, P>(database: D, path: &P) -> Result<()>
where
- D: Into<Supercow<'d, Database>>,
+ D: Into<ScopedSupercow<'d, Database>>,
P: AsRef<Path>,
{
let dbref = database.into();
@@ -318,6 +330,45 @@ pub trait DatabaseExt {
None => Err(Error::NotmuchError(Status::FileError)),
}
}
+
+ fn get_default_indexopts<'d, D>(database: D) -> Result<IndexOpts<'d>>
+ where
+ D: Into<ScopedSupercow<'d, Database>>
+ {
+ let dbref = database.into();
+
+ let opts = unsafe { ffi::notmuch_database_get_default_indexopts(dbref.ptr) };
+
+ Ok(IndexOpts::from_ptr(opts, ScopedSupercow::phantom(dbref)))
+ }
+
+
+ fn index_file<'d, D, P>(database: D, path: &P, indexopts: Option<IndexOpts<'d>>) -> Result<Option<Message<'d, Database>>>
+ where
+ D: Into<ScopedSupercow<'d, Database>>,
+ P: AsRef<Path>,
+ {
+ let dbref = database.into();
+
+ let opts = indexopts.map_or(ptr::null_mut(), |opt| opt.ptr);
+
+ match path.as_ref().to_str() {
+ Some(path_str) => {
+ let msg_path = CString::new(path_str).unwrap();
+
+ let mut msg = ptr::null_mut();
+ unsafe { ffi::notmuch_database_index_file(dbref.ptr, msg_path.as_ptr(), opts, &mut msg) }
+ .as_result()?;
+
+ if msg.is_null() {
+ Ok(None)
+ } else {
+ Ok(Some(Message::from_ptr(msg, Supercow::phantom(dbref))))
+ }
+ }
+ None => Err(Error::NotmuchError(Status::FileError)),
+ }
+ }
}
impl DatabaseExt for Database {}
diff --git a/src/directory.rs b/src/directory.rs
index 8f09ed7..1c8a3df 100644
--- a/src/directory.rs
+++ b/src/directory.rs
@@ -23,7 +23,7 @@ impl<'d> Drop for Directory<'d> {
impl<'d> FilenamesOwner for Directory<'d> {}
impl<'d> Directory<'d> {
- pub fn from_ptr<O>(ptr: *mut ffi::notmuch_directory_t, owner: O) -> Directory<'d>
+ pub(crate) fn from_ptr<O>(ptr: *mut ffi::notmuch_directory_t, owner: O) -> Directory<'d>
where
O: Into<ScopedPhantomcow<'d, Database>>,
{
diff --git a/src/ffi.rs b/src/ffi.rs
index 3874ae5..7533b06 100644
--- a/src/ffi.rs
+++ b/src/ffi.rs
@@ -112,6 +112,17 @@ notmuch_enum! {
}
}
+notmuch_enum! {
+ #[repr(C)]
+ #[derive(Debug, Eq, PartialEq, Clone, Copy)]
+ pub enum notmuch_decryption_policy_t => DecryptionPolicy {
+ NOTMUCH_DECRYPT_FALSE => False,
+ NOTMUCH_DECRYPT_TRUE => True,
+ NOTMUCH_DECRYPT_AUTO => Auto,
+ NOTMUCH_DECRYPT_NOSTASH => NoStash
+ }
+}
+
#[repr(C)]
pub struct notmuch_database_t(c_void);
#[repr(C)]
@@ -1729,6 +1740,55 @@ extern "C" {
/// @since libnotmuch 4.4 (notmuch 0.23)
pub fn notmuch_config_list_destroy(config_list: *mut notmuch_config_list_t);
+ /// get the current default indexing options for a given database.
+ ///
+ /// This object will survive until the database itself is destroyed,
+ /// but the caller may also release it earlier with
+ /// notmuch_indexopts_destroy.
+ ///
+ /// This object represents a set of options on how a message can be
+ /// added to the index. At the moment it is a featureless stub.
+ ///
+ /// @since libnotmuch 5.1 (notmuch 0.26)
+ pub fn notmuch_database_get_default_indexopts(db: *mut notmuch_database_t) -> *mut notmuch_indexopts_t;
+
+
+ ////
+ //// Stating a policy about how to decrypt messages.
+ ////
+ //// See index.decrypt in notmuch-config(1) for more details.
+ ////
+ //// typedef enum {
+ //// NOTMUCH_DECRYPT_FALSE,
+ //// NOTMUCH_DECRYPT_TRUE,
+ //// NOTMUCH_DECRYPT_AUTO,
+ //// NOTMUCH_DECRYPT_NOSTASH,
+ //// } notmuch_decryption_policy_t;
+ ////
+ ////
+ //// Specify whether to decrypt encrypted parts while indexing.
+ ////
+ //// Be aware that the index is likely sufficient to reconstruct the
+ //// cleartext of the message itself, so please ensure that the notmuch
+ //// message index is adequately protected. DO NOT SET THIS FLAG TO TRUE
+ //// without considering the security of your index.
+ ////
+ //// @since libnotmuch 5.1 (notmuch 0.26)
+ pub fn notmuch_indexopts_set_decrypt_policy(options: *mut notmuch_indexopts_t,
+ decrypt_policy: notmuch_decryption_policy_t) -> notmuch_status_t;
+
+ //// Return whether to decrypt encrypted parts while indexing.
+ //// see notmuch_indexopts_set_decrypt_policy.
+ ////
+ //// @since libnotmuch 5.1 (notmuch 0.26)
+ pub fn notmuch_indexopts_get_decrypt_policy(options: *const notmuch_indexopts_t) -> notmuch_decryption_policy_t;
+
+
+ /// Destroy a notmuch_indexopts_t object.
+ ///
+ /// @since libnotmuch 5.1 (notmuch 0.26)
+ pub fn notmuch_indexopts_destroy(options: *mut notmuch_indexopts_t);
+
/// interrogate the library for compile time features
///
/// @since libnotmuch 4.4 (notmuch 0.23)
diff --git a/src/index.rs b/src/index.rs
new file mode 100644
index 0000000..41505b6
--- /dev/null
+++ b/src/index.rs
@@ -0,0 +1,46 @@
+use std::ops::Drop;
+use supercow::Supercow;
+
+use error::{Error, Result};
+use ffi;
+use ffi::DecryptionPolicy;
+use Database;
+use Filenames;
+use FilenamesOwner;
+use utils::{ScopedSupercow, ScopedPhantomcow};
+
+
+#[derive(Debug)]
+pub struct IndexOpts<'d> {
+ pub(crate) ptr: *mut ffi::notmuch_indexopts_t,
+ marker: ScopedPhantomcow<'d, Database>,
+}
+
+impl<'d> Drop for IndexOpts<'d> {
+ fn drop(&mut self) {
+ unsafe { ffi::notmuch_indexopts_destroy(self.ptr) };
+ }
+}
+
+impl<'d> IndexOpts<'d> {
+ pub fn from_ptr<O>(ptr: *mut ffi::notmuch_indexopts_t, owner: O) -> IndexOpts<'d>
+ where
+ O: Into<ScopedPhantomcow<'d, Database>>,
+ {
+ IndexOpts {
+ ptr,
+ marker: owner.into(),
+ }
+ }
+
+ pub fn set_decrypt_policy(self: &Self, decrypt_policy: DecryptionPolicy) -> Result<()> {
+ unsafe { ffi::notmuch_indexopts_set_decrypt_policy(self.ptr, decrypt_policy.into()) }.as_result()
+ }
+
+ pub fn get_decrypt_policy(self: &Self) -> DecryptionPolicy {
+ unsafe { ffi::notmuch_indexopts_get_decrypt_policy(self.ptr)}.into()
+ }
+}
+
+unsafe impl<'d> Send for IndexOpts<'d> {}
+unsafe impl<'d> Sync for IndexOpts<'d> {} \ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index ef8cc33..2d43f21 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,6 +20,7 @@ mod query;
mod tags;
mod thread;
mod threads;
+mod index;
pub use database::{Database, DatabaseExt};
pub use directory::{Directory, DirectoryExt};
@@ -31,5 +32,6 @@ pub use query::{Query, QueryExt};
pub use tags::{Tags, TagsExt, TagsOwner};
pub use thread::{Thread, ThreadExt};
pub use threads::{Threads, ThreadsExt};
+pub use index::IndexOpts;
-pub use ffi::{DatabaseMode, Sort}; \ No newline at end of file
+pub use ffi::{DatabaseMode, Sort, DecryptionPolicy}; \ No newline at end of file