diff --git a/examples/basic.rs b/examples/basic.rs index 1aee000..2107ec2 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -17,11 +17,9 @@ fn main() { imap_socket.login("username", "password").unwrap(); match imap_socket.capability() { - Ok(capabilities) => { - for capability in capabilities.iter() { - println!("{}", capability); - } - } + Ok(capabilities) => for capability in capabilities.iter() { + println!("{}", capability); + }, Err(e) => println!("Error parsing capability: {}", e), }; @@ -33,11 +31,9 @@ fn main() { }; match imap_socket.fetch("2", "body[text]") { - Ok(lines) => { - for line in lines.iter() { - print!("{}", line); - } - } + Ok(lines) => for line in lines.iter() { + print!("{}", line); + }, Err(e) => println!("Error Fetching email 2: {}", e), }; diff --git a/examples/gmail_oauth2.rs b/examples/gmail_oauth2.rs index 6f5b91d..b80bfac 100644 --- a/examples/gmail_oauth2.rs +++ b/examples/gmail_oauth2.rs @@ -1,6 +1,6 @@ +extern crate base64; extern crate imap; extern crate openssl; -extern crate base64; use openssl::ssl::{SslConnectorBuilder, SslMethod}; use base64::encode; @@ -44,11 +44,9 @@ fn main() { }; match imap_socket.fetch("2", "body[text]") { - Ok(lines) => { - for line in lines.iter() { - print!("{}", line); - } - } + Ok(lines) => for line in lines.iter() { + print!("{}", line); + }, Err(e) => println!("Error Fetching email 2: {}", e), }; diff --git a/src/client.rs b/src/client.rs index 12d07ca..7f00f62 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,8 +6,8 @@ use bufstream::BufStream; use super::mailbox::Mailbox; use super::authenticator::Authenticator; -use super::parse::{parse_response_ok, parse_capability, parse_select_or_examine, parse_response, - parse_authenticate_response}; +use super::parse::{parse_authenticate_response, parse_capability, parse_response, + parse_response_ok, parse_select_or_examine}; use super::error::{Error, Result}; static TAG_PREFIX: &'static str = "a"; @@ -101,7 +101,8 @@ impl<'a, T: Read + Write + 'a> IdleHandle<'a, T> { fn wait_inner(&mut self) -> Result<()> { match self.client.readline().map(|_| ()) { Err(Error::Io(ref e)) - if e.kind() == io::ErrorKind::TimedOut || e.kind() == io::ErrorKind::WouldBlock => { + if e.kind() == io::ErrorKind::TimedOut || e.kind() == io::ErrorKind::WouldBlock => + { // we need to refresh the IDLE connection try!(self.terminate()); try!(self.init()); @@ -264,7 +265,6 @@ impl Client { } else if line.starts_with(format!("{}{} ", TAG_PREFIX, self.tag).as_bytes()) { try!(parse_response(vec![String::from_utf8(line).unwrap()])); return Ok(()); - } else { let mut lines = try!(self.read_response()); lines.insert(0, String::from_utf8(line).unwrap()); @@ -281,17 +281,13 @@ impl Client { /// Selects a mailbox pub fn select(&mut self, mailbox_name: &str) -> Result { - let lines = try!(self.run_command_and_read_response( - &format!("SELECT {}", mailbox_name) - )); + let lines = try!(self.run_command_and_read_response(&format!("SELECT {}", mailbox_name))); parse_select_or_examine(lines) } /// Examine is identical to Select, but the selected mailbox is identified as read-only pub fn examine(&mut self, mailbox_name: &str) -> Result { - let lines = try!(self.run_command_and_read_response( - &format!("EXAMINE {}", mailbox_name) - )); + let lines = try!(self.run_command_and_read_response(&format!("EXAMINE {}", mailbox_name))); parse_select_or_examine(lines) } @@ -427,9 +423,7 @@ impl Client { /// The APPEND command adds a mail to a mailbox. pub fn append(&mut self, folder: &str, content: &[u8]) -> Result> { - try!(self.run_command( - &format!("APPEND \"{}\" {{{}}}", folder, content.len()) - )); + try!(self.run_command(&format!("APPEND \"{}\" {{{}}}", folder, content.len()))); let line = try!(self.readline()); if !line.starts_with(b"+") { return Err(Error::Append); @@ -552,7 +546,9 @@ mod tests { fn readline_delay_read() { let greeting = "* OK Dovecot ready.\r\n"; let expected_response: String = greeting.to_string(); - let mock_stream = MockStream::default().with_buf(greeting.as_bytes().to_vec()).with_delay(); + let mock_stream = MockStream::default() + .with_buf(greeting.as_bytes().to_vec()) + .with_delay(); let mut client = Client::new(mock_stream); let actual_response = String::from_utf8(client.readline().unwrap()).unwrap(); assert_eq!(expected_response, actual_response); @@ -850,7 +846,6 @@ mod tests { where F: FnOnce(&mut Client, &str, &str) -> Result, { - let res = "* 2 FETCH (FLAGS (\\Deleted \\Seen))\r\n\ * 3 FETCH (FLAGS (\\Deleted))\r\n\ * 4 FETCH (FLAGS (\\Deleted \\Flagged \\Seen))\r\n\ @@ -873,7 +868,6 @@ mod tests { where F: FnOnce(&mut Client, &str, &str) -> Result, { - generic_with_uid( "OK COPY completed\r\n", "COPY", @@ -898,7 +892,6 @@ mod tests { where F: FnOnce(&mut Client, &str, &str) -> Result, { - generic_with_uid("OK FETCH completed\r\n", "FETCH", "1", "BODY[]", prefix, op); } @@ -906,7 +899,6 @@ mod tests { where F: FnOnce(&mut Client, &str, &str) -> Result, { - let resp = format!("a1 {}\r\n", res).as_bytes().to_vec(); let line = format!("a1{}{} {} {}\r\n", prefix, cmd, seq, query); let mut client = Client::new(MockStream::new(resp)); diff --git a/src/lib.rs b/src/lib.rs index 1a7687a..6473674 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,8 @@ //! imap is a IMAP client for Rust. -extern crate openssl; extern crate bufstream; +extern crate openssl; extern crate regex; pub mod authenticator; diff --git a/src/mock_stream.rs b/src/mock_stream.rs index 580311e..c06652f 100644 --- a/src/mock_stream.rs +++ b/src/mock_stream.rs @@ -1,4 +1,4 @@ -use std::io::{Read, Result, Write, Error, ErrorKind}; +use std::io::{Error, ErrorKind, Read, Result, Write}; use std::cmp::min; pub struct MockStream {