handle TimedOut error and use write_all
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user