diff options
Diffstat (limited to 'lib/domain/libimagmail/src/mail.rs')
-rw-r--r-- | lib/domain/libimagmail/src/mail.rs | 52 |
1 files changed, 51 insertions, 1 deletions
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)] |