mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-15 20:07:57 +08:00
refactor: use imap and smtp streams from toolbox
This commit is contained in:
@@ -10,7 +10,6 @@ use pimalaya_toolbox::terminal::printer::{Message, Printer};
|
||||
use crate::imap::{
|
||||
account::ImapAccount,
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxSelectFlag, TargetMailboxNameArg},
|
||||
stream,
|
||||
};
|
||||
|
||||
/// Move message(s) to the given mailbox.
|
||||
@@ -37,18 +36,17 @@ pub struct MoveMessageCommand {
|
||||
}
|
||||
|
||||
impl MoveMessageCommand {
|
||||
pub fn exec(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let (mut context, mut stream) = stream::connect(account.backend)?;
|
||||
|
||||
pub fn execute(self, printer: &mut impl Printer, account: ImapAccount) -> Result<()> {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox.name.try_into()?;
|
||||
|
||||
if self.select.r#true {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapSelect::new(context, mailbox);
|
||||
let mut coroutine = ImapSelect::new(imap.context, mailbox);
|
||||
|
||||
context = loop {
|
||||
imap.context = loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapSelectResult::Io { io } => arg = Some(handle(&mut stream, io)?),
|
||||
ImapSelectResult::Io { io } => arg = Some(handle(&mut imap.stream, io)?),
|
||||
ImapSelectResult::Ok { context, .. } => break context,
|
||||
ImapSelectResult::Err { err, .. } => bail!(err),
|
||||
}
|
||||
@@ -59,11 +57,11 @@ impl MoveMessageCommand {
|
||||
let destination: Mailbox<'static> = self.destination.name.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapMove::new(context, sequence_set, destination, !self.seq);
|
||||
let mut coroutine = ImapMove::new(imap.context, sequence_set, destination, !self.seq);
|
||||
|
||||
loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapMoveResult::Io { io } => arg = Some(handle(&mut stream, io)?),
|
||||
ImapMoveResult::Io { io } => arg = Some(handle(&mut imap.stream, io)?),
|
||||
ImapMoveResult::Ok { .. } => break,
|
||||
ImapMoveResult::Err { err, .. } => bail!(err),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user