mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-15 20:07:57 +08:00
refactor: unify command names
This commit is contained in:
+15
-15
@@ -1,10 +1,7 @@
|
||||
use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
use io_imap::{
|
||||
coroutines::{r#move::*, select::*},
|
||||
types::mailbox::Mailbox,
|
||||
};
|
||||
use io_stream::runtimes::std::handle;
|
||||
use io_imap::{rfc3501::select::*, rfc6851::r#move::*, types::mailbox::Mailbox};
|
||||
use io_socket::runtimes::std_stream::handle;
|
||||
use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
|
||||
use crate::imap::{
|
||||
@@ -18,7 +15,7 @@ use crate::imap::{
|
||||
/// from the source mailbox to the destination mailbox. Requires the
|
||||
/// MOVE IMAP extension.
|
||||
#[derive(Debug, Parser)]
|
||||
pub struct MoveMessagesCommand {
|
||||
pub struct ImapMessageMoveCommand {
|
||||
#[command(flatten)]
|
||||
pub mailbox_name: MailboxNameOptionalFlag,
|
||||
#[command(flatten)]
|
||||
@@ -35,20 +32,22 @@ pub struct MoveMessagesCommand {
|
||||
pub seq: bool,
|
||||
}
|
||||
|
||||
impl MoveMessagesCommand {
|
||||
impl ImapMessageMoveCommand {
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
let mut coroutine = ImapMailboxSelect::new(imap.context, mailbox);
|
||||
|
||||
imap.context = loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapSelectResult::Io { io } => arg = Some(handle(&mut imap.stream, io)?),
|
||||
ImapSelectResult::Ok { context, .. } => break context,
|
||||
ImapSelectResult::Err { err, .. } => bail!(err),
|
||||
ImapMailboxSelectResult::Io { input } => {
|
||||
arg = Some(handle(&mut imap.stream, input)?)
|
||||
}
|
||||
ImapMailboxSelectResult::Ok { context, .. } => break context,
|
||||
ImapMailboxSelectResult::Err { err, .. } => bail!(err),
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -57,13 +56,14 @@ impl MoveMessagesCommand {
|
||||
let destination: Mailbox<'static> = self.mailbox_dest_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapMove::new(imap.context, sequence_set, destination, !self.seq);
|
||||
let mut coroutine =
|
||||
ImapMessageMove::new(imap.context, sequence_set, destination, !self.seq);
|
||||
|
||||
loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapMoveResult::Io { io } => arg = Some(handle(&mut imap.stream, io)?),
|
||||
ImapMoveResult::Ok { .. } => break,
|
||||
ImapMoveResult::Err { err, .. } => bail!(err),
|
||||
ImapMessageMoveResult::Io { input } => arg = Some(handle(&mut imap.stream, input)?),
|
||||
ImapMessageMoveResult::Ok { .. } => break,
|
||||
ImapMessageMoveResult::Err { err, .. } => bail!(err),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user