summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-mail/src/util.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-mail/src/util.rs')
-rw-r--r--bin/domain/imag-mail/src/util.rs37
1 files changed, 26 insertions, 11 deletions
diff --git a/bin/domain/imag-mail/src/util.rs b/bin/domain/imag-mail/src/util.rs
index 7f116649..c17e8f4c 100644
--- a/bin/domain/imag-mail/src/util.rs
+++ b/bin/domain/imag-mail/src/util.rs
@@ -19,6 +19,7 @@
use std::collections::BTreeMap;
use std::io::Write;
+use std::path::PathBuf;
use clap::ArgMatches;
use failure::Error;
@@ -27,10 +28,8 @@ use failure::err_msg;
use handlebars::Handlebars;
use toml_query::read::TomlValueReadTypeExt;
-use libimagmail::mail::Mail;
+use libimagmail::mail::ParsedMail;
use libimagrt::runtime::Runtime;
-use libimagstore::store::FileLockEntry;
-use libimagentryref::reference::Config as RefConfig;
pub fn get_mail_print_format(config_value_path: &'static str, rt: &Runtime, scmd: &ArgMatches) -> Result<Handlebars> {
let fmt = match scmd.value_of("format").map(String::from) {
@@ -53,27 +52,27 @@ pub fn get_mail_print_format(config_value_path: &'static str, rt: &Runtime, scmd
Ok(hb)
}
-pub fn build_data_object_for_handlebars(i: usize, m: &FileLockEntry, refconfig: &RefConfig) -> Result<BTreeMap<&'static str, String>> {
+pub fn build_data_object_for_handlebars<'a>(i: usize, m: &'a ParsedMail<'a>) -> Result<BTreeMap<&'static str, String>> {
let mut data = BTreeMap::new();
data.insert("i", format!("{}", i));
- let id = match m.get_message_id(refconfig)? {
- Some(f) => f.into(),
+ let id = match m.message_id()? {
+ Some(f) => f,
None => "<no id>".to_owned(),
};
- let from = match m.get_from(refconfig)? {
+ let from = match m.from()? {
Some(f) => f,
None => "<no from>".to_owned(),
};
- let to = match m.get_to(refconfig)? {
+ let to = match m.to()? {
Some(f) => f,
None => "<no to>".to_owned(),
};
- let subject = match m.get_subject(refconfig)? {
+ let subject = match m.subject()? {
Some(f) => f,
None => "<no subject>".to_owned(),
};
@@ -86,10 +85,26 @@ 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)?;
+pub fn list_mail<'a>(m: &'a ParsedMail<'a>, i: usize, list_format: &Handlebars, out: &mut dyn Write) -> Result<()> {
+ let data = build_data_object_for_handlebars(i, m)?;
let s = list_format.render("format", &data)?;
writeln!(out, "{}", s)?;
Ok(())
}
+pub fn get_notmuch_database_path(rt: &Runtime) -> Result<PathBuf> {
+ if let Some(pb) = rt.cli()
+ .value_of("database_path")
+ .map(String::from)
+ .map(PathBuf::from)
+ {
+ return Ok(pb)
+ } else {
+ rt.config()
+ .ok_or_else(|| err_msg("No configuration file"))?
+ .read_string("mail.notmuch_database")
+ .map_err(Error::from)?
+ .map(PathBuf::from)
+ .ok_or_else(|| format_err!("Configuration 'mail.notmuch_database' does not exist"))
+ }
+}