testing/imap_conn: update imapconn shell use

async
Manos Pitsidianakis 2019-12-11 00:07:47 +02:00
parent 504b658f68
commit bce97d71bb
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
3 changed files with 18 additions and 6 deletions

View File

@ -250,6 +250,10 @@ pub trait MailBackend: ::std::fmt::Debug + Send + Sync {
None
}
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any {
unimplemented!()
}
}
/// A `BackendOp` manages common operations for the various mail backends. They only live for the

View File

@ -471,6 +471,10 @@ impl MailBackend for ImapType {
self
}
fn as_any_mut(&mut self) -> &mut dyn::std::any::Any {
self
}
fn tags(&self) -> Option<Arc<RwLock<BTreeMap<u64, String>>>> {
if *self.can_create_flags.lock().unwrap() {
Some(self.tag_index.clone())
@ -530,8 +534,8 @@ impl ImapType {
pub fn shell(&mut self) {
let mut conn = ImapConnection::new_connection(&self.server_conf);
let mut res = String::with_capacity(8 * 1024);
conn.send_command(b"NOOP").unwrap();
conn.read_response(&mut res).unwrap();
debug!("out: {}", &res);
let mut input = String::new();
loop {
@ -540,6 +544,9 @@ impl ImapType {
match io::stdin().read_line(&mut input) {
Ok(_) => {
if input.trim().eq_ignore_ascii_case("logout") {
break;
}
conn.send_command(input.as_bytes()).unwrap();
conn.read_lines(&mut res, String::new()).unwrap();
if input.trim() == "IDLE" {
@ -550,9 +557,6 @@ impl ImapType {
conn = iter.into_conn();
}
debug!("out: {}", &res);
if input.trim().eq_ignore_ascii_case("logout") {
break;
}
}
Err(error) => debug!("error: {}", error),
}

View File

@ -33,7 +33,11 @@ fn main() -> Result<()> {
.collect(),
..Default::default()
};
let mut imap = ImapType::new(&set, Box::new(|_| true));
imap.shell();
let mut imap = ImapType::new(&set, Box::new(|_| true))?;
(imap.as_any_mut())
.downcast_mut::<ImapType>()
.unwrap()
.shell();
Ok(())
}