review copy command

This commit is contained in:
Clément DOUIN 2021-09-19 11:18:17 +02:00
parent c155d30e54
commit 2e27972716
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
4 changed files with 8 additions and 6 deletions

View file

@ -44,4 +44,5 @@ pub fn target_arg<'a>() -> Arg<'a, 'a> {
Arg::with_name("target")
.help("Specifies the targetted mailbox")
.value_name("TARGET")
.required(true)
}

View file

@ -152,7 +152,9 @@ impl TryFrom<Option<&str>> for Mbox {
fn try_from(mbox: Option<&str>) -> Result<Self, Self::Error> {
debug!("init mailbox from `{:?}`", mbox);
Ok(Self {
name: mbox.ok_or(anyhow!("cannot parse mailbox"))?.to_string(),
name: mbox
.ok_or(anyhow!("the target mailbox cannot be empty"))?
.to_string(),
..Self::default()
})
}

View file

@ -288,7 +288,7 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
.arg(uid_arg())
.arg(msg::attachment::arg::path_arg()),
SubCommand::with_name("copy")
.aliases(&["cp"])
.aliases(&["cp", "c"])
.about("Copies a message to the targetted mailbox")
.arg(uid_arg())
.arg(mbox::arg::target_arg()),

View file

@ -149,7 +149,8 @@ pub fn attachments<OutputService: OutputServiceInterface, ImapService: ImapServi
Ok(())
}
pub fn copy<ImapService: ImapServiceInterface>(
/// Copy the given message UID to the targetted mailbox.
pub fn copy<OutputService: OutputServiceInterface, ImapService: ImapServiceInterface>(
uid: &str,
mbox: Option<&str>,
output: &OutputService,
@ -157,12 +158,10 @@ pub fn copy<ImapService: ImapServiceInterface>(
) -> Result<()> {
let target = Mbox::try_from(mbox)?;
let mut msg = imap.get_msg(&uid)?;
// the message, which will be in the new mailbox doesn't need to be seen
msg.flags.insert(Flag::Seen);
imap.append_msg(&target, &mut msg)?;
debug!("message {} successfully copied to folder `{}`", uid, target);
output.print(format!(
"Message {} successfully copied to folder `{}`",
r#"Message {} successfully copied to folder "{}""#,
uid, target
))?;
imap.logout()?;