Skip to content

Commit

Permalink
fix editor command hanging, add --preview flag for msg read cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
soywod committed Dec 9, 2023
1 parent 04e721d commit 203ed2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
9 changes: 3 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down
15 changes: 13 additions & 2 deletions src/email/message/command/read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/ui/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use email::{
};
use log::debug;
use mml::MmlCompilerBuilder;
use process::Cmd;
use process::SingleCmd;
use std::{env, fs};

use crate::{
Expand All @@ -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")?;
Expand Down

0 comments on commit 203ed2f

Please sign in to comment.