mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 09:05:13 +00:00
review delete command
This commit is contained in:
parent
2e27972716
commit
71818e04b4
|
@ -204,35 +204,22 @@ impl<'a> ImapServiceInterface for ImapService<'a> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Add the given flags to the given mail.
|
||||
/// Add flags to the given message UID sequence.
|
||||
///
|
||||
/// # Example
|
||||
/// ```no_run
|
||||
/// use himalaya::imap::model::ImapConnector;
|
||||
/// use himalaya::config::model::Account;
|
||||
/// use himalaya::flag::model::Flags;
|
||||
/// use imap::types::Flag;
|
||||
/// ```ignore
|
||||
///
|
||||
/// fn main() {
|
||||
/// let account = Account::default();
|
||||
/// let mut imap_conn = ImapConnector::new(&account).unwrap();
|
||||
/// let flags = Flags::from(vec![Flag::Seen]);
|
||||
///
|
||||
/// // Mark the message with the UID 42 in the mailbox "rofl" as "Seen"
|
||||
/// imap_conn.add_flags("rofl", "42", flags).unwrap();
|
||||
///
|
||||
/// imap_conn.logout();
|
||||
/// }
|
||||
/// let flags = Flags::from(vec![Flag::Seen, Flag::Deleted]);
|
||||
/// imap.add_flags("5:10", flags)
|
||||
/// ```
|
||||
fn add_flags(&mut self, uid_seq: &str, flags: Flags) -> Result<()> {
|
||||
let mbox = self.mbox.to_owned();
|
||||
let flags: String = flags.to_string();
|
||||
self.sess()?
|
||||
.select(&mbox.name)
|
||||
.context(format!("cannot select mbox `{}`", self.mbox.name))?;
|
||||
.context(format!(r#"cannot select mailbox "{}""#, self.mbox.name))?;
|
||||
self.sess()?
|
||||
.uid_store(uid_seq, format!("+FLAGS ({})", flags))
|
||||
.context(format!("cannot add flags `{}`", &flags))?;
|
||||
.context(format!(r#"cannot add flags "{}""#, &flags))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
|
@ -298,7 +298,7 @@ pub fn subcmds<'a>() -> Vec<App<'a, 'a>> {
|
|||
.arg(uid_arg())
|
||||
.arg(mbox::arg::target_arg()),
|
||||
SubCommand::with_name("delete")
|
||||
.aliases(&["remove", "rm"])
|
||||
.aliases(&["del", "d", "remove", "rm"])
|
||||
.about("Deletes a message")
|
||||
.arg(uid_arg()),
|
||||
],
|
||||
|
|
|
@ -168,16 +168,16 @@ pub fn copy<OutputService: OutputServiceInterface, ImapService: ImapServiceInter
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn delete<ImapService: ImapServiceInterface>(
|
||||
/// Delete the given message UID from the selected mailbox.
|
||||
pub fn delete<OutputService: OutputServiceInterface, ImapService: ImapServiceInterface>(
|
||||
uid: &str,
|
||||
output: &OutputService,
|
||||
imap: &mut ImapService,
|
||||
) -> Result<()> {
|
||||
let flags = vec![Flag::Seen, Flag::Deleted];
|
||||
imap.add_flags(uid, Flags::from(flags))?;
|
||||
let flags = Flags::from(vec![Flag::Seen, Flag::Deleted]);
|
||||
imap.add_flags(uid, flags)?;
|
||||
imap.expunge()?;
|
||||
debug!("message {} successfully deleted", uid);
|
||||
output.print(format!("Message {} successfully deleted", uid))?;
|
||||
output.print(format!("Message(s) {} successfully deleted", uid))?;
|
||||
imap.logout()?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue