From 56a85113b7bfb89ca22180f0923bf8cd30515daf Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sun, 5 Jan 2020 15:09:46 +0100 Subject: Add helper to get the whole thread from a single message Signed-off-by: Matthias Beyer --- lib/domain/libimagmail/src/mail.rs | 14 +++++++++ lib/domain/libimagmail/src/notmuch/mod.rs | 1 + lib/domain/libimagmail/src/notmuch/thread.rs | 44 ++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 lib/domain/libimagmail/src/notmuch/thread.rs 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> { + 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 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 +} + +impl From> 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) -> Self { + Thread { msgs } + } + + pub fn messages(&self) -> &Vec { + &self.msgs + } +} -- cgit v1.2.3