summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-03 17:54:02 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-03 17:54:02 +0100
commit96992b86b3cb198bb132555e79827d253a45bdbc (patch)
tree439d7acf75cfb05f832d33191b9cc10f75c097cc
parent23499d18eb7b7d5e6565c42270f0123101328434 (diff)
parente5f176c8691e778e5de3973fd10321871ce4fdbb (diff)
downloadimag-96992b86b3cb198bb132555e79827d253a45bdbc.zip
imag-96992b86b3cb198bb132555e79827d253a45bdbc.tar.gz
Merge branch 'imag-mail-unread' into master
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/domain/imag-mail/src/lib.rs37
-rw-r--r--bin/domain/imag-mail/src/ui.rs13
2 files changed, 50 insertions, 0 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index 4bb217f..d069ee0 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."))
diff --git a/bin/domain/imag-mail/src/ui.rs b/bin/domain/imag-mail/src/ui.rs
index 2462e15..324fabb 100644
--- a/bin/domain/imag-mail/src/ui.rs
+++ b/bin/domain/imag-mail/src/ui.rs
@@ -93,6 +93,19 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
.help("The format to list the mails with"))
)
+ .subcommand(SubCommand::with_name("unread")
+ .about("Show unread mail")
+ .version("0.1")
+
+ .arg(Arg::with_name("unread-read")
+ .long("read")
+ .short("r")
+ .takes_value(false)
+ .required(false)
+ .multiple(false)
+ .help("Print the textual content of the mail itself as well"))
+ )
+
.subcommand(SubCommand::with_name("mail-store")
.about("Operations on (subsets of) all mails")
.version("0.1")