.as_slice() -> & in function calls
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
+11
-11
@@ -102,25 +102,25 @@ impl<S: Connecter + Write + Read = TcpStream> Client<S> {
|
||||
|
||||
/// 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<S: Connecter + Write + Read = TcpStream> Client<S> {
|
||||
/// 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<S: Connecter + Write + Read = TcpStream> Client<S> {
|
||||
|
||||
/// 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
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ impl Extension {
|
||||
let mut esmtp_features: Vec<Extension> = 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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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(),
|
||||
})
|
||||
}
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
+7
-9
@@ -181,7 +181,7 @@ impl<S: Connecter + Write + Read = TcpStream> Sender<S> {
|
||||
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<S: Connecter + Write + Read = TcpStream> Sender<S> {
|
||||
},
|
||||
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<S: Connecter + Write + Read = TcpStream> Sender<S> {
|
||||
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<S: Connecter + Write + Read = TcpStream> Sender<S> {
|
||||
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<S: Connecter + Write + Read = TcpStream> Sender<S> {
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user