From a6f45b3c15ccbf1a77abf2f48b1ced892369204c Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sat, 14 Mar 2015 17:30:57 +0100 Subject: [PATCH] .as_slice() -> & in function calls --- src/client/authentication.rs | 2 +- src/client/mod.rs | 22 +++++++++++----------- src/extension.rs | 2 +- src/mailer/address.rs | 2 +- src/mailer/mod.rs | 2 +- src/sender/mod.rs | 16 +++++++--------- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/client/authentication.rs b/src/client/authentication.rs index 9a070ce..c13a217 100644 --- a/src/client/authentication.rs +++ b/src/client/authentication.rs @@ -28,7 +28,7 @@ pub fn cram_md5(username: &str, password: &str, encoded_challenge: &str) -> Stri let challenge = encoded_challenge.from_base64().unwrap(); let mut hmac = Hmac::new(Md5::new(), password.as_bytes()); - hmac.input(challenge.as_slice()); + hmac.input(&challenge); format!("{} {}", username, hmac.result().code().to_hex()).as_bytes().to_base64(base64::STANDARD) } diff --git a/src/client/mod.rs b/src/client/mod.rs index 89381fe..2c1a401 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -102,25 +102,25 @@ impl Client { /// Send a HELO command and fills `server_info` pub fn helo(&mut self, hostname: &str) -> SmtpResult { - self.command(format!("HELO {}", hostname).as_slice()) + self.command(&format!("HELO {}", hostname)) } /// Sends a EHLO command and fills `server_info` pub fn ehlo(&mut self, hostname: &str) -> SmtpResult { - self.command(format!("EHLO {}", hostname).as_slice()) + self.command(&format!("EHLO {}", hostname)) } /// Sends a MAIL command pub fn mail(&mut self, address: &str, options: Option<&str>) -> SmtpResult { match options { - Some(ref options) => self.command(format!("MAIL FROM:<{}> {}", address, options).as_slice()), - None => self.command(format!("MAIL FROM:<{}>", address).as_slice()), + Some(ref options) => self.command(&format!("MAIL FROM:<{}> {}", address, options)), + None => self.command(&format!("MAIL FROM:<{}>", address)), } } /// Sends a RCPT command pub fn rcpt(&mut self, address: &str) -> SmtpResult { - self.command(format!("RCPT TO:<{}>", address).as_slice()) + self.command(&format!("RCPT TO:<{}>", address)) } /// Sends a DATA command @@ -141,19 +141,19 @@ impl Client { /// Sends a HELP command pub fn help(&mut self, argument: Option<&str>) -> SmtpResult { match argument { - Some(ref argument) => self.command(format!("HELP {}", argument).as_slice()), + Some(ref argument) => self.command(&format!("HELP {}", argument)), None => self.command("HELP"), } } /// Sends a VRFY command pub fn vrfy(&mut self, address: &str) -> SmtpResult { - self.command(format!("VRFY {}", address).as_slice()) + self.command(&format!("VRFY {}", address)) } /// Sends a EXPN command pub fn expn(&mut self, address: &str) -> SmtpResult { - self.command(format!("EXPN {}", address).as_slice()) + self.command(&format!("EXPN {}", address)) } /// Sends a RSET command @@ -163,18 +163,18 @@ impl Client { /// Sends an AUTH command with PLAIN mecanism pub fn auth_plain(&mut self, username: &str, password: &str) -> SmtpResult { - self.command(format!("AUTH PLAIN {}", plain(username, password)).as_slice()) + self.command(&format!("AUTH PLAIN {}", plain(username, password))) } /// Sends an AUTH command with CRAM-MD5 mecanism pub fn auth_cram_md5(&mut self, username: &str, password: &str) -> SmtpResult { let encoded_challenge = try!(self.command("AUTH CRAM-MD5")).first_word().expect("No challenge"); - self.command(format!("AUTH CRAM-MD5 {}", cram_md5(username, password, encoded_challenge.as_slice())).as_slice()) + self.command(&format!("AUTH CRAM-MD5 {}", cram_md5(username, password, &encoded_challenge))) } /// Sends the message content and close pub fn message(&mut self, message_content: &str) -> SmtpResult { - self.send_server(escape_dot(message_content).as_slice(), MESSAGE_ENDING) + self.send_server(&escape_dot(message_content), MESSAGE_ENDING) } /// Sends a string to the server and gets the response diff --git a/src/extension.rs b/src/extension.rs index 84db303..86e50ef 100644 --- a/src/extension.rs +++ b/src/extension.rs @@ -67,7 +67,7 @@ impl Extension { let mut esmtp_features: Vec = Vec::new(); for line in response.message() { - if let Ok(keywords) = Extension::from_str(line.as_slice()) { + if let Ok(keywords) = Extension::from_str(&line) { esmtp_features.push_all(&keywords); }; } diff --git a/src/mailer/address.rs b/src/mailer/address.rs index d5b8311..8518564 100644 --- a/src/mailer/address.rs +++ b/src/mailer/address.rs @@ -50,7 +50,7 @@ pub struct Address { impl Display for Address { fn fmt(&self, f: &mut Formatter) -> Result { write! (f, "{}", match self.alias { - Some(ref alias_string) => format!("{}{}<{}>", alias_string, SP, self.address.as_slice()), + Some(ref alias_string) => format!("{}{}<{}>", alias_string, SP, &self.address), None => self.address.clone(), }) } diff --git a/src/mailer/mod.rs b/src/mailer/mod.rs index 299f883..a5489a1 100644 --- a/src/mailer/mod.rs +++ b/src/mailer/mod.rs @@ -47,7 +47,7 @@ impl Display for Email { fn fmt(&self, f: &mut Formatter) -> Result { let mut formatted_headers = String::new(); for header in self.headers.iter() { - formatted_headers.push_str(format! ("{}", header) .as_slice()); + formatted_headers.push_str(&format! ("{}", header)); formatted_headers.push_str(CRLF); } write! (f, "{}{}{}", formatted_headers, CRLF, self.body) diff --git a/src/sender/mod.rs b/src/sender/mod.rs index 64d9c79..4f14d90 100644 --- a/src/sender/mod.rs +++ b/src/sender/mod.rs @@ -181,7 +181,7 @@ impl Sender { info!("connection established to {}", self.client_info.server_addr); // Extended Hello or Hello if needed - match self.client.ehlo(self.client_info.hello_name.as_slice()) { + match self.client.ehlo(&self.client_info.hello_name) { Ok(response) => {self.server_info = Some( ServerInfo{ name: response.first_word().expect("Server announced no hostname"), @@ -190,7 +190,7 @@ impl Sender { }, Err(error) => match error { SmtpError::PermanentError(ref response) if response.has_code(550) => { - match self.client.helo(self.client_info.hello_name.as_slice()) { + match self.client.helo(&self.client_info.hello_name) { Ok(response) => {self.server_info = Some( ServerInfo{ name: response.first_word().expect("Server announced no hostname"), @@ -217,12 +217,10 @@ impl Sender { let (username, password) = self.client_info.credentials.clone().unwrap(); if self.server_info.as_ref().unwrap().supports_feature(Extension::CramMd5Authentication) { - let result = self.client.auth_cram_md5(username.as_slice(), - password.as_slice()); + let result = self.client.auth_cram_md5(&username, &password); try_smtp!(result, self); } else if self.server_info.as_ref().unwrap().supports_feature(Extension::PlainAuthentication) { - let result = self.client.auth_plain(username.as_slice(), - password.as_slice()); + let result = self.client.auth_plain(&username, &password); try_smtp!(result, self); } else { debug!("No supported authentication mecanisms available"); @@ -243,14 +241,14 @@ impl Sender { false => None, }; - try_smtp!(self.client.mail(from_address.as_slice(), mail_options), self); + try_smtp!(self.client.mail(&from_address, mail_options), self); // Log the mail command info!("{}: from=<{}>", current_message, from_address); // Recipient for to_address in to_addresses.iter() { - try_smtp!(self.client.rcpt(to_address.as_slice()), self); + try_smtp!(self.client.rcpt(&to_address), self); // Log the rcpt command info!("{}: to=<{}>", current_message, to_address); } @@ -259,7 +257,7 @@ impl Sender { try_smtp!(self.client.data(), self); // Message content - let result = self.client.message(message.as_slice()); + let result = self.client.message(&message); if result.is_ok() { // Increment the connection reuse counter