Cleaning up some of the authenticator code

This commit is contained in:
Matt McCoy 2016-06-29 16:45:36 -04:00
parent 8d39bfd343
commit 43f4737b85

View file

@ -60,9 +60,17 @@ impl<T: Read+Write> Client<T> {
} }
} }
/// Authenticate will authenticate with the server, using the authenticator given.
pub fn authenticate<A: Authenticator>(&mut self, auth_type: &str, authenticator: A) -> Result<()> { pub fn authenticate<A: Authenticator>(&mut self, auth_type: &str, authenticator: A) -> Result<()> {
match self.run_command(&format!("AUTHENTICATE {}", auth_type).to_string()) { match self.run_command(&format!("AUTHENTICATE {}", auth_type).to_string()) {
Ok(_) => { Ok(_) => self.do_auth_handshake(authenticator),
Err(e) => Err(e)
}
}
/// This func does the handshake process once the authenticate command is made.
fn do_auth_handshake<A: Authenticator>(&mut self, authenticator: A) -> Result<()> {
// TODO Clean up this code
loop { loop {
let line = match self.readline() { let line = match self.readline() {
Ok(l) => l, Ok(l) => l,
@ -99,9 +107,6 @@ impl<T: Read+Write> Client<T> {
}; };
} }
} }
},
Err(e) => Err(e)
}
} }
/// Log in to the IMAP server. /// Log in to the IMAP server.