mirror of
https://github.com/soywod/himalaya.git
synced 2024-11-22 11:00:19 +00:00
review copy command
This commit is contained in:
parent
c155d30e54
commit
2e27972716
4 changed files with 8 additions and 6 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
})
|
||||
}
|
||||
|
|
|
@ -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()),
|
||||
|
|
|
@ -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()?;
|
||||
|
|
Loading…
Reference in a new issue