diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2020-01-03 12:48:30 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2020-01-03 16:55:32 +0100 |
commit | 61d3d2b769a1ec20d9eb6141c70ca40de028fe4b (patch) | |
tree | a57944861dfc12fc39a8e4a639946abc6e98ad99 | |
parent | 4548ac8f6365e327892e3517ac26ec79aeaa5f68 (diff) |
Add MailStore::thread_root_of()
This patch adds a function to find the root node of a mailthread (as in
In-Reply-To header).
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/domain/libimagmail/src/mail.rs | 1 | ||||
-rw-r--r-- | lib/domain/libimagmail/src/store.rs | 20 |
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) + } + } } |