Escape password according to RFC3501
Rebased by rhn <gihu.rhn@porcupinefactory.org>
This commit is contained in:
parent
542ee159a4
commit
1ad1f1f847
1 changed files with 8 additions and 2 deletions
|
|
@ -15,6 +15,12 @@ const INITIAL_TAG: u32 = 0;
|
||||||
const CR: u8 = 0x0d;
|
const CR: u8 = 0x0d;
|
||||||
const LF: u8 = 0x0a;
|
const LF: u8 = 0x0a;
|
||||||
|
|
||||||
|
macro_rules! quote {
|
||||||
|
($x: expr) => (
|
||||||
|
format!("\"{}\"", $x.replace("\\", "\\\\").replace("\"", "\\\""))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Stream to interface with the IMAP server. This interface is only for the command stream.
|
/// Stream to interface with the IMAP server. This interface is only for the command stream.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Client<T: Read + Write> {
|
pub struct Client<T: Read + Write> {
|
||||||
|
|
@ -278,7 +284,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
|
|
||||||
/// Log in to the IMAP server.
|
/// Log in to the IMAP server.
|
||||||
pub fn login(&mut self, username: &str, password: &str) -> Result<()> {
|
pub fn login(&mut self, username: &str, password: &str) -> Result<()> {
|
||||||
self.run_command_and_check_ok(&format!("LOGIN {} {}", username, password))
|
self.run_command_and_check_ok(&format!("LOGIN {} {}", username, quote!(password)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Selects a mailbox
|
/// Selects a mailbox
|
||||||
|
|
@ -601,7 +607,7 @@ mod tests {
|
||||||
let response = b"a1 OK Logged in\r\n".to_vec();
|
let response = b"a1 OK Logged in\r\n".to_vec();
|
||||||
let username = "username";
|
let username = "username";
|
||||||
let password = "password";
|
let password = "password";
|
||||||
let command = format!("a1 LOGIN {} {}\r\n", username, password);
|
let command = format!("a1 LOGIN {} {}\r\n", username, quote!(password));
|
||||||
let mock_stream = MockStream::new(response);
|
let mock_stream = MockStream::new(response);
|
||||||
let mut client = Client::new(mock_stream);
|
let mut client = Client::new(mock_stream);
|
||||||
client.login(username, password).unwrap();
|
client.login(username, password).unwrap();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue