From 2bcad3ff873430511403e6e8ac3cf439f045ea61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Sun, 19 Sep 2021 10:55:15 +0200 Subject: [PATCH] review attachment command --- src/domain/msg/attachment/arg.rs | 1 + src/domain/msg/handler.rs | 23 +++++++++-------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/domain/msg/attachment/arg.rs b/src/domain/msg/attachment/arg.rs index b36daf2..b2d2fee 100644 --- a/src/domain/msg/attachment/arg.rs +++ b/src/domain/msg/attachment/arg.rs @@ -9,6 +9,7 @@ use crate::domain::msg; /// Message attachment subcommands. pub(crate) fn subcmds<'a>() -> Vec> { vec![SubCommand::with_name("attachments") + .aliases(&["attachment", "att", "a"]) .about("Downloads all message attachments") .arg(msg::arg::uid_arg())] } diff --git a/src/domain/msg/handler.rs b/src/domain/msg/handler.rs index bcbf6d9..d74404a 100644 --- a/src/domain/msg/handler.rs +++ b/src/domain/msg/handler.rs @@ -116,7 +116,8 @@ fn msg_interaction( +/// Download all attachments from the given message UID to the user account downloads directory. +pub fn attachments( uid: &str, account: &Account, output: &OutputService, @@ -127,27 +128,21 @@ pub fn attachments( debug!( "{} attachment(s) found for message {}", - &attachments.len(), - &uid + attachments.len(), + uid ); - // Iterate through all attachments and download them to the download - // directory of the account. for attachment in &attachments { let filepath = account.downloads_dir.join(&attachment.filename); - debug!("downloading {}…", &attachment.filename); + debug!("downloading {}…", attachment.filename); fs::write(&filepath, &attachment.body_raw) - .context(format!("cannot save attachment {:?}", filepath))?; + .context(format!("cannot download attachment {:?}", filepath))?; } - debug!( - "{} attachment(s) successfully downloaded", - &attachments.len() - ); - output.print(format!( - "{} attachment(s) successfully downloaded", - &attachments.len() + "{} attachment(s) successfully downloaded to {:?}", + attachments.len(), + account.downloads_dir ))?; imap.logout()?;