diff options
Diffstat (limited to 'bin/domain/imag-mail/src/lib.rs')
-rw-r--r-- | bin/domain/imag-mail/src/lib.rs | 63 |
1 files changed, 15 insertions, 48 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs index eb0f68b6..f428bf3f 100644 --- a/bin/domain/imag-mail/src/lib.rs +++ b/bin/domain/imag-mail/src/lib.rs @@ -38,8 +38,8 @@ extern crate clap; #[macro_use] extern crate log; #[macro_use] extern crate failure; extern crate toml_query; -#[macro_use] extern crate indoc; extern crate resiter; +extern crate handlebars; extern crate libimagrt; extern crate libimagmail; @@ -47,6 +47,7 @@ extern crate libimagerror; extern crate libimagstore; extern crate libimagutil; extern crate libimagentryref; +extern crate libimaginteraction; use std::io::Write; use std::path::PathBuf; @@ -59,19 +60,16 @@ use clap::App; use resiter::AndThen; use resiter::IterInnerOkOrElse; -use libimagmail::mail::Mail; use libimagmail::store::MailStore; -use libimagmail::util; -use libimagentryref::reference::{Ref, RefFassade}; use libimagentryref::util::get_ref_config; use libimagrt::runtime::Runtime; use libimagrt::application::ImagApplication; use libimagutil::info_result::*; -use libimagstore::store::FileLockEntry; use libimagstore::storeid::StoreIdIterator; use libimagstore::iter::get::StoreIdGetIteratorExtension; mod ui; +mod util; /// Marker enum for implementing ImagApplication on /// @@ -141,48 +139,10 @@ fn import_mail(rt: &Runtime) -> Result<()> { } fn list(rt: &Runtime) -> Result<()> { - let refconfig = get_ref_config(rt, "imag-mail")?; - let scmd = rt.cli().subcommand_matches("list").unwrap(); // safe via clap - - // TODO: Implement lister type in libimagmail for this - // - // Optimization: Pass refconfig here instead of call get_ref_config() in lister function. This - // way we do not call get_ref_config() multiple times. - fn list_mail<'a>(rt: &Runtime, - refconfig: &::libimagentryref::reference::Config, - m: &FileLockEntry<'a>) -> Result<()> { - - let id = match m.get_message_id(&refconfig)? { - Some(f) => f.into(), - None => "<no id>".to_owned(), - }; - - let from = match m.get_from(&refconfig)? { - Some(f) => f, - None => "<no from>".to_owned(), - }; - - let to = match m.get_to(&refconfig)? { - Some(f) => f, - None => "<no to>".to_owned(), - }; - - let subject = match m.get_subject(&refconfig)? { - Some(f) => f, - None => "<no subject>".to_owned(), - }; - - writeln!(rt.stdout(), - "Mail: {id}\nFrom: {from}\nTo: {to}\n{subj}\n", - from = from, - id = id, - subj = subject, - to = to - )?; - - rt.report_touched(m.get_location())?; - Ok(()) - } + let refconfig = get_ref_config(rt, "imag-mail")?; + let scmd = rt.cli().subcommand_matches("list").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 @@ -200,7 +160,14 @@ fn list(rt: &Runtime) -> Result<()> { .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| list_mail(&rt, &refconfig, &m)) + .and_then_ok(|m| { + 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(|_| ()) } |