mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-17 13:17:55 +08:00
feat: add downloads directory argument for attachment download
Refs: #559
This commit is contained in:
Generated
+8
-8
@@ -1216,7 +1216,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "email-lib"
|
name = "email-lib"
|
||||||
version = "0.26.4"
|
version = "0.26.4"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -1862,7 +1862,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "http-lib"
|
name = "http-lib"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
"tokio",
|
"tokio",
|
||||||
@@ -2265,7 +2265,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "keyring-lib"
|
name = "keyring-lib"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"keyring",
|
"keyring",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@@ -2581,7 +2581,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "mml-lib"
|
name = "mml-lib"
|
||||||
version = "1.1.1"
|
version = "1.1.1"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
"chumsky",
|
"chumsky",
|
||||||
@@ -2787,7 +2787,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "oauth-lib"
|
name = "oauth-lib"
|
||||||
version = "2.0.0"
|
version = "2.0.0"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"http-lib",
|
"http-lib",
|
||||||
"oauth2",
|
"oauth2",
|
||||||
@@ -3097,7 +3097,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "pgp-lib"
|
name = "pgp-lib"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-recursion",
|
"async-recursion",
|
||||||
"futures",
|
"futures",
|
||||||
@@ -3284,7 +3284,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "process-lib"
|
name = "process-lib"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"thiserror 2.0.18",
|
"thiserror 2.0.18",
|
||||||
@@ -3727,7 +3727,7 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "secret-lib"
|
name = "secret-lib"
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
source = "git+https://github.com/pimalaya/core#145f89686fc6ef7b41523e62802a7133e1461100"
|
source = "git+https://github.com/pimalaya/core#839bc44905570a17a86554d49b7d081b1e15c1a8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"keyring-lib",
|
"keyring-lib",
|
||||||
"process-lib",
|
"process-lib",
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ use tracing::info;
|
|||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
account::arg::name::AccountNameFlag, config::TomlConfig, envelope::arg::ids::EnvelopeIdsArgs,
|
account::arg::name::AccountNameFlag, config::TomlConfig, dir_parser,
|
||||||
folder::arg::name::FolderNameOptionalFlag,
|
envelope::arg::ids::EnvelopeIdsArgs, folder::arg::name::FolderNameOptionalFlag,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Download all attachments found in the given message.
|
/// Download all attachments found in the given message.
|
||||||
@@ -28,6 +28,13 @@ pub struct AttachmentDownloadCommand {
|
|||||||
|
|
||||||
#[command(flatten)]
|
#[command(flatten)]
|
||||||
pub account: AccountNameFlag,
|
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 {
|
impl AttachmentDownloadCommand {
|
||||||
@@ -85,7 +92,8 @@ impl AttachmentDownloadCommand {
|
|||||||
.filename
|
.filename
|
||||||
.unwrap_or_else(|| Uuid::new_v4().to_string())
|
.unwrap_or_else(|| Uuid::new_v4().to_string())
|
||||||
.into();
|
.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))?;
|
printer.log(format!("Downloading {:?}…\n", filepath))?;
|
||||||
fs::write(&filepath, &attachment.body)
|
fs::write(&filepath, &attachment.body)
|
||||||
.with_context(|| format!("cannot save attachment at {filepath:?}"))?;
|
.with_context(|| format!("cannot save attachment at {filepath:?}"))?;
|
||||||
|
|||||||
+14
@@ -6,5 +6,19 @@ pub mod email;
|
|||||||
pub mod folder;
|
pub mod folder;
|
||||||
pub mod manual;
|
pub mod manual;
|
||||||
|
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use shellexpand_utils::{canonicalize, expand};
|
||||||
|
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use crate::email::{envelope, flag, message};
|
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
@@ -4,10 +4,9 @@ use clap::{CommandFactory, Parser};
|
|||||||
use clap_mangen::Man;
|
use clap_mangen::Man;
|
||||||
use color_eyre::Result;
|
use color_eyre::Result;
|
||||||
use pimalaya_tui::terminal::cli::printer::Printer;
|
use pimalaya_tui::terminal::cli::printer::Printer;
|
||||||
use shellexpand_utils::{canonicalize, expand};
|
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
use crate::cli::Cli;
|
use crate::{cli::Cli, dir_parser};
|
||||||
|
|
||||||
/// Generate manual pages to the given directory.
|
/// Generate manual pages to the given directory.
|
||||||
///
|
///
|
||||||
@@ -61,13 +60,3 @@ impl ManualGenerateCommand {
|
|||||||
Ok(())
|
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())
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user