summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-mail/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-mail/src/config.rs')
-rw-r--r--bin/domain/imag-mail/src/config.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/bin/domain/imag-mail/src/config.rs b/bin/domain/imag-mail/src/config.rs
new file mode 100644
index 00000000..39cee237
--- /dev/null
+++ b/bin/domain/imag-mail/src/config.rs
@@ -0,0 +1,66 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2020 Matthias Beyer <mail@beyermatthias.de> and contributors
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; version
+// 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+//
+
+use std::path::PathBuf;
+
+use handlebars::Handlebars;
+use failure::Fallible as Result;
+use clap::ArgMatches;
+
+use libimagrt::runtime::Runtime;
+
+#[derive(Debug, Serialize, Deserialize, Partial)]
+#[location = "mail"]
+pub struct MailConfig {
+ #[serde(rename = "list_format")]
+ list_format: String,
+
+ #[serde(rename = "notmuch_database")]
+ notmuch_database_path: PathBuf,
+}
+
+impl MailConfig {
+
+ pub fn get_list_format(&self, scmd: &ArgMatches) -> Result<Handlebars> {
+ let fmt = scmd
+ .value_of("format")
+ .map(String::from)
+ .unwrap_or_else(|| self.list_format.clone());
+
+ let mut hb = Handlebars::new();
+ hb.register_template_string("format", fmt)?;
+
+ hb.register_escape_fn(::handlebars::no_escape);
+ ::libimaginteraction::format::register_all_color_helpers(&mut hb);
+ ::libimaginteraction::format::register_all_format_helpers(&mut hb);
+ Ok(hb)
+ }
+
+ pub fn get_notmuch_database_path(&self, rt: &Runtime) -> PathBuf {
+ if let Some(pb) = rt.cli()
+ .value_of("database_path")
+ .map(String::from)
+ .map(PathBuf::from)
+ {
+ pb
+ } else {
+ self.notmuch_database_path.clone()
+ }
+ }
+}