summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2020-01-03 18:27:59 +0100
committerMatthias Beyer <mail@beyermatthias.de>2020-01-03 18:48:21 +0100
commit74d19e1a4bd066d124f0e5c8649c0d699c6bb76a (patch)
tree02a48902d6440bc5104cf9e3536ad5062014cfe8
parent18ca974e29fa475b87d3de0359ab821bafe1998d (diff)
downloadimag-74d19e1a4bd066d124f0e5c8649c0d699c6bb76a.zip
imag-74d19e1a4bd066d124f0e5c8649c0d699c6bb76a.tar.gz
Outsource listing of a single mail to helper function
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--bin/domain/imag-mail/src/lib.rs11
-rw-r--r--bin/domain/imag-mail/src/util.rs8
2 files changed, 12 insertions, 7 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index d069ee0..10d6b85 100644
--- a/bin/domain/imag-mail/src/lib.rs
+++ b/bin/domain/imag-mail/src/lib.rs
@@ -51,7 +51,6 @@ extern crate libimagutil;
extern crate libimagentryref;
extern crate libimaginteraction;
-use std::io::Write;
use std::path::PathBuf;
use failure::Fallible as Result;
@@ -209,6 +208,7 @@ fn list(rt: &Runtime) -> Result<()> {
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 out = rt.stdout();
let mut i = 0;
if rt.ids_from_stdin() {
@@ -228,9 +228,7 @@ fn list(rt: &Runtime) -> Result<()> {
.into_get_iter(rt.store())
.map_inner_ok_or_else(|| err_msg("Did not find one entry"))
.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)?;
+ crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?;
rt.report_touched(m.get_location())?;
i += 1;
Ok(())
@@ -243,6 +241,7 @@ 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 out = rt.stdout();
let mut i = 0;
if rt.ids_from_stdin() {
@@ -261,9 +260,7 @@ fn unread(rt: &Runtime) -> Result<()> {
.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)?;
+ crate::util::list_mail(&m, i, &refconfig, &list_format, &mut out)?;
rt.report_touched(m.get_location())?;
i += 1;
}
diff --git a/bin/domain/imag-mail/src/util.rs b/bin/domain/imag-mail/src/util.rs
index 77d6b5a..7f11664 100644
--- a/bin/domain/imag-mail/src/util.rs
+++ b/bin/domain/imag-mail/src/util.rs
@@ -18,6 +18,7 @@
//
use std::collections::BTreeMap;
+use std::io::Write;
use clap::ArgMatches;
use failure::Error;
@@ -85,3 +86,10 @@ pub fn build_data_object_for_handlebars(i: usize, m: &FileLockEntry, refconfig:
Ok(data)
}
+pub fn list_mail(m: &FileLockEntry, i: usize, refconfig: &RefConfig, list_format: &Handlebars, out: &mut dyn Write) -> Result<()> {
+ let data = build_data_object_for_handlebars(i, m, refconfig)?;
+ let s = list_format.render("format", &data)?;
+ writeln!(out, "{}", s)?;
+ Ok(())
+}
+