summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-mail/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-mail/src/lib.rs')
-rw-r--r--bin/domain/imag-mail/src/lib.rs60
1 files changed, 26 insertions, 34 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index 30df9d0c..720f7a93 100644
--- a/bin/domain/imag-mail/src/lib.rs
+++ b/bin/domain/imag-mail/src/lib.rs
@@ -40,6 +40,7 @@ extern crate clap;
extern crate toml_query;
extern crate resiter;
extern crate handlebars;
+extern crate itertools;
extern crate libimagrt;
extern crate libimagmail;
@@ -59,12 +60,12 @@ use resiter::IterInnerOkOrElse;
use resiter::Filter;
use resiter::Map;
use handlebars::Handlebars;
+use itertools::Itertools;
use libimagmail::store::MailStore;
use libimagmail::store::Sorting;
use libimagmail::mail::Mail;
use libimagmail::store::MailStoreWithConnection;
-use libimagmail::mailtree::Mailtree;
use libimagmail::notmuch::connection::NotmuchConnection;
use libimagrt::runtime::Runtime;
use libimagrt::application::ImagApplication;
@@ -195,7 +196,6 @@ fn list(rt: &Runtime) -> Result<()> {
/// This function implements the tree-style printing functionality ("--tree").
fn process_tree<'a, I>(iter: I,
mailstore: &'a MailStoreWithConnection<'a>,
- i: &mut usize,
conn: &NotmuchConnection,
list_format: &Handlebars,
rt: &Runtime,
@@ -238,9 +238,28 @@ fn list(rt: &Runtime) -> Result<()> {
.collect::<Result<Vec<_>>>()?;
trace!("mss = {:?}", mss);
- mss.into_iter()
- .map(|mt| print_traverse(&mailstore, mt, i, conn, list_format, rt, out))
- .collect::<Result<Vec<_>>>()
+ mss.iter()
+ .map(|mailtree| mailtree.traverse())
+ .flatten()
+ .unique_by(|tpl| tpl.1.clone())
+ .sorted_by(|a, b| a.0.cmp(&b.0))
+ .enumerate()
+ .map(|(i, (indent, mid))| {
+ let fle = mailstore.get_mail_by_id(&mid)?.ok_or_else(|| format_err!("Cannot find mail with id = {}", mid))?;
+ trace!("Printing: {}", fle.get_location());
+
+ let loaded = fle.load(&conn)?
+ .ok_or_else(|| format_err!("Mail not found: {}", fle.get_location()))?;
+ trace!("Loaded: {}", fle.get_location());
+
+ let parsed = loaded.parsed()?;
+ trace!("Parsed: {}", fle.get_location());
+
+ crate::util::list_mail(&parsed, i, indent, list_format, out)?;
+ trace!("Listed: {}", fle.get_location());
+ rt.report_touched(fle.get_location())
+ })
+ .collect::<Result<Vec<()>>>()
.map(|_| ())
}
@@ -258,7 +277,7 @@ fn list(rt: &Runtime) -> Result<()> {
.map(Ok);
if tree {
- process_tree(iter, &mailstore, &mut i, &notmuch_connection, &list_format, rt, &mut out, find_root)
+ process_tree(iter, &mailstore, &notmuch_connection, &list_format, rt, &mut out, find_root)
} else {
process_nontree(iter, &mut i, &notmuch_connection, &list_format, rt, &mut out)
}
@@ -276,7 +295,7 @@ fn list(rt: &Runtime) -> Result<()> {
if tree {
let mailstore = store.with_connection(&notmuch_connection);
- process_tree(iter, &mailstore, &mut i, &notmuch_connection, &list_format, rt, &mut out, find_root)
+ process_tree(iter, &mailstore, &notmuch_connection, &list_format, rt, &mut out, find_root)
} else {
process_nontree(iter, &mut i, &notmuch_connection, &list_format, rt, &mut out)
}
@@ -300,30 +319,3 @@ fn print_id(rt: &Runtime) -> Result<()> {
.map(|_| ())
}
-fn print_traverse<'a>(store: &'a MailStoreWithConnection<'a>,
- tree: Mailtree,
- i: &mut usize,
- conn: &NotmuchConnection,
- list_format: &Handlebars,
- rt: &Runtime,
- out: &mut dyn Write) -> Result<()> {
- trace!("Print-Traversing starting with: {:?}", tree.root());
- for (indent, mid) in tree.traverse() {
- let fle = store.get_mail_by_id(&mid)?.ok_or_else(|| format_err!("Cannot find mail with id = {}", mid))?;
- trace!("Printing: {}", fle.get_location());
-
- let loaded = fle.load(&conn)?
- .ok_or_else(|| format_err!("Mail not found: {}", fle.get_location()))?;
- trace!("Loaded: {}", fle.get_location());
-
- let parsed = loaded.parsed()?;
- trace!("Parsed: {}", fle.get_location());
-
- crate::util::list_mail(&parsed, *i, indent, list_format, out)?;
- trace!("Listed: {}", fle.get_location());
- rt.report_touched(fle.get_location())?;
- *i += 1; // poor mans enumerate()
- }
-
- Ok(())
-}