diff --git a/Cargo.lock b/Cargo.lock index 16099b5f..96f9edcf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1216,7 +1216,7 @@ dependencies = [ [[package]] name = "email-lib" version = "0.26.4" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "async-trait", "chrono", @@ -1862,7 +1862,7 @@ dependencies = [ [[package]] name = "http-lib" version = "0.1.0" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "thiserror 2.0.18", "tokio", @@ -2265,7 +2265,7 @@ dependencies = [ [[package]] name = "keyring-lib" version = "1.0.2" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "keyring", "once_cell", @@ -2581,7 +2581,7 @@ dependencies = [ [[package]] name = "mml-lib" version = "1.1.1" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "async-recursion", "chumsky", @@ -2787,7 +2787,7 @@ dependencies = [ [[package]] name = "oauth-lib" version = "2.0.0" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "http-lib", "oauth2", @@ -3097,7 +3097,7 @@ dependencies = [ [[package]] name = "pgp-lib" version = "1.0.0" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "async-recursion", "futures", @@ -3284,7 +3284,7 @@ dependencies = [ [[package]] name = "process-lib" version = "1.0.0" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "serde", "thiserror 2.0.18", @@ -3727,7 +3727,7 @@ dependencies = [ [[package]] name = "secret-lib" version = "1.0.0" -source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100" +source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8" dependencies = [ "keyring-lib", "process-lib", diff --git a/src/email/message/attachment/command/download.rs b/src/email/message/attachment/command/download.rs index 65ffc83f..774e638a 100644 --- a/src/email/message/attachment/command/download.rs +++ b/src/email/message/attachment/command/download.rs @@ -10,8 +10,8 @@ use tracing::info; use uuid::Uuid; use crate::{ - account::arg::name::AccountNameFlag, config::TomlConfig, envelope::arg::ids::EnvelopeIdsArgs, - folder::arg::name::FolderNameOptionalFlag, + account::arg::name::AccountNameFlag, config::TomlConfig, dir_parser, + envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::FolderNameOptionalFlag, }; /// Download all attachments found in the given message. @@ -28,6 +28,13 @@ pub struct AttachmentDownloadCommand { #[command(flatten)] pub account: AccountNameFlag, + + /// Override the download directory. + /// + /// If omitted, it uses the downloads directory from the config, + /// or `XDG_DOWNLOAD_DIR`. + #[arg(short = 'd', long, value_name = "PATH", value_parser = dir_parser)] + pub downloads_dir: Option, } impl AttachmentDownloadCommand { @@ -85,7 +92,8 @@ impl AttachmentDownloadCommand { .filename .unwrap_or_else(|| Uuid::new_v4().to_string()) .into(); - let filepath = account_config.get_download_file_path(&filename)?; + let filepath = account_config + .get_download_file_path(self.downloads_dir.as_deref(), &filename)?; printer.log(format!("Downloading {:?}…\n", filepath))?; fs::write(&filepath, &attachment.body) .with_context(|| format!("cannot save attachment at {filepath:?}"))?; diff --git a/src/lib.rs b/src/lib.rs index 0f796718..4f08591f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,5 +6,19 @@ pub mod email; pub mod folder; pub mod manual; +use std::path::PathBuf; + +use shellexpand_utils::{canonicalize, expand}; + #[doc(inline)] pub use crate::email::{envelope, flag, message}; + +/// Parse the given [`str`] as [`PathBuf`]. +/// +/// The path is first shell expanded, then canonicalized (if +/// applicable). +fn dir_parser(path: &str) -> Result { + expand::try_path(path) + .map(canonicalize::path) + .map_err(|err| err.to_string()) +} diff --git a/src/manual/command.rs b/src/manual/command.rs index 66a59f3e..2857efb2 100644 --- a/src/manual/command.rs +++ b/src/manual/command.rs @@ -4,10 +4,9 @@ use clap::{CommandFactory, Parser}; use clap_mangen::Man; use color_eyre::Result; use pimalaya_tui::terminal::cli::printer::Printer; -use shellexpand_utils::{canonicalize, expand}; use tracing::info; -use crate::cli::Cli; +use crate::{cli::Cli, dir_parser}; /// Generate manual pages to the given directory. /// @@ -61,13 +60,3 @@ impl ManualGenerateCommand { Ok(()) } } - -/// Parse the given [`str`] as [`PathBuf`]. -/// -/// The path is first shell expanded, then canonicalized (if -/// applicable). -fn dir_parser(path: &str) -> Result { - expand::try_path(path) - .map(canonicalize::path) - .map_err(|err| err.to_string()) -}