handle TimedOut error and use write_all

This commit is contained in:
Florian Stecker
2024-07-29 13:21:24 -04:00
parent caf3912af1
commit 257d95528a
2 changed files with 5 additions and 389 deletions

View File

@@ -56,6 +56,7 @@ struct Status {
const CONNECTION_LOST_ERRORS: &[ErrorKind] = &[
ErrorKind::Interrupted,
ErrorKind::TimedOut,
ErrorKind::WouldBlock, // when a read times out
];
@@ -242,7 +243,7 @@ pub fn connect_and_idle<F: Fn(), G: Fn()>(cli: &Cli, connected_callback: F, mail
let responses = buffer[0..len]
.split(|&x|x == b'\r' || x == b'\n')
.filter(|&x|x.len() != 0);
.filter(|&x|!x.is_empty());
for response in responses {
if cli.verbose > 0 {
@@ -258,17 +259,17 @@ pub fn connect_and_idle<F: Fn(), G: Fn()>(cli: &Cli, connected_callback: F, mail
match state {
ImapState::Unauthenticated => if response.starts_with(b"* OK") {
let request = format!("A001 login {} {}\r\n", cli.username, cli.password);
tls_client.writer().write(request.as_bytes())?;
tls_client.writer().write_all(request.as_bytes())?;
state = ImapState::Authenticated;
},
ImapState::Authenticated => if response.starts_with(b"A001 OK") {
tls_client.writer().write(b"A002 select inbox\r\n")?;
tls_client.writer().write_all(b"A002 select inbox\r\n")?;
state = ImapState::Inbox;
} else if response.starts_with(b"A001") {
bail!("The server rejected authentication");
},
ImapState::Inbox => if response.starts_with(b"A002 OK") {
tls_client.writer().write(b"A003 idle\r\n")?;
tls_client.writer().write_all(b"A003 idle\r\n")?;
state = ImapState::Idling;
connected_callback();
// notify timer thread that we're live