Browse Source

testing/imap_conn: update imapconn shell use

async
Manos Pitsidianakis 2 years ago
parent
commit
bce97d71bb
Signed by: epilys GPG Key ID: 73627C2F690DF710
  1. 4
      melib/src/backends.rs
  2. 12
      melib/src/backends/imap.rs
  3. 8
      testing/src/imap_conn.rs

4
melib/src/backends.rs

@ -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

12
melib/src/backends/imap.rs

@ -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),
}

8
testing/src/imap_conn.rs

@ -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(())
}
Loading…
Cancel
Save