From 392d25a8107ed8a89797703d15e8b2a302d2b557 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 6 Jan 2020 12:51:14 +0100 Subject: Add debug and trace output Signed-off-by: Matthias Beyer --- bin/domain/imag-mail/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index 4d013ba3..fb2aa9fc 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -134,13 +134,23 @@ fn import(rt: &Runtime) -> Result<()> { } fn list(rt: &Runtime) -> Result<()> { + debug!("Listing mail"); let scmd = rt.cli().subcommand_matches("list").unwrap(); let store = rt.store(); let list_format = util::get_mail_print_format("mail.list_format", rt, &scmd)?; + debug!("List-format: {:?}", list_format); + let notmuch_path = crate::util::get_notmuch_database_path(rt)?; + debug!("notmuch path: {:?}", notmuch_path); + let notmuch_connection = NotmuchConnection::open(notmuch_path)?; + let tree = scmd.is_present("tree"); + debug!("tree: {}", tree); + let find_root = scmd.is_present("find-root"); + debug!("find_root: {}", find_root); + let mut out = rt.stdout(); let mut i = 0; @@ -156,13 +166,18 @@ fn list(rt: &Runtime) -> Result<()> { -> Result<()> where I: Iterator>> { + debug!("Processing non-tree"); iter.and_then_ok(|fle| { + trace!("Loading: {}", 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()); let r = crate::util::list_mail(&parsed, *i, 0, list_format, out); // indentation hard coded to zero + trace!("Listed: {}", fle.get_location()); *i += 1; // poor mans enumerate() r.map(|_| fle) }) @@ -185,8 +200,10 @@ fn list(rt: &Runtime) -> Result<()> { -> Result<()> where I: Iterator>> { + debug!("Processing tree"); let iter = if find_root { let iter = iter.and_then_ok(|fle| { + trace!("Loading: {}", fle.get_location()); fle.load(conn)? .ok_or_else(|| format_err!("Cannot load mail: {}", fle.get_location()))? .parsed()? @@ -272,14 +289,20 @@ fn print_traverse<'a>(store: &'a MailStoreWithConnection<'a>, 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() } -- cgit v1.2.3