Browse Source

testing/imap_conn: update imapconn shell use

tags/alpha-0.5.0
Manos Pitsidianakis 2 months ago
parent
commit
bce97d71bb
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS. GPG Key ID: 73627C2F690DF710
3 changed files with 18 additions and 6 deletions
  1. +4
    -0
      melib/src/backends.rs
  2. +8
    -4
      melib/src/backends/imap.rs
  3. +6
    -2
      testing/src/imap_conn.rs

+ 4
- 0
melib/src/backends.rs 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


+ 8
- 4
melib/src/backends/imap.rs 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),
}


+ 6
- 2
testing/src/imap_conn.rs 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(())
}

Loading…
Cancel
Save