From a37faf0beca87f611e9ae747bd3b3cd7e1049136 Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Thu, 27 Aug 2020 17:07:19 +0300 Subject: [PATCH] Fix imapconn IMAP shell binary IMAP shell hasn't been working since updating IMAP to async. Now it works by using block_on executor. --- melib/src/backends/imap.rs | 28 ++++++++++++++++++++-------- testing/src/imap_conn.rs | 3 ++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/melib/src/backends/imap.rs b/melib/src/backends/imap.rs index b923136d..9f7118e7 100644 --- a/melib/src/backends/imap.rs +++ b/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( diff --git a/testing/src/imap_conn.rs b/testing/src/imap_conn.rs index 00b66523..00fa93ae 100644 --- a/testing/src/imap_conn.rs +++ b/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::() .unwrap()