From 0d113cf40e13fd1036829e51ece6ff66bf530624 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 23 Sep 2016 18:22:03 +0200 Subject: [PATCH 1/8] Initial import --- imag-mail/Cargo.toml | 6 ++++++ imag-mail/src/main.rs | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 imag-mail/Cargo.toml create mode 100644 imag-mail/src/main.rs diff --git a/imag-mail/Cargo.toml b/imag-mail/Cargo.toml new file mode 100644 index 00000000..6c35a231 --- /dev/null +++ b/imag-mail/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "imag-mail" +version = "0.2.0" +authors = ["Matthias Beyer "] + +[dependencies] diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs new file mode 100644 index 00000000..c836cd6e --- /dev/null +++ b/imag-mail/src/main.rs @@ -0,0 +1,22 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer 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 +// + +fn main() { + println!("Hello, world!"); +} From 64956443d90eeb57862c5dfcf3cd2939d4ba6445 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 23 Sep 2016 18:23:05 +0200 Subject: [PATCH 2/8] Link README from documentation --- imag-mail/README.md | 1 + 1 file changed, 1 insertion(+) create mode 120000 imag-mail/README.md diff --git a/imag-mail/README.md b/imag-mail/README.md new file mode 120000 index 00000000..d5d8fb01 --- /dev/null +++ b/imag-mail/README.md @@ -0,0 +1 @@ +../doc/src/04020-module-mails.md \ No newline at end of file From 29e0e72471021d8ff148b73149a33d366c815d01 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 23 Sep 2016 18:25:05 +0200 Subject: [PATCH 3/8] Add dependencies --- imag-mail/Cargo.toml | 19 +++++++++++++++++++ imag-mail/src/main.rs | 12 ++++++++++++ 2 files changed, 31 insertions(+) diff --git a/imag-mail/Cargo.toml b/imag-mail/Cargo.toml index 6c35a231..e1e40606 100644 --- a/imag-mail/Cargo.toml +++ b/imag-mail/Cargo.toml @@ -4,3 +4,22 @@ version = "0.2.0" authors = ["Matthias Beyer "] [dependencies] +semver = "0.2.1" +clap = "2.*" +log = "0.3" +version = "2.0.1" +toml = "0.2.*" +url = "1.1" + +[dependencies.libimagrt] +path = "../libimagrt" + +[dependencies.libimagmail] +path = "../libimagmail" + +[dependencies.libimagerror] +path = "../libimagerror" + +[dependencies.libimagutil] +path = "../libimagutil" + diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs index c836cd6e..d906e12f 100644 --- a/imag-mail/src/main.rs +++ b/imag-mail/src/main.rs @@ -17,6 +17,18 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA // +extern crate semver; +extern crate clap; +extern crate log; +extern crate version; +extern crate toml; +extern crate url; + +extern crate libimagrt; +extern crate libimagmail; +extern crate libimagerror; +extern crate libimagutil; + fn main() { println!("Hello, world!"); } From cea84cb7fd6581010ab048f96634d716f7ac6f89 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 23 Sep 2016 18:25:16 +0200 Subject: [PATCH 4/8] Add UI module --- imag-mail/src/main.rs | 2 ++ imag-mail/src/ui.rs | 74 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 imag-mail/src/ui.rs diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs index d906e12f..ed0c4beb 100644 --- a/imag-mail/src/main.rs +++ b/imag-mail/src/main.rs @@ -29,6 +29,8 @@ extern crate libimagmail; extern crate libimagerror; extern crate libimagutil; +mod ui; + fn main() { println!("Hello, world!"); } diff --git a/imag-mail/src/ui.rs b/imag-mail/src/ui.rs new file mode 100644 index 00000000..3e999949 --- /dev/null +++ b/imag-mail/src/ui.rs @@ -0,0 +1,74 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer 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 clap::{Arg, ArgGroup, App, SubCommand}; + +pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> { + app + .subcommand(SubCommand::with_name("import-mail") + .about("Import a mail (create a reference to it) (Maildir)") + .version("0.1") + .arg(Arg::with_name("path") + .long("path") + .short("p") + .takes_value(true) + .required(true) + .help("Path to the mail file or a directory which is then searched recursively") + .value_name("PATH")) + ) + + .subcommand(SubCommand::with_name("list") + .about("List all stored references to mails") + .version("0.1") + + // TODO: Thee following four arguments are the same as in imag-ref. + // We should make these importable from libimagref. + + .arg(Arg::with_name("check-dead") + .long("check-dead") + .short("d") + .help("Check each reference whether it is dead")) + + .arg(Arg::with_name("check-changed") + .long("check-changed") + .short("c") + .help("Check whether a reference had changed (content or permissions)")) + + .arg(Arg::with_name("check-changed-content") + .long("check-changed-content") + .short("C") + .help("Check whether the content of the referenced file changed")) + + .arg(Arg::with_name("check-changed-permissions") + .long("check-changed-perms") + .short("P") + .help("Check whether the permissions of the referenced file changed")) + + ) + + .subcommand(SubCommand::with_name("mail-store") + .about("Operations on (subsets of) all mails") + .version("0.1") + .subcommand(SubCommand::with_name("update-refs") + .about("Create references based on Message-IDs for all loaded mails") + .version("0.1")) + // TODO: We really should be able to filter here. + ) +} + From c8efc1aa34e6defc0e1915f2c04ead7619a95fef Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 20 Oct 2016 17:26:17 +0200 Subject: [PATCH 5/8] Dump in first source code pieces --- imag-mail/Cargo.toml | 3 ++ imag-mail/src/main.rs | 76 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 3 deletions(-) diff --git a/imag-mail/Cargo.toml b/imag-mail/Cargo.toml index e1e40606..e5ffada0 100644 --- a/imag-mail/Cargo.toml +++ b/imag-mail/Cargo.toml @@ -23,3 +23,6 @@ path = "../libimagerror" [dependencies.libimagutil] path = "../libimagutil" +[dependencies.libimagref] +path = "../libimagref" + diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs index ed0c4beb..117414ba 100644 --- a/imag-mail/src/main.rs +++ b/imag-mail/src/main.rs @@ -19,18 +19,88 @@ extern crate semver; extern crate clap; -extern crate log; -extern crate version; extern crate toml; extern crate url; +#[macro_use] extern crate log; +#[macro_use] extern crate version; extern crate libimagrt; extern crate libimagmail; extern crate libimagerror; extern crate libimagutil; +extern crate libimagref; + +use libimagutil::debug_result::*; +use libimagutil::info_result::*; +use libimagref::reference::Ref; mod ui; +use ui::build_ui; + fn main() { - println!("Hello, world!"); + let rt = generate_runtime_setup("imag-mail", + &version!()[..], + "Mail collection tool", + build_ui); + + rt.cli() + .subcommand_name() + .map(|name| { + debug!("Call {}", name); + match name { + "import-mail" => import_mail(&rt), + "list" => list(&rt), + "mail-store" => mail_store(&rt), + _ => debug!("Unknown command") // More error handling + } + }); } + +fn import_mail(rt: &Runtime) { + let scmd = rt.cli().subcommand_matches("import-mail").unwrap(); + let path = scmd.value_of("path").unwrap(); // enforced by clap + + Mail::import_from_path(rt.store(), path) + .map_err_trace() + .map_info_str("Ok"); +} + +fn list(rt: &Runtime) { + use libimagmail::error::MailErrorKind as MEK; + use libimagmail::error::MapErrInto; + + let scmd = rt.cli().subcommand_matches("list").unwrap(); + let do_check_dead = scmd.is_present("check-dead"); + let do_check_changed = scmd.is_present("check-changed"); + let do_check_changed_content = scmd.is_present("check-changed-content"); + let do_check_changed_permiss = scmd.is_present("check-changed-permissions"); + let store = rt.store(); + + let iter = match store.retrieve_for_module("ref") { + Ok(iter) => iter.filter_map(|id| { + Ref::get(store, id) + .map_err_into(MEK::RefHandlingError) + .and_then(|rf| Mail::from_ref(rf)) + .map_err_trace() + .ok() + }), + Err(e) => trace_error_exit(&e, 1), + }; + + fn list_mail(m: Mail) { + unimplemented!() + } + + // TODO: Implement lister type in libimagmail for this + for mail in iter { + list_mail(mail) + } +} + +fn mail_store(rt: &Runtime) { + let scmd = rt.cli().subcommand_matches("mail-store").unwrap(); + error!("This feature is currently not implemented."); + unimplemented!() +} + From d62a54ee743a7da347b824c31919d395a8545668 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 22 Oct 2016 12:59:01 +0200 Subject: [PATCH 6/8] Add imports --- imag-mail/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs index 117414ba..ab324c94 100644 --- a/imag-mail/src/main.rs +++ b/imag-mail/src/main.rs @@ -30,9 +30,13 @@ extern crate libimagerror; extern crate libimagutil; extern crate libimagref; +use libimagerror::trace::{MapErrTrace, trace_error, trace_error_exit}; +use libimagmail::mail::Mail; +use libimagref::reference::Ref; +use libimagrt::runtime::Runtime; +use libimagrt::setup::generate_runtime_setup; use libimagutil::debug_result::*; use libimagutil::info_result::*; -use libimagref::reference::Ref; mod ui; From e74c7392d9058b895bb6ffff9b85b5952ef28a18 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Sat, 22 Oct 2016 13:13:58 +0200 Subject: [PATCH 7/8] Implement list_mail() helper fn --- imag-mail/src/main.rs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/imag-mail/src/main.rs b/imag-mail/src/main.rs index ab324c94..bdd51bdb 100644 --- a/imag-mail/src/main.rs +++ b/imag-mail/src/main.rs @@ -93,7 +93,48 @@ fn list(rt: &Runtime) { }; fn list_mail(m: Mail) { - unimplemented!() + let id = match m.get_message_id() { + Ok(Some(f)) => f, + Ok(None) => "".to_owned(), + Err(e) => { + trace_error(&e); + "".to_owned() + }, + }; + + let from = match m.get_from() { + Ok(Some(f)) => f, + Ok(None) => "".to_owned(), + Err(e) => { + trace_error(&e); + "".to_owned() + }, + }; + + let to = match m.get_to() { + Ok(Some(f)) => f, + Ok(None) => "".to_owned(), + Err(e) => { + trace_error(&e); + "".to_owned() + }, + }; + + let subject = match m.get_subject() { + Ok(Some(f)) => f, + Ok(None) => "".to_owned(), + Err(e) => { + trace_error(&e); + "".to_owned() + }, + }; + + println!("Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n", + from = from, + id = id, + subj = subject, + to = to + ); } // TODO: Implement lister type in libimagmail for this From ccc6d2e3858200ead4e7654454a56cd4b5930f03 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 25 Oct 2016 09:47:02 +0200 Subject: [PATCH 8/8] Update deps --- imag-mail/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/imag-mail/Cargo.toml b/imag-mail/Cargo.toml index e5ffada0..86f2a1be 100644 --- a/imag-mail/Cargo.toml +++ b/imag-mail/Cargo.toml @@ -4,12 +4,12 @@ version = "0.2.0" authors = ["Matthias Beyer "] [dependencies] -semver = "0.2.1" +semver = "0.5" clap = "2.*" log = "0.3" version = "2.0.1" toml = "0.2.*" -url = "1.1" +url = "1.2" [dependencies.libimagrt] path = "../libimagrt"