summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-02-17 11:49:37 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-02-20 16:22:52 +0100
commit198c59f717a2c3b2dff8c9d9d5a7a1f45684ceda (patch)
tree7ded93dd7840c786a32cf6ec55afe5f590447ad9
parentf84cc8169fffee3904cd44c14baec0bac7a05478 (diff)
downloadimag-198c59f717a2c3b2dff8c9d9d5a7a1f45684ceda.zip
imag-198c59f717a2c3b2dff8c9d9d5a7a1f45684ceda.tar.gz
Revert "Remove imag-mail"
This reverts commit f9a980c344227898df1fec54a41c84275f7325b2. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--Cargo.toml1
-rw-r--r--bin/core/imag/build.rs2
-rw-r--r--bin/domain/imag-mail/Cargo.toml37
l---------bin/domain/imag-mail/README.md1
-rw-r--r--bin/domain/imag-mail/src/main.rs175
-rw-r--r--bin/domain/imag-mail/src/ui.rs74
6 files changed, 290 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 96a18e2..20f7d34 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,6 +22,7 @@ members = [
"bin/domain/imag-diary",
"bin/domain/imag-habit",
"bin/domain/imag-log",
+ "bin/domain/imag-mail",
"bin/domain/imag-notes",
"bin/domain/imag-timetrack",
"bin/domain/imag-todo",
diff --git a/bin/core/imag/build.rs b/bin/core/imag/build.rs
index 33dfc97..7d91385 100644
--- a/bin/core/imag/build.rs
+++ b/bin/core/imag/build.rs
@@ -99,6 +99,7 @@ gen_mods_buildui!(
("../../../bin/domain/imag-diary/src/ui.rs" , imagdiary) ,
("../../../bin/domain/imag-habit/src/ui.rs" , imaghabit) ,
("../../../bin/domain/imag-log/src/ui.rs" , imaglog) ,
+ ("../../../bin/domain/imag-mail/src/ui.rs" , imagmail) ,
("../../../bin/domain/imag-notes/src/ui.rs" , imagnotes) ,
("../../../bin/domain/imag-timetrack/src/ui.rs" , imagtimetrack) ,
("../../../bin/domain/imag-todo/src/ui.rs" , imagtodo) ,
@@ -128,6 +129,7 @@ fn main() {
.subcommand(build_subcommand!("init" , imaginit , version))
.subcommand(build_subcommand!("link" , imaglink , version))
.subcommand(build_subcommand!("log" , imaglog , version))
+ .subcommand(build_subcommand!("mail" , imagmail , version))
.subcommand(build_subcommand!("mv" , imagmv , version))
.subcommand(build_subcommand!("notes" , imagnotes , version))
.subcommand(build_subcommand!("ref" , imagref , version))
diff --git a/bin/domain/imag-mail/Cargo.toml b/bin/domain/imag-mail/Cargo.toml
new file mode 100644
index 0000000..68836c5
--- /dev/null
+++ b/bin/domain/imag-mail/Cargo.toml
@@ -0,0 +1,37 @@
+[package]
+name = "imag-mail"
+version = "0.10.0"
+authors = ["Matthias Beyer <mail@beyermatthias.de>"]
+
+description = "Part of the imag core distribution: imag-mail command"
+
+keywords = ["imag", "PIM", "personal", "information", "management"]
+readme = "../../../README.md"
+license = "LGPL-2.1"
+
+documentation = "https://imag-pim.org/doc/"
+repository = "https://github.com/matthiasbeyer/imag"
+homepage = "http://imag-pim.org"
+
+build = "../../../build.rs"
+
+[badges]
+travis-ci = { repository = "matthiasbeyer/imag" }
+is-it-maintained-issue-resolution = { repository = "matthiasbeyer/imag" }
+is-it-maintained-open-issues = { repository = "matthiasbeyer/imag" }
+maintenance = { status = "actively-developed" }
+
+[dependencies]
+log = "0.4.0"
+failure = "0.1"
+
+libimagrt = { version = "0.10.0", path = "../../../lib/core/libimagrt" }
+libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
+libimagmail = { version = "0.10.0", path = "../../../lib/domain/libimagmail" }
+libimagutil = { version = "0.10.0", path = "../../../lib/etc/libimagutil" }
+
+[dependencies.clap]
+version = "^2.29"
+default-features = false
+features = ["color", "suggestions", "wrap_help"]
+
diff --git a/bin/domain/imag-mail/README.md b/bin/domain/imag-mail/README.md
new file mode 120000
index 0000000..764e9f3
--- /dev/null
+++ b/bin/domain/imag-mail/README.md
@@ -0,0 +1 @@
+../../../doc/src/04020-module-mails.md \ No newline at end of file
diff --git a/bin/domain/imag-mail/src/main.rs b/bin/domain/imag-mail/src/main.rs
new file mode 100644
index 0000000..d9b9dfb
--- /dev/null
+++ b/bin/domain/imag-mail/src/main.rs
@@ -0,0 +1,175 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 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
+//
+
+#![forbid(unsafe_code)]
+
+#![deny(
+ non_camel_case_types,
+ non_snake_case,
+ path_statements,
+ trivial_numeric_casts,
+ unstable_features,
+ unused_allocation,
+ unused_import_braces,
+ unused_imports,
+ unused_must_use,
+ unused_mut,
+ unused_qualifications,
+ while_true,
+)]
+
+extern crate clap;
+#[macro_use] extern crate log;
+extern crate failure;
+
+#[macro_use] extern crate libimagrt;
+extern crate libimagmail;
+extern crate libimagerror;
+extern crate libimagutil;
+
+use std::io::Write;
+
+use failure::Error;
+use failure::err_msg;
+
+use libimagerror::trace::{MapErrTrace, trace_error};
+use libimagerror::iter::TraceIterator;
+use libimagerror::exit::ExitUnwrap;
+use libimagerror::io::ToExitCode;
+use libimagmail::mail::Mail;
+use libimagrt::runtime::Runtime;
+use libimagrt::setup::generate_runtime_setup;
+use libimagutil::info_result::*;
+
+mod ui;
+
+use ui::build_ui;
+
+fn main() {
+ let version = make_imag_version!();
+ 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),
+ other => {
+ debug!("Unknown command");
+ let _ = rt.handle_unknown_subcommand("imag-mail", other, rt.cli())
+ .map_err_trace_exit_unwrap()
+ .code()
+ .map(::std::process::exit);
+ }
+ }
+ });
+}
+
+fn import_mail(rt: &Runtime) {
+ let scmd = rt.cli().subcommand_matches("import-mail").unwrap();
+ let path = scmd.value_of("path").unwrap(); // enforced by clap
+
+ let mail = Mail::import_from_path(rt.store(), path)
+ .map_info_str("Ok")
+ .map_err_trace_exit_unwrap();
+
+ let _ = rt.report_touched(mail.fle().get_location()).unwrap_or_exit();
+}
+
+fn list(rt: &Runtime) {
+ use failure::ResultExt;
+
+ // TODO: Implement lister type in libimagmail for this
+ fn list_mail(rt: &Runtime, m: Mail) {
+ let id = match m.get_message_id() {
+ Ok(Some(f)) => f,
+ Ok(None) => "<no id>".to_owned(),
+ Err(e) => {
+ trace_error(&e);
+ "<error>".to_owned()
+ },
+ };
+
+ let from = match m.get_from() {
+ Ok(Some(f)) => f,
+ Ok(None) => "<no from>".to_owned(),
+ Err(e) => {
+ trace_error(&e);
+ "<error>".to_owned()
+ },
+ };
+
+ let to = match m.get_to() {
+ Ok(Some(f)) => f,
+ Ok(None) => "<no to>".to_owned(),
+ Err(e) => {
+ trace_error(&e);
+ "<error>".to_owned()
+ },
+ };
+
+ let subject = match m.get_subject() {
+ Ok(Some(f)) => f,
+ Ok(None) => "<no subject>".to_owned(),
+ Err(e) => {
+ trace_error(&e);
+ "<error>".to_owned()
+ },
+ };
+
+ writeln!(rt.stdout(),
+ "Mail: {id}\n\tFrom: {from}\n\tTo: {to}\n\t{subj}\n",
+ from = from,
+ id = id,
+ subj = subject,
+ to = to
+ ).to_exit_code().unwrap_or_exit();
+
+ let _ = rt.report_touched(m.fle().get_location()).unwrap_or_exit();
+ }
+
+ let _ = rt.store()
+ .entries()
+ .map_err_trace_exit_unwrap()
+ .trace_unwrap_exit()
+ .filter(|id| id.is_in_collection(&["mail"]))
+ .filter_map(|id| {
+ rt.store()
+ .get(id)
+ .context(err_msg("Ref handling error"))
+ .map_err(Error::from)
+ .map_err_trace_exit_unwrap()
+ .map(|fle| Mail::from_fle(fle).map_err_trace().ok())
+ })
+ .filter_map(|e| e)
+ .for_each(|m| list_mail(&rt, m));
+}
+
+fn mail_store(rt: &Runtime) {
+ let _ = rt.cli().subcommand_matches("mail-store").unwrap();
+ error!("This feature is currently not implemented.");
+ unimplemented!()
+}
+
diff --git a/bin/domain/imag-mail/src/ui.rs b/bin/domain/imag-mail/src/ui.rs
new file mode 100644
index 0000000..938764e
--- /dev/null
+++ b/bin/domain/imag-mail/src/ui.rs
@@ -0,0 +1,74 @@
+//
+// imag - the personal information management suite for the commandline
+// Copyright (C) 2015-2019 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 clap::{Arg, 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 libimagentryref.
+
+ .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.
+ )
+}
+