mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-20 15:11:11 +00:00
review attachment command
This commit is contained in:
parent
474fae06ee
commit
2bcad3ff87
|
@ -9,6 +9,7 @@ use crate::domain::msg;
|
||||||
/// Message attachment subcommands.
|
/// Message attachment subcommands.
|
||||||
pub(crate) fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
pub(crate) fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
vec![SubCommand::with_name("attachments")
|
vec![SubCommand::with_name("attachments")
|
||||||
|
.aliases(&["attachment", "att", "a"])
|
||||||
.about("Downloads all message attachments")
|
.about("Downloads all message attachments")
|
||||||
.arg(msg::arg::uid_arg())]
|
.arg(msg::arg::uid_arg())]
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,8 @@ fn msg_interaction<ImapService: ImapServiceInterface, SmtpService: SmtpServiceIn
|
||||||
Ok(true)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn attachments<ImapService: ImapServiceInterface>(
|
/// Download all attachments from the given message UID to the user account downloads directory.
|
||||||
|
pub fn attachments<OutputService: OutputServiceInterface, ImapService: ImapServiceInterface>(
|
||||||
uid: &str,
|
uid: &str,
|
||||||
account: &Account,
|
account: &Account,
|
||||||
output: &OutputService,
|
output: &OutputService,
|
||||||
|
@ -127,27 +128,21 @@ pub fn attachments<ImapService: ImapServiceInterface>(
|
||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"{} attachment(s) found for message {}",
|
"{} attachment(s) found for message {}",
|
||||||
&attachments.len(),
|
attachments.len(),
|
||||||
&uid
|
uid
|
||||||
);
|
);
|
||||||
|
|
||||||
// Iterate through all attachments and download them to the download
|
|
||||||
// directory of the account.
|
|
||||||
for attachment in &attachments {
|
for attachment in &attachments {
|
||||||
let filepath = account.downloads_dir.join(&attachment.filename);
|
let filepath = account.downloads_dir.join(&attachment.filename);
|
||||||
debug!("downloading {}…", &attachment.filename);
|
debug!("downloading {}…", attachment.filename);
|
||||||
fs::write(&filepath, &attachment.body_raw)
|
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!(
|
output.print(format!(
|
||||||
"{} attachment(s) successfully downloaded",
|
"{} attachment(s) successfully downloaded to {:?}",
|
||||||
&attachments.len()
|
attachments.len(),
|
||||||
|
account.downloads_dir
|
||||||
))?;
|
))?;
|
||||||
|
|
||||||
imap.logout()?;
|
imap.logout()?;
|
||||||
|
|
Loading…
Reference in a new issue