feat: add downloads directory argument for attachment download

Refs: #559
This commit is contained in:
Clément DOUIN
2026-01-21 22:12:30 +01:00
parent 63b3485575
commit 6219e30609
4 changed files with 34 additions and 23 deletions
Generated
+8 -8
View File
@@ -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",
@@ -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<PathBuf>,
}
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:?}"))?;
+14
View File
@@ -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<PathBuf, String> {
expand::try_path(path)
.map(canonicalize::path)
.map_err(|err| err.to_string())
}
+1 -12
View File
@@ -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<PathBuf, String> {
expand::try_path(path)
.map(canonicalize::path)
.map_err(|err| err.to_string())
}