melib/imap: try NOOPing in connect()

master
Manos Pitsidianakis 2020-09-12 21:33:25 +03:00
parent 5079881a4c
commit 7c6e3658c7
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
1 changed files with 18 additions and 2 deletions

View File

@ -526,9 +526,24 @@ impl ImapConnection {
self.stream = Err(err);
}
}
if self.stream.is_ok() {
if debug!(self.stream.is_ok()) {
let mut ret = String::new();
if let Err(err) = try_await(async {
self.send_command(b"NOOP").await?;
self.read_response(&mut ret, RequiredResponses::empty())
.await
})
.await
{
debug!("connect(): connection is probably dead: {:?}", &err);
} else {
debug!(
"connect(): connection is probably alive, NOOP returned {:?}",
&ret
);
return Ok(());
}
}
let new_stream = debug!(ImapStream::new_connection(&self.server_conf).await);
if let Err(err) = new_stream.as_ref() {
self.uid_store.is_online.lock().unwrap().1 = Err(err.clone());
@ -714,6 +729,7 @@ impl ImapConnection {
}
Err(err)
} else {
*self.uid_store.is_online.lock().unwrap() = (Instant::now(), Ok(()));
Ok(())
}
}