summaryrefslogtreecommitdiffstats
path: root/bin/domain/imag-mail/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'bin/domain/imag-mail/src/lib.rs')
-rw-r--r--bin/domain/imag-mail/src/lib.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/bin/domain/imag-mail/src/lib.rs b/bin/domain/imag-mail/src/lib.rs
index 0dd7f2bb..e290d7d8 100644
--- a/bin/domain/imag-mail/src/lib.rs
+++ b/bin/domain/imag-mail/src/lib.rs
@@ -40,6 +40,7 @@ extern crate clap;
extern crate toml_query;
#[macro_use] extern crate indoc;
extern crate resiter;
+extern crate walkdir;
extern crate libimagrt;
extern crate libimagmail;
@@ -58,6 +59,7 @@ use toml_query::read::TomlValueReadTypeExt;
use clap::App;
use resiter::AndThen;
use resiter::IterInnerOkOrElse;
+use resiter::Map;
use libimagmail::mail::Mail;
use libimagmail::store::MailStore;
@@ -81,6 +83,7 @@ pub enum ImagMail {}
impl ImagApplication for ImagMail {
fn run(rt: Runtime) -> Result<()> {
match rt.cli().subcommand_name().ok_or_else(|| err_msg("No subcommand called"))? {
+ "scan" => scan(&rt),
"import-mail" => import_mail(&rt),
"list" => list(&rt),
"mail-store" => mail_store(&rt),
@@ -112,6 +115,35 @@ impl ImagApplication for ImagMail {
}
}
+fn scan(rt: &Runtime) -> Result<()> {
+ let collection_name = get_ref_collection_name(rt)?;
+ let refconfig = get_ref_config(rt, "imag-mail")?;
+ let scmd = rt.cli().subcommand_matches("scan").unwrap();
+ let store = rt.store();
+
+ scmd.values_of("path")
+ .unwrap() // enforced by clap
+ .map(PathBuf::from)
+ .map(|path| {
+ walkdir::WalkDir::new(path)
+ .follow_links(false)
+ .into_iter()
+ .filter_entry(|entry| entry.file_type().is_file())
+ .map_ok(|entry| entry.into_path())
+ .map_err(Error::from)
+ })
+ .flatten()
+ .and_then_ok(|path| {
+ if scmd.is_present("ignore_existing_ids") {
+ store.retrieve_mail_from_path(path, &collection_name, &refconfig)
+ } else {
+ store.create_mail_from_path(path, &collection_name, &refconfig)
+ }
+ })
+ .and_then_ok(|e| rt.report_touched(e.get_location()).map_err(Error::from))
+ .collect::<Result<Vec<()>>>()
+ .map(|_| ())
+}
fn import_mail(rt: &Runtime) -> Result<()> {
let collection_name = get_ref_collection_name(rt)?;