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 2020-08-27 17:07:19 +03:00
parent e9a80b32ac
commit a37faf0bec
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 22 additions and 9 deletions

View File

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

View File

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