diff --git a/src/client.rs b/src/client.rs index 71c98365..43f0c5da 100644 --- a/src/client.rs +++ b/src/client.rs @@ -26,10 +26,10 @@ macro_rules! quote { fn validate_str(value: &str) -> Result { let quoted = quote!(value); - if let Some(_) = quoted.find("\n") { + if quoted.find('\n').is_some() { return Err(Error::Validate(ValidateError('\n'))); } - if let Some(_) = quoted.find("\r") { + if quoted.find('\r').is_some() { return Err(Error::Validate(ValidateError('\r'))); } Ok(quoted) @@ -126,7 +126,7 @@ pub trait SetReadTimeout { impl<'a, T: Read + Write + 'a> IdleHandle<'a, T> { fn new(session: &'a mut Session) -> Result { let mut h = IdleHandle { - session: session, + session, keepalive: Duration::from_secs(29 * 60), done: false, }; @@ -239,7 +239,7 @@ impl<'a, T: Read + Write + 'a> Drop for IdleHandle<'a, T> { impl<'a> SetReadTimeout for TcpStream { fn set_read_timeout(&mut self, timeout: Option) -> Result<()> { - TcpStream::set_read_timeout(self, timeout).map_err(|e| Error::Io(e)) + TcpStream::set_read_timeout(self, timeout).map_err(Error::Io) } } @@ -247,7 +247,7 @@ impl<'a> SetReadTimeout for TlsStream { fn set_read_timeout(&mut self, timeout: Option) -> Result<()> { self.get_ref() .set_read_timeout(timeout) - .map_err(|e| Error::Io(e)) + .map_err(Error::Io) } } @@ -368,13 +368,13 @@ impl Client { authenticator: A, ) -> ::std::result::Result, (Error, Client)> { ok_or_unauth_client_err!(self.run_command(&format!("AUTHENTICATE {}", auth_type)), self); - self.do_auth_handshake(authenticator) + self.do_auth_handshake(&authenticator) } /// This func does the handshake process once the authenticate command is made. fn do_auth_handshake( mut self, - authenticator: A + authenticator: &A ) -> ::std::result::Result, (Error, Client)> { // TODO Clean up this code loop { @@ -466,7 +466,7 @@ impl Session { /// server responses in RFC 3501](https://tools.ietf.org/html/rfc3501#section-7). pub fn fetch(&mut self, sequence_set: &str, query: &str) -> ZeroCopyResult> { self.run_command_and_read_response(&format!("FETCH {} {}", sequence_set, query)) - .and_then(|lines| parse_fetches(lines)) + .and_then(parse_fetches) } /// Fetch retreives data associated with a set of messages by UID in the mailbox. @@ -476,7 +476,7 @@ impl Session { /// server responses in RFC 3501](https://tools.ietf.org/html/rfc3501#section-7). pub fn uid_fetch(&mut self, uid_set: &str, query: &str) -> ZeroCopyResult> { self.run_command_and_read_response(&format!("UID FETCH {} {}", uid_set, query)) - .and_then(|lines| parse_fetches(lines)) + .and_then(parse_fetches) } /// Noop always succeeds, and it does nothing. @@ -522,8 +522,8 @@ impl Session { /// Capability requests a listing of capabilities that the server supports. pub fn capabilities(&mut self) -> ZeroCopyResult { - self.run_command_and_read_response(&format!("CAPABILITY")) - .and_then(|lines| parse_capabilities(lines)) + self.run_command_and_read_response("CAPABILITY") + .and_then(parse_capabilities) } /// Expunge permanently removes all messages that have the \Deleted flag set from the currently @@ -546,12 +546,12 @@ impl Session { /// Store alters data associated with a message in the mailbox. pub fn store(&mut self, sequence_set: &str, query: &str) -> ZeroCopyResult> { self.run_command_and_read_response(&format!("STORE {} {}", sequence_set, query)) - .and_then(|lines| parse_fetches(lines)) + .and_then(parse_fetches) } pub fn uid_store(&mut self, uid_set: &str, query: &str) -> ZeroCopyResult> { self.run_command_and_read_response(&format!("UID STORE {} {}", uid_set, query)) - .and_then(|lines| parse_fetches(lines)) + .and_then(parse_fetches) } /// Copy copies the specified message to the end of the specified destination mailbox. @@ -574,7 +574,7 @@ impl Session { "LIST {} {}", quote!(reference_name), mailbox_search_pattern - )).and_then(|lines| parse_names(lines)) + )).and_then(parse_names) } /// The LSUB command returns a subset of names from the set of names @@ -588,7 +588,7 @@ impl Session { "LSUB {} {}", quote!(reference_name), mailbox_search_pattern - )).and_then(|lines| parse_names(lines)) + )).and_then(parse_names) } /// The STATUS command requests the status of the indicated mailbox. @@ -623,7 +623,7 @@ impl Session { // these are only here because they are public interface, the rest is in `Connection` /// Runs a command and checks if it returns OK. pub fn run_command_and_check_ok(&mut self, command: &str) -> Result<()> { - self.run_command_and_read_response(command).map(|_| (())) + self.run_command_and_read_response(command).map(|_| ()) } /// Runs any command passed to it. @@ -654,7 +654,7 @@ impl Connection { } fn run_command(&mut self, untagged_command: &str) -> Result<()> { - let command = self.create_command(untagged_command.to_string()); + let command = self.create_command(untagged_command); self.write_line(command.into_bytes().as_slice()) } @@ -725,12 +725,12 @@ impl Connection { match status { Status::Bad => { break Err(Error::BadResponse( - expl.unwrap_or("no explanation given".to_string()), + expl.unwrap_or_else(|| "no explanation given".to_string()), )) } Status::No => { break Err(Error::NoResponse( - expl.unwrap_or("no explanation given".to_string()), + expl.unwrap_or_else(|| "no explanation given".to_string()), )) } _ => break Err(Error::Parse(ParseError::Invalid(data.split_off(0)))), @@ -758,10 +758,9 @@ impl Connection { Ok(read) } - fn create_command(&mut self, command: String) -> String { + fn create_command(&mut self, command: &str) -> String { self.tag += 1; - let command = format!("{}{} {}", TAG_PREFIX, self.tag, command); - return command; + format!("{}{} {}", TAG_PREFIX, self.tag, command) } fn write_line(&mut self, buf: &[u8]) -> Result<()> { @@ -858,14 +857,14 @@ mod tests { let mut imap_stream = Client::new(mock_stream); let expected_command = format!("a1 {}", base_command); - let command = imap_stream.create_command(String::from(base_command)); + let command = imap_stream.create_command(&base_command); assert!( command == expected_command, "expected command doesn't equal actual command" ); let expected_command2 = format!("a2 {}", base_command); - let command2 = imap_stream.create_command(String::from(base_command)); + let command2 = imap_stream.create_command(&base_command); assert!( command2 == expected_command2, "expected command doesn't equal actual command" diff --git a/src/parse.rs b/src/parse.rs index 8e68dcea..069fe553 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -8,7 +8,7 @@ use super::types::*; pub fn parse_authenticate_response(line: String) -> Result { let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap(); - for cap in authenticate_regex.captures_iter(line.as_str()) { + if let Some(cap) = authenticate_regex.captures_iter(line.as_str()).next() { let data = cap.get(1).map(|x| x.as_str()).unwrap_or(""); return Ok(String::from(data)); } @@ -112,9 +112,7 @@ pub fn parse_fetches(lines: Vec) -> ZeroCopyResult> { AttributeValue::Rfc822(rfc) => fetch.rfc822 = rfc, AttributeValue::Rfc822Header(rfc) => fetch.rfc822_header = rfc, AttributeValue::BodySection { - section: _, - index: _, - data, + data, .. } => fetch.body = data, _ => {} } diff --git a/src/types/capabilities.rs b/src/types/capabilities.rs index 6221f1e0..6e805757 100644 --- a/src/types/capabilities.rs +++ b/src/types/capabilities.rs @@ -15,7 +15,7 @@ impl Capabilities { self.0.contains(s) } - pub fn iter<'a>(&'a self) -> Iter<'a, &'a str> { + pub fn iter(&self) -> Iter<&str> { self.0.iter() } diff --git a/src/types/fetch.rs b/src/types/fetch.rs index e04514a1..4db4d9ab 100644 --- a/src/types/fetch.rs +++ b/src/types/fetch.rs @@ -11,19 +11,19 @@ pub struct Fetch { } impl Fetch { - pub fn flags<'a>(&'a self) -> &'a [&'a str] { + pub fn flags(&self) -> &[&str] { &self.flags[..] } - pub fn rfc822_header<'a>(&'a self) -> Option<&'a [u8]> { + pub fn rfc822_header(&self) -> Option<&[u8]> { self.rfc822_header } - pub fn rfc822<'a>(&'a self) -> Option<&'a [u8]> { + pub fn rfc822(&self) -> Option<&[u8]> { self.rfc822 } - pub fn body<'a>(&'a self) -> Option<&'a [u8]> { + pub fn body(&self) -> Option<&[u8]> { self.body } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 42f89600..058b229c 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -66,9 +66,6 @@ impl PartialEq for ZeroCopy { fn eq(&self, other: &ZeroCopy) -> bool { **self == **other } - fn ne(&self, other: &ZeroCopy) -> bool { - **self != **other - } } impl Eq for ZeroCopy {} diff --git a/src/types/name.rs b/src/types/name.rs index 74c635f2..865d299d 100644 --- a/src/types/name.rs +++ b/src/types/name.rs @@ -8,15 +8,15 @@ pub struct Name { } impl Name { - pub fn attributes<'a>(&'a self) -> &'a [&'a str] { + pub fn attributes(&self) -> &[&str] { &self.attributes[..] } - pub fn delimiter<'a>(&'a self) -> &'a str { + pub fn delimiter(&self) -> &str { self.delimiter } - pub fn name<'a>(&'a self) -> &'a str { + pub fn name(&self) -> &str { self.name } }