diff options
Diffstat (limited to 'bin/domain/imag-mail/src/lib.rs')
-rw-r--r-- | bin/domain/imag-mail/src/lib.rs | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index 4bb217ff..d069ee0e 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -66,6 +66,7 @@ use resiter::Map; use rayon::prelude::*; use libimagmail::store::MailStore; +use libimagmail::mail::Mail; use libimagentryref::util::get_ref_config; use libimagentryref::reference::Config as RefConfig; use libimagrt::runtime::Runtime; @@ -88,6 +89,7 @@ impl ImagApplication for ImagMail { "scan" => scan(&rt), "import-mail" => import_mail(&rt), "list" => list(&rt), + "unread" => unread(&rt), "mail-store" => mail_store(&rt), other => { debug!("Unknown command"); @@ -237,6 +239,41 @@ fn list(rt: &Runtime) -> Result<()> { .map(|_| ()) } +fn unread(rt: &Runtime) -> Result<()> { + let refconfig = get_ref_config(rt, "imag-mail")?; + let scmd = rt.cli().subcommand_matches("unread").unwrap(); // safe via clap + let list_format = util::get_mail_print_format("mail.list_format", rt, &scmd)?; + let mut i = 0; + + if rt.ids_from_stdin() { + let iter = rt + .ids::<crate::ui::PathProvider>()? + .ok_or_else(|| err_msg("No ids supplied"))? + .into_iter() + .map(Ok); + + StoreIdIterator::new(Box::new(iter)) + } else { + rt.store().all_mails()?.into_storeid_iter() + } + .inspect(|id| debug!("Found: {:?}", id)) + .into_get_iter(rt.store()) + .map_inner_ok_or_else(|| err_msg("Did not find one entry")) + .and_then_ok(|m| { + if !m.is_seen(&refconfig)? { + let data = util::build_data_object_for_handlebars(i, &m, &refconfig)?; + let s = list_format.render("format", &data)?; + writeln!(rt.stdout(), "{}", s)?; + rt.report_touched(m.get_location())?; + i += 1; + } + + Ok(()) + }) + .collect::<Result<Vec<_>>>() + .map(|_| ()) +} + fn mail_store(rt: &Runtime) -> Result<()> { let _ = rt.cli().subcommand_matches("mail-store").unwrap(); Err(format_err!("This feature is currently not implemented.")) |