summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-05 15:09:46 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-05 16:11:27 +0100
commit56a85113b7bfb89ca22180f0923bf8cd30515daf (patch)
tree9d61651effebd6e9dc44ff1193ffceb7f432959a
parentcdce07e59f211a5cbcc1164080eb5f7036cc6f81 (diff)
Add helper to get the whole thread from a single message
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--lib/domain/libimagmail/src/mail.rs14
-rw-r--r--lib/domain/libimagmail/src/notmuch/mod.rs1
-rw-r--r--lib/domain/libimagmail/src/notmuch/thread.rs44
3 files changed, 59 insertions, 0 deletions
diff --git a/lib/domain/libimagmail/src/mail.rs b/lib/domain/libimagmail/src/mail.rs
index b79c11d0..dc7b3c0d 100644
--- a/lib/domain/libimagmail/src/mail.rs
+++ b/lib/domain/libimagmail/src/mail.rs
@@ -29,6 +29,7 @@ use libimagentryutil::isa::IsKindHeaderPathProvider;
use libimagentryutil::isa::Is;
use crate::notmuch::connection::NotmuchConnection;
+use crate::notmuch::thread::Thread;
provide_kindflag_path!(pub IsMail, "mail.is_mail");
@@ -126,4 +127,17 @@ impl<'a> LoadedMail<'a> {
&self.tags
}
+
+ // More convenience functionality
+
+ pub fn threads(&self, conn: &NotmuchConnection) -> Result<Vec<Thread>> {
+ let id = self.get_id();
+ conn.process(|db| {
+ db.create_query(&format!("thread:{}", id))?
+ .search_threads()
+ .map_err(Error::from)
+ .map(|it| it.map(Thread::from).collect())
+ })
+ }
+
}
diff --git a/lib/domain/libimagmail/src/notmuch/mod.rs b/lib/domain/libimagmail/src/notmuch/mod.rs
index 4ef47243..812a045f 100644
--- a/lib/domain/libimagmail/src/notmuch/mod.rs
+++ b/lib/domain/libimagmail/src/notmuch/mod.rs
@@ -18,3 +18,4 @@
//
pub mod connection;
+pub mod thread;
diff --git a/lib/domain/libimagmail/src/notmuch/thread.rs b/lib/domain/libimagmail/src/notmuch/thread.rs
new file mode 100644
index 00000000..782ad786
--- /dev/null
+++ b/lib/domain/libimagmail/src/notmuch/thread.rs
@@ -0,0 +1,44 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use notmuch_rs::Thread as NotmuchThread;
+
+pub struct Thread {
+ msgs: Vec<String>
+}
+
+impl From<NotmuchThread<'_, '_>> for Thread {
+ fn from(nmt: NotmuchThread) -> Self {
+ let msgs = nmt.messages()
+ .map(|msg| msg.id().into_owned())
+ .collect();
+
+ Thread::new(msgs)
+ }
+}
+
+impl Thread {
+ pub(crate) fn new(msgs: Vec<String>) -> Self {
+ Thread { msgs }
+ }
+
+ pub fn messages(&self) -> &Vec<String> {
+ &self.msgs
+ }
+}