diff --git a/examples/basic.rs b/examples/basic.rs index b952422..6949bbb 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,8 +1,8 @@ extern crate imap; extern crate native_tls; -use native_tls::TlsConnector; use imap::client::Client; +use native_tls::TlsConnector; // To connect to the gmail IMAP server with this you will need to allow unsecure apps access. // See: https://support.google.com/accounts/answer/6010255?hl=en diff --git a/examples/gmail_oauth2.rs b/examples/gmail_oauth2.rs index 891e7cb..30a2356 100644 --- a/examples/gmail_oauth2.rs +++ b/examples/gmail_oauth2.rs @@ -2,10 +2,10 @@ extern crate base64; extern crate imap; extern crate native_tls; -use native_tls::TlsConnector; use base64::encode; -use imap::client::Client; use imap::authenticator::Authenticator; +use imap::client::Client; +use native_tls::TlsConnector; struct GmailOAuth2 { user: String, @@ -18,8 +18,7 @@ impl Authenticator for GmailOAuth2 { encode( format!( "user={}\x01auth=Bearer {}\x01\x01", - self.user, - self.access_token + self.user, self.access_token ).as_bytes(), ) } diff --git a/src/client.rs b/src/client.rs index 7f164fd..091e004 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,15 +1,15 @@ -use std::net::{TcpStream, ToSocketAddrs}; -use native_tls::{TlsConnector, TlsStream}; -use std::io::{self, Read, Write}; -use std::time::Duration; use bufstream::BufStream; +use native_tls::{TlsConnector, TlsStream}; use nom::IResult; +use std::io::{self, Read, Write}; +use std::net::{TcpStream, ToSocketAddrs}; +use std::time::Duration; -use super::types::*; use super::authenticator::Authenticator; +use super::error::{Error, ParseError, Result, ValidateError}; use super::parse::{parse_authenticate_response, parse_capabilities, parse_fetches, parse_mailbox, parse_names}; -use super::error::{Error, ParseError, Result, ValidateError}; +use super::types::*; static TAG_PREFIX: &'static str = "a"; const INITIAL_TAG: u32 = 0; @@ -17,9 +17,9 @@ const CR: u8 = 0x0d; const LF: u8 = 0x0a; macro_rules! quote { - ($x: expr) => ( + ($x:expr) => { format!("\"{}\"", $x.replace(r"\", r"\\").replace("\"", "\\\"")) - ) + }; } fn validate_str(value: &str) -> Result { @@ -447,9 +447,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 mut v = Vec::new(); try!(self.readline(&mut v)); if !v.starts_with(b"+") { @@ -538,14 +536,14 @@ impl Client { use imap_proto::Status; match status { Status::Bad => { - break Err(Error::BadResponse( - expl.unwrap_or("no explanation given".to_string()), - )) + break Err(Error::BadResponse(expl.unwrap_or( + "no explanation given".to_string(), + ))) } Status::No => { - break Err(Error::NoResponse( - expl.unwrap_or("no explanation given".to_string()), - )) + break Err(Error::NoResponse(expl.unwrap_or( + "no explanation given".to_string(), + ))) } _ => break Err(Error::Parse(ParseError::Invalid(data.split_off(0)))), } @@ -597,9 +595,9 @@ impl Client { #[cfg(test)] mod tests { - use super::*; - use super::super::mock_stream::MockStream; use super::super::error::Result; + use super::super::mock_stream::MockStream; + use super::*; #[test] fn read_response() { @@ -610,7 +608,6 @@ mod tests { assert_eq!(Vec::::new(), actual_response); } - #[test] fn fetch_body() { let response = "a0 OK Logged in.\r\n\ @@ -622,7 +619,6 @@ mod tests { client.read_response().unwrap(); } - #[test] fn read_greeting() { let greeting = "* OK Dovecot ready.\r\n"; diff --git a/src/error.rs b/src/error.rs index 4420355..602e903 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,14 +1,14 @@ -use std::io::Error as IoError; -use std::result; -use std::fmt; use std::error::Error as StdError; +use std::fmt; +use std::io::Error as IoError; use std::net::TcpStream; +use std::result; use std::string::FromUtf8Error; -use imap_proto::Response; -use native_tls::HandshakeError as TlsHandshakeError; -use native_tls::Error as TlsError; use bufstream::IntoInnerError as BufError; +use imap_proto::Response; +use native_tls::Error as TlsError; +use native_tls::HandshakeError as TlsHandshakeError; pub type Result = result::Result; diff --git a/src/lib.rs b/src/lib.rs index 46a6657..85e622d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ extern crate native_tls; extern crate nom; extern crate regex; -mod types; mod parse; +mod types; pub mod authenticator; pub mod client; diff --git a/src/mock_stream.rs b/src/mock_stream.rs index fdda020..f1286f9 100644 --- a/src/mock_stream.rs +++ b/src/mock_stream.rs @@ -1,5 +1,5 @@ -use std::io::{Error, ErrorKind, Read, Result, Write}; use std::cmp::min; +use std::io::{Error, ErrorKind, Read, Result, Write}; #[derive(Clone, Debug, Eq, PartialEq, Hash)] pub struct MockStream { diff --git a/src/parse.rs b/src/parse.rs index d511fe6..c894835 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -1,9 +1,9 @@ -use regex::Regex; -use nom::IResult; use imap_proto::{self, Response}; +use nom::IResult; +use regex::Regex; -use super::types::*; use super::error::{Error, ParseError, Result}; +use super::types::*; pub fn parse_authenticate_response(line: String) -> Result { let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap(); @@ -59,8 +59,8 @@ pub fn parse_names(lines: Vec) -> ZeroCopyResult> { flags, delimiter, name, - }) | - Response::MailboxData(MailboxDatum::SubList { + }) + | Response::MailboxData(MailboxDatum::SubList { flags, delimiter, name, diff --git a/src/types/capabilities.rs b/src/types/capabilities.rs index a42c7e7..41da7db 100644 --- a/src/types/capabilities.rs +++ b/src/types/capabilities.rs @@ -4,8 +4,8 @@ use std::collections::HashSet; use std::collections::hash_set::Iter; pub struct Capabilities(pub(crate) HashSet<&'static str>); -use std::hash::Hash; use std::borrow::Borrow; +use std::hash::Hash; impl Capabilities { pub fn has(&self, s: &S) -> bool where