fix editor command hanging, add --preview flag for msg read cmd

This commit is contained in:
Clément DOUIN 2023-12-09 22:06:08 +01:00
parent 04e721d591
commit 203ed2f917
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
4 changed files with 25 additions and 13 deletions

9
Cargo.lock generated
View file

@ -2445,8 +2445,6 @@ dependencies = [
[[package]]
name = "keyring-lib"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8dcc9433b6eaf33f2f6a8d3a53b598a5d0b8be224c41bd98d1ec936ef4d02d69"
dependencies = [
"keyring",
"log",
@ -3233,10 +3231,10 @@ dependencies = [
[[package]]
name = "process-lib"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe824234b824573ff3a80ddf3a6b19e6ffba966798d071f280723ee02a7273ce"
dependencies = [
"anyhow",
"log",
"once_cell",
"thiserror",
"tokio",
]
@ -3707,9 +3705,8 @@ dependencies = [
[[package]]
name = "secret-lib"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d46e99ae858a1978ec3e6e887966514900229fc0df99935a2c61102854f9195e"
dependencies = [
"anyhow",
"keyring-lib",
"log",
"process-lib",

View file

@ -104,7 +104,8 @@ default-features = false
path = "/home/soywod/sourcehut/pimalaya/email"
[dependencies.keyring-lib]
version = "=0.1.0"
# version = "=0.1.0"
path = "/home/soywod/sourcehut/pimalaya/keyring"
[dependencies.mail-builder]
version = "0.3"
@ -114,7 +115,8 @@ version = "0.3"
path = "/home/soywod/sourcehut/pimalaya/oauth"
[dependencies.process-lib]
version = "=0.1.0"
# version = "=0.1.0"
path = "/home/soywod/sourcehut/pimalaya/process"
[dependencies.mml-lib]
# version = "=1.0.1"
@ -123,7 +125,8 @@ features = ["compiler", "interpreter"]
path = "/home/soywod/sourcehut/pimalaya/mml"
[dependencies.secret-lib]
version = "=0.1.0"
# version = "=0.1.0"
path = "/home/soywod/sourcehut/pimalaya/secret"
[dependencies.serde]
version = "1.0"

View file

@ -11,7 +11,9 @@ use crate::{
/// Read a message.
///
/// This command allows you to read a message.
/// This command allows you to read a message. When reading a message,
/// the "seen" flag is automatically applied to the corresponding
/// envelope. To prevent this behaviour, use the --preview flag.
#[derive(Debug, Parser)]
pub struct MessageReadCommand {
#[command(flatten)]
@ -20,6 +22,11 @@ pub struct MessageReadCommand {
#[command(flatten)]
pub envelopes: EnvelopeIdsArgs,
/// Read the message without applying the "seen" flag to its
/// corresponding envelope.
#[arg(long, short)]
pub preview: bool,
/// Read the raw version of the given message.
///
/// The raw message represents the headers and the body as it is
@ -79,7 +86,11 @@ impl MessageReadCommand {
let backend = Backend::new(toml_account_config, account_config.clone(), false).await?;
let ids = &self.envelopes.ids;
let emails = backend.get_messages(&folder, &ids).await?;
let emails = if self.preview {
backend.peek_messages(&folder, &ids).await
} else {
backend.get_messages(&folder, &ids).await
}?;
let mut glue = "";
let mut bodies = String::default();

View file

@ -6,7 +6,7 @@ use email::{
};
use log::debug;
use mml::MmlCompilerBuilder;
use process::Cmd;
use process::SingleCmd;
use std::{env, fs};
use crate::{
@ -23,7 +23,8 @@ pub async fn open_with_tpl(tpl: String) -> Result<String> {
debug!("open editor");
let editor = env::var("EDITOR").context("cannot get editor from env var")?;
Cmd::from(format!("{editor} {}", &path.to_string_lossy()))
SingleCmd::from(format!("{editor} {}", &path.to_string_lossy()))
.with_output_piped(false)
.run()
.await
.context("cannot launch editor")?;