mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
review copy command
This commit is contained in:
parent
c155d30e54
commit
2e27972716
|
@ -44,4 +44,5 @@ pub fn target_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name("target")
|
Arg::with_name("target")
|
||||||
.help("Specifies the targetted mailbox")
|
.help("Specifies the targetted mailbox")
|
||||||
.value_name("TARGET")
|
.value_name("TARGET")
|
||||||
|
.required(true)
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,7 +152,9 @@ impl TryFrom<Option<&str>> for Mbox {
|
||||||
fn try_from(mbox: Option<&str>) -> Result<Self, Self::Error> {
|
fn try_from(mbox: Option<&str>) -> Result<Self, Self::Error> {
|
||||||
debug!("init mailbox from `{:?}`", mbox);
|
debug!("init mailbox from `{:?}`", mbox);
|
||||||
Ok(Self {
|
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()
|
..Self::default()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -288,7 +288,7 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
.arg(uid_arg())
|
.arg(uid_arg())
|
||||||
.arg(msg::attachment::arg::path_arg()),
|
.arg(msg::attachment::arg::path_arg()),
|
||||||
SubCommand::with_name("copy")
|
SubCommand::with_name("copy")
|
||||||
.aliases(&["cp"])
|
.aliases(&["cp", "c"])
|
||||||
.about("Copies a message to the targetted mailbox")
|
.about("Copies a message to the targetted mailbox")
|
||||||
.arg(uid_arg())
|
.arg(uid_arg())
|
||||||
.arg(mbox::arg::target_arg()),
|
.arg(mbox::arg::target_arg()),
|
||||||
|
|
|
@ -149,7 +149,8 @@ pub fn attachments<OutputService: OutputServiceInterface, ImapService: ImapServi
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy<ImapService: ImapServiceInterface>(
|
/// Copy the given message UID to the targetted mailbox.
|
||||||
|
pub fn copy<OutputService: OutputServiceInterface, ImapService: ImapServiceInterface>(
|
||||||
uid: &str,
|
uid: &str,
|
||||||
mbox: Option<&str>,
|
mbox: Option<&str>,
|
||||||
output: &OutputService,
|
output: &OutputService,
|
||||||
|
@ -157,12 +158,10 @@ pub fn copy<ImapService: ImapServiceInterface>(
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let target = Mbox::try_from(mbox)?;
|
let target = Mbox::try_from(mbox)?;
|
||||||
let mut msg = imap.get_msg(&uid)?;
|
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);
|
msg.flags.insert(Flag::Seen);
|
||||||
imap.append_msg(&target, &mut msg)?;
|
imap.append_msg(&target, &mut msg)?;
|
||||||
debug!("message {} successfully copied to folder `{}`", uid, target);
|
|
||||||
output.print(format!(
|
output.print(format!(
|
||||||
"Message {} successfully copied to folder `{}`",
|
r#"Message {} successfully copied to folder "{}""#,
|
||||||
uid, target
|
uid, target
|
||||||
))?;
|
))?;
|
||||||
imap.logout()?;
|
imap.logout()?;
|
||||||
|
|
Loading…
Reference in a new issue