summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/domain/libimagmail/src/mail.rs1
-rw-r--r--lib/domain/libimagmail/src/store.rs20
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs
index bdcee6a2..d8e009f0 100644
--- a/lib/domain/libimagmail/src/mail.rs
+++ b/lib/domain/libimagmail/src/mail.rs
@@ -249,6 +249,7 @@ impl Mail for Entry {
Ok(iter)
}
+
}
#[derive(Debug)]
diff --git a/lib/domain/libimagmail/src/store.rs b/lib/domain/libimagmail/src/store.rs
index 637dac54..88f49df1 100644
--- a/lib/domain/libimagmail/src/store.rs
+++ b/lib/domain/libimagmail/src/store.rs
@@ -59,6 +59,8 @@ pub trait MailStore<'a> {
fn get_mail(&'a self, mid: MessageId) -> Result<Option<FileLockEntry<'a>>>;
fn all_mails(&'a self) -> Result<Entries<'a>>;
+
+ fn thread_root_of(&'a self, mid: MessageId, refconfig: &Config) -> Result<Option<FileLockEntry<'a>>>;
}
impl<'a> MailStore<'a> for Store {
@@ -149,5 +151,23 @@ impl<'a> MailStore<'a> for Store {
fn all_mails(&'a self) -> Result<Entries<'a>> {
self.entries()?.in_collection("mail")
}
+
+ /// Compute the thread root of the thread the Mail belongs to
+ ///
+ /// This function recursively traverses the thread using `Store::get_mail()` and
+ /// `Mail::get_in_reply_to()` to find the root of the thread (The mail that is not a reply to
+ /// any other mail).
+ ///
+ fn thread_root_of(&'a self, mid: MessageId, refconfig: &Config) -> Result<Option<FileLockEntry<'a>>> {
+ if let Some(entry) = self.get_mail(mid)? {
+ if let Some(parent_mid) = entry.get_in_reply_to(refconfig)? {
+ self.thread_root_of(parent_mid, refconfig)
+ } else {
+ Ok(Some(entry))
+ }
+ } else {
+ Ok(None)
+ }
+ }
}