diff --git a/Cargo.lock b/Cargo.lock index 467759302..08d4ab42b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -834,6 +834,7 @@ dependencies = [ "native-tls", "num-derive", "num-traits", + "open", "percent-encoding", "pgp", "pretty_assertions", @@ -1978,6 +1979,15 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +[[package]] +name = "open" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c283bf0114efea9e42f1a60edea9859e8c47528eae09d01df4b29c1e489cc48" +dependencies = [ + "winapi", +] + [[package]] name = "openssl" version = "0.10.29" diff --git a/Cargo.toml b/Cargo.toml index 1a51cd505..ed8fa1744 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,7 @@ pretty_env_logger = { version = "0.4.0", optional = true } log = {version = "0.4.8", optional = true } rustyline = { version = "4.1.0", optional = true } ansi_term = { version = "0.12.1", optional = true } +open = { version = "1.4.0", optional = true } [dev-dependencies] @@ -93,7 +94,7 @@ required-features = ["repl"] [features] default = [] internals = [] -repl = ["internals", "rustyline", "log", "pretty_env_logger", "ansi_term"] +repl = ["internals", "rustyline", "log", "pretty_env_logger", "ansi_term", "open"] vendored = ["async-native-tls/vendored", "async-smtp/native-tls-vendored"] nightly = ["pgp/nightly"] diff --git a/examples/repl/cmdline.rs b/examples/repl/cmdline.rs index 619988837..d1dde5fc9 100644 --- a/examples/repl/cmdline.rs +++ b/examples/repl/cmdline.rs @@ -370,6 +370,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu ===========================Message commands==\n\ listmsgs \n\ msginfo \n\ + openfile \n\ listfresh\n\ forward \n\ markseen \n\ @@ -890,6 +891,15 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu let res = message::get_msg_info(&context, id).await; println!("{}", res); } + "openfile" => { + ensure!(!arg1.is_empty(), "Argument missing."); + let id = MsgId::new(arg1.parse()?); + let msg = Message::load_from_db(&context, id).await?; + let filepath = msg.get_file(&context); + ensure!(filepath.is_some(), "Message has no file."); + let filepath = filepath.unwrap(); + open::that(filepath)?; + } "listfresh" => { let msglist = context.get_fresh_msgs().await; diff --git a/examples/repl/main.rs b/examples/repl/main.rs index e53bed1c2..a14157286 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -186,9 +186,10 @@ const CHAT_COMMANDS: [&str; 26] = [ "unpin", "delchat", ]; -const MESSAGE_COMMANDS: [&str; 8] = [ +const MESSAGE_COMMANDS: [&str; 9] = [ "listmsgs", "msginfo", + "openfile", "listfresh", "forward", "markseen",