diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-01-03 11:51:01 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-01-03 11:51:02 +0100 |
commit | f79593d9b95172aa9b2039d2a5f1384167b14863 (patch) | |
tree | b58819a8c77dcea9c89f76dde10dbc4d9a7a61f3 | |
parent | 1a9fc47a805d2dc86b163d1ce524d88dee076893 (diff) |
Add Mail::{get_,neighbors}()
This patch adds functions to get the direct neighbors of a mail.
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/domain/libimagmail/Cargo.toml | 1 | ||||
-rw-r--r-- | lib/domain/libimagmail/src/lib.rs | 1 | ||||
-rw-r--r-- | lib/domain/libimagmail/src/mail.rs | 52 |
3 files changed, 53 insertions, 1 deletions
diff --git a/lib/domain/libimagmail/Cargo.toml b/lib/domain/libimagmail/Cargo.toml index 32255a51..1585dd12 100644 --- a/lib/domain/libimagmail/Cargo.toml +++ b/lib/domain/libimagmail/Cargo.toml @@ -32,5 +32,6 @@ serde_derive = "1.0.94" libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" } libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" } libimagentryref = { version = "0.10.0", path = "../../../lib/entry/libimagentryref" } +libimagentrylink = { version = "0.10.0", path = "../../../lib/entry/libimagentrylink/" } libimagentryutil = { version = "0.10.0", path = "../../../lib/entry/libimagentryutil/" } diff --git a/lib/domain/libimagmail/src/lib.rs b/lib/domain/libimagmail/src/lib.rs index 32f1da64..1a58df0a 100644 --- a/lib/domain/libimagmail/src/lib.rs +++ b/lib/domain/libimagmail/src/lib.rs @@ -49,6 +49,7 @@ extern crate serde; extern crate libimagerror; #[macro_use] extern crate libimagstore; extern crate libimagentryref; +extern crate libimagentrylink; #[macro_use] extern crate libimagentryutil; module_entry_path_mod!("mail"); diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs index 1d2f5a2d..b33b4f91 100644 --- a/lib/domain/libimagmail/src/mail.rs +++ b/lib/domain/libimagmail/src/mail.rs @@ -27,12 +27,19 @@ use libimagentryutil::isa::Is; use libimagentryutil::isa::IsKindHeaderPathProvider; use libimagentryref::reference::Config as RefConfig; use libimagentryref::reference::{Ref, RefFassade}; +use libimagentrylink::linkable::Linkable; +use libimagstore::store::Store; +use libimagstore::storeid::StoreId; +use libimagstore::storeid::StoreIdIterator; +use libimagstore::iter::get::StoreIdGetIteratorExtension; use crate::mid::MessageId; +use crate::iter::MailIterator; +use crate::iter::IntoMailIterator; provide_kindflag_path!(pub IsMail, "mail.is_mail"); -pub trait Mail : RefFassade { +pub trait Mail : RefFassade + Linkable { fn is_mail(&self) -> Result<bool>; fn get_field(&self, refconfig: &RefConfig, field: &str) -> Result<Option<String>>; fn get_from(&self, refconfig: &RefConfig) -> Result<Option<String>>; @@ -40,6 +47,10 @@ pub trait Mail : RefFassade { fn get_subject(&self, refconfig: &RefConfig) -> Result<Option<String>>; fn get_message_id(&self, refconfig: &RefConfig) -> Result<Option<MessageId>>; fn get_in_reply_to(&self, refconfig: &RefConfig) -> Result<Option<MessageId>>; + + fn neighbors(&self) -> Result<StoreIdIterator>; + fn get_neighbors<'a>(&self, store: &'a Store) -> Result<MailIterator<'a>>; + } impl Mail for Entry { @@ -134,6 +145,45 @@ impl Mail for Entry { .map(|o| o.map(crate::util::strip_message_delimiters).map(MessageId::from)) } + /// Get all direct neighbors for the Mail + /// + /// # Note + /// + /// This fetches only the neighbors which are linked. So it basically only checks the entries + /// which this entry is linked to and filters them for Mail::is_mail() + /// + /// # Warning + /// + /// Might yield store entries which are not a Mail in the Mail::is_mail() sence but are simply + /// stored in /mail in the store. + /// + /// To be sure, you should filter this iterator after getting the FileLockEntries from Store. + /// Or use `Mail::get_neighbors(&store)`. + /// + fn neighbors(&self) -> Result<StoreIdIterator> { + let iter = self + .links()? + .map(|link| link.into()) + .filter(|id: &StoreId| id.is_in_collection(&["mail"])) + .map(Ok); + + Ok(StoreIdIterator::new(Box::new(iter))) + } + + /// Get alldirect neighbors for the Mail (as FileLockEntry) + /// + /// # See also + /// + /// Documentation of `Mail::neighbors()`. + fn get_neighbors<'a>(&self, store: &'a Store) -> Result<MailIterator<'a>> { + self.links() + .map(|iter| { + iter.map(|link| link.into()) + .map(Ok) + .into_get_iter(store) + .into_mail_iterator() + }) + } } #[derive(Debug)] |