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