mirror of
https://github.com/pimalaya/himalaya.git
synced 2026-06-15 20:07:57 +08:00
rewrite lib without io-socket nor io-fs, and with io-email
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use std::io::{Read, Write};
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use clap::Parser;
|
||||
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::{
|
||||
@@ -9,6 +10,8 @@ use crate::imap::{
|
||||
mailbox::arg::{MailboxNameOptionalFlag, MailboxNoSelectFlag, TargetMailboxNameArg},
|
||||
};
|
||||
|
||||
const READ_BUFFER_SIZE: usize = 16 * 1024;
|
||||
|
||||
/// Move message(s) to the given mailbox.
|
||||
///
|
||||
/// This command moves messages identified by the given sequence set
|
||||
@@ -37,17 +40,24 @@ impl ImapMessageMoveCommand {
|
||||
let mut imap = account.new_imap_session()?;
|
||||
let mailbox = self.mailbox_name.inner.try_into()?;
|
||||
|
||||
let mut buf = [0u8; READ_BUFFER_SIZE];
|
||||
|
||||
if !self.mailbox_no_select.inner {
|
||||
let mut arg = None;
|
||||
let mut coroutine = ImapMailboxSelect::new(imap.context, mailbox);
|
||||
let mut arg: Option<&[u8]> = None;
|
||||
|
||||
imap.context = loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapMailboxSelectResult::Io { input } => {
|
||||
arg = Some(handle(&mut imap.stream, input)?)
|
||||
}
|
||||
ImapMailboxSelectResult::Ok { context, .. } => break context,
|
||||
ImapMailboxSelectResult::Err { err, .. } => bail!(err),
|
||||
ImapMailboxSelectResult::WantsRead => {
|
||||
let n = imap.stream.read(&mut buf)?;
|
||||
arg = Some(&buf[..n]);
|
||||
}
|
||||
ImapMailboxSelectResult::WantsWrite(bytes) => {
|
||||
imap.stream.write_all(&bytes)?;
|
||||
arg = None;
|
||||
}
|
||||
ImapMailboxSelectResult::Err { err, .. } => bail!("{err}"),
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -55,15 +65,22 @@ impl ImapMessageMoveCommand {
|
||||
let sequence_set = self.sequence_set.as_str().try_into()?;
|
||||
let destination: Mailbox<'static> = self.mailbox_dest_name.inner.try_into()?;
|
||||
|
||||
let mut arg = None;
|
||||
let mut coroutine =
|
||||
ImapMessageMove::new(imap.context, sequence_set, destination, !self.seq);
|
||||
let mut arg: Option<&[u8]> = None;
|
||||
|
||||
loop {
|
||||
match coroutine.resume(arg.take()) {
|
||||
ImapMessageMoveResult::Io { input } => arg = Some(handle(&mut imap.stream, input)?),
|
||||
ImapMessageMoveResult::Ok { .. } => break,
|
||||
ImapMessageMoveResult::Err { err, .. } => bail!(err),
|
||||
ImapMessageMoveResult::WantsRead => {
|
||||
let n = imap.stream.read(&mut buf)?;
|
||||
arg = Some(&buf[..n]);
|
||||
}
|
||||
ImapMessageMoveResult::WantsWrite(bytes) => {
|
||||
imap.stream.write_all(&bytes)?;
|
||||
arg = None;
|
||||
}
|
||||
ImapMessageMoveResult::Err { err, .. } => bail!("{err}"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user