Browse Source

Fix imapconn IMAP shell binary

IMAP shell hasn't been working since updating IMAP to async. Now it
works by using block_on executor.
master
Manos Pitsidianakis 2 years ago
parent
commit
a37faf0bec
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 28
      melib/src/backends/imap.rs
  2. 3
      testing/src/imap_conn.rs

28
melib/src/backends/imap.rs

@ -1197,14 +1197,17 @@ impl ImapType {
}
pub fn shell(&mut self) {
unimplemented!()
/*
let mut conn = ImapConnection::new_connection(&self.server_conf, self.uid_store.clone());
conn.connect().unwrap();
futures::executor::block_on(timeout(Duration::from_secs(3), conn.connect())).unwrap();
let mut res = String::with_capacity(8 * 1024);
conn.send_command(b"NOOP").unwrap();
conn.read_response(&mut res, RequiredResponses::empty())
futures::executor::block_on(timeout(Duration::from_secs(3), conn.send_command(b"NOOP")))
.unwrap();
futures::executor::block_on(timeout(
Duration::from_secs(3),
conn.read_response(&mut res, RequiredResponses::empty()),
))
.unwrap();
let mut input = String::new();
loop {
@ -1216,8 +1219,17 @@ impl ImapType {
if input.trim().eq_ignore_ascii_case("logout") {
break;
}
conn.send_command(input.as_bytes()).unwrap();
conn.read_lines(&mut res, String::new()).unwrap();
futures::executor::block_on(timeout(
Duration::from_secs(3),
conn.send_command(input.as_bytes()),
))
.unwrap();
futures::executor::block_on(timeout(
Duration::from_secs(3),
conn.read_lines(&mut res, String::new()),
))
.unwrap();
/*
if input.trim() == "IDLE" {
let mut iter = ImapBlockingConnection::from(conn);
while let Some(line) = iter.next() {
@ -1225,12 +1237,12 @@ impl ImapType {
}
conn = iter.into_conn();
}
*/
debug!("out: {}", &res);
}
Err(error) => debug!("error: {}", error),
}
}
*/
}
pub async fn imap_mailboxes(

3
testing/src/imap_conn.rs

@ -1,7 +1,7 @@
extern crate melib;
use melib::backends::ImapType;
use melib::Result;
use melib::{futures, smol, Result};
use melib::{AccountSettings, BackendEventConsumer};
/// Opens an interactive shell on an IMAP server. Suggested use is with rlwrap(1)
@ -48,6 +48,7 @@ fn main() -> Result<()> {
BackendEventConsumer::new(std::sync::Arc::new(|_, _| ())),
)?;
std::thread::spawn(|| smol::run(futures::future::pending::<()>()));
(imap.as_any_mut())
.downcast_mut::<ImapType>()
.unwrap()

Loading…
Cancel
Save