Merge pull request #142 from amousset/formatting

style(all): Run last rustfmt
This commit is contained in:
Alexis Mousset
2017-06-14 00:53:45 +02:00
committed by GitHub
9 changed files with 53 additions and 54 deletions

View File

@@ -40,7 +40,7 @@ pub trait EmailTransport<U> {
} }
/// Minimal email structure /// Minimal email structure
#[derive(Debug,Clone)] #[derive(Debug, Clone)]
pub struct SimpleSendableEmail { pub struct SimpleSendableEmail {
/// To /// To
to: Vec<String>, to: Vec<String>,

View File

@@ -25,7 +25,7 @@ use std::process::{Command, Stdio};
pub mod error; pub mod error;
/// Sends an email using the `sendmail` command /// Sends an email using the `sendmail` command
#[derive(Debug,Default)] #[derive(Debug, Default)]
pub struct SendmailTransport { pub struct SendmailTransport {
command: String, command: String,
} }

View File

@@ -10,7 +10,7 @@ use std::fmt;
use std::fmt::{Display, Formatter}; use std::fmt::{Display, Formatter};
/// Represents authentication mechanisms /// Represents authentication mechanisms
#[derive(PartialEq,Eq,Copy,Clone,Hash,Debug)] #[derive(PartialEq, Eq, Copy, Clone, Hash, Debug)]
pub enum Mechanism { pub enum Mechanism {
/// PLAIN authentication mechanism /// PLAIN authentication mechanism
/// RFC 4616: https://tools.ietf.org/html/rfc4616 /// RFC 4616: https://tools.ietf.org/html/rfc4616

View File

@@ -6,7 +6,7 @@ use std::sync::{Arc, Mutex};
pub type MockCursor = Cursor<Vec<u8>>; pub type MockCursor = Cursor<Vec<u8>>;
#[derive(Clone,Debug)] #[derive(Clone, Debug)]
pub struct MockStream { pub struct MockStream {
reader: Arc<Mutex<MockCursor>>, reader: Arc<Mutex<MockCursor>>,
writer: Arc<Mutex<MockCursor>>, writer: Arc<Mutex<MockCursor>>,

View File

@@ -24,11 +24,10 @@ pub mod mock;
#[inline] #[inline]
fn escape_dot(string: &str) -> String { fn escape_dot(string: &str) -> String {
if string.starts_with('.') { if string.starts_with('.') {
format!(".{}", string) format!(".{}", string)
} else { } else {
string.to_string() string.to_string()
} }.replace("\r.", "\r..")
.replace("\r.", "\r..")
.replace("\n.", "\n..") .replace("\n.", "\n..")
} }
@@ -204,12 +203,12 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
if mechanism.supports_initial_response() { if mechanism.supports_initial_response() {
self.command(&format!("AUTH {} {}", self.command(&format!("AUTH {} {}",
mechanism, mechanism,
base64::encode_config(try!(mechanism.response(username, base64::encode_config(try!(mechanism.response(username,
password, password,
None)) None))
.as_bytes(), .as_bytes(),
base64::STANDARD))) base64::STANDARD)))
} else { } else {
let encoded_challenge = match try!(self.command(&format!("AUTH {}", mechanism))) let encoded_challenge = match try!(self.command(&format!("AUTH {}", mechanism)))
.first_word() { .first_word() {
@@ -234,10 +233,11 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
let mut challenge_expected = 3; let mut challenge_expected = 3;
while challenge_expected > 0 { while challenge_expected > 0 {
let response = try!(self.command(&base64::encode_config(&try!(mechanism.response(username, let response =
try!(self.command(&base64::encode_config(&try!(mechanism.response(username,
password, password,
Some(&decoded_challenge))) Some(&decoded_challenge)))
.as_bytes(), .as_bytes(),
base64::STANDARD))); base64::STANDARD)));
if !response.has_code(334) { if !response.has_code(334) {

View File

@@ -9,7 +9,7 @@ use std::fmt::{Display, Formatter};
use std::result::Result; use std::result::Result;
/// Supported ESMTP keywords /// Supported ESMTP keywords
#[derive(PartialEq,Eq,Hash,Clone,Debug)] #[derive(PartialEq, Eq, Hash, Clone, Debug)]
pub enum Extension { pub enum Extension {
/// 8BITMIME keyword /// 8BITMIME keyword
/// ///
@@ -39,7 +39,7 @@ impl Display for Extension {
} }
/// Contains information about an SMTP server /// Contains information about an SMTP server
#[derive(Clone,Debug,Eq,PartialEq)] #[derive(Clone, Debug, Eq, PartialEq)]
pub struct ServerInfo { pub struct ServerInfo {
/// Server name /// Server name
/// ///

View File

@@ -148,7 +148,7 @@ pub const MESSAGE_ENDING: &'static str = "\r\n.\r\n";
pub const NUL: &'static str = "\0"; pub const NUL: &'static str = "\0";
/// TLS security level /// TLS security level
#[derive(PartialEq,Eq,Copy,Clone,Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum SecurityLevel { pub enum SecurityLevel {
/// Use a TLS wrapped connection /// Use a TLS wrapped connection
/// ///
@@ -401,14 +401,13 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
} }
if self.state.connection_reuse_count == 0 { if self.state.connection_reuse_count == 0 {
try!(self.client try!(self.client.connect(
.connect(&self.client_info.server_addr, &self.client_info.server_addr,
match self.client_info.security_level { match self.client_info.security_level {
SecurityLevel::EncryptedWrapper => { SecurityLevel::EncryptedWrapper => Some(&self.client_info.ssl_context),
Some(&self.client_info.ssl_context) _ => None,
} },
_ => None, ));
}));
try!(self.client.set_timeout(self.client_info.timeout)); try!(self.client.set_timeout(self.client_info.timeout));

View File

@@ -9,7 +9,7 @@ use std::result;
use std::str::FromStr; use std::str::FromStr;
/// First digit indicates severity /// First digit indicates severity
#[derive(PartialEq,Eq,Copy,Clone,Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum Severity { pub enum Severity {
/// 2yx /// 2yx
PositiveCompletion, PositiveCompletion,
@@ -46,7 +46,7 @@ impl Display for Severity {
} }
/// Second digit /// Second digit
#[derive(PartialEq,Eq,Copy,Clone,Debug)] #[derive(PartialEq, Eq, Copy, Clone, Debug)]
pub enum Category { pub enum Category {
/// x0z /// x0z
Syntax, Syntax,
@@ -91,7 +91,7 @@ impl Display for Category {
} }
/// Represents a 3 digit SMTP response code /// Represents a 3 digit SMTP response code
#[derive(PartialEq,Eq,Clone,Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct Code { pub struct Code {
/// First digit of the response code /// First digit of the response code
severity: Severity, severity: Severity,
@@ -142,7 +142,7 @@ impl Code {
} }
/// Parses an SMTP response /// Parses an SMTP response
#[derive(PartialEq,Eq,Clone,Debug,Default)] #[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct ResponseParser { pub struct ResponseParser {
/// Response code /// Response code
code: Option<Code>, code: Option<Code>,
@@ -192,7 +192,7 @@ impl ResponseParser {
/// Contains an SMTP reply, with separated code and message /// Contains an SMTP reply, with separated code and message
/// ///
/// The text message is optional, only the code is mandatory /// The text message is optional, only the code is mandatory
#[derive(PartialEq,Eq,Clone,Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct Response { pub struct Response {
/// Response code /// Response code
code: Code, code: Code,
@@ -396,7 +396,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.is_positive()); .is_positive());
assert!(!Response::new(Code { assert!(!Response::new(Code {
severity: "5".parse::<Severity>().unwrap(), severity: "5".parse::<Severity>().unwrap(),
category: "4".parse::<Category>().unwrap(), category: "4".parse::<Category>().unwrap(),
@@ -405,7 +405,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.is_positive()); .is_positive());
} }
#[test] #[test]
@@ -418,7 +418,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.message(), .message(),
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]); "SIZE 42".to_string()]);
@@ -429,7 +429,7 @@ mod test {
detail: 1, detail: 1,
}, },
vec![]) vec![])
.message(), .message(),
empty_message); empty_message);
} }
@@ -443,7 +443,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.severity(), .severity(),
Severity::PositiveCompletion); Severity::PositiveCompletion);
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "5".parse::<Severity>().unwrap(), severity: "5".parse::<Severity>().unwrap(),
@@ -453,7 +453,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.severity(), .severity(),
Severity::PermanentNegativeCompletion); Severity::PermanentNegativeCompletion);
} }
@@ -467,7 +467,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.category(), .category(),
Category::Unspecified4); Category::Unspecified4);
} }
@@ -481,7 +481,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.detail(), .detail(),
1); 1);
} }
@@ -495,7 +495,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.code(), .code(),
"241"); "241");
} }
@@ -509,7 +509,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.has_code(241)); .has_code(241));
assert!(!Response::new(Code { assert!(!Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
category: "4".parse::<Category>().unwrap(), category: "4".parse::<Category>().unwrap(),
@@ -518,7 +518,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.has_code(251)); .has_code(251));
} }
#[test] #[test]
@@ -531,7 +531,7 @@ mod test {
vec!["me".to_string(), vec!["me".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.first_word(), .first_word(),
Some("me".to_string())); Some("me".to_string()));
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
@@ -541,7 +541,7 @@ mod test {
vec!["me mo".to_string(), vec!["me mo".to_string(),
"8BITMIME".to_string(), "8BITMIME".to_string(),
"SIZE 42".to_string()]) "SIZE 42".to_string()])
.first_word(), .first_word(),
Some("me".to_string())); Some("me".to_string()));
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
@@ -549,7 +549,7 @@ mod test {
detail: 1, detail: 1,
}, },
vec![]) vec![])
.first_word(), .first_word(),
None); None);
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
@@ -557,7 +557,7 @@ mod test {
detail: 1, detail: 1,
}, },
vec![" ".to_string()]) vec![" ".to_string()])
.first_word(), .first_word(),
None); None);
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
@@ -565,7 +565,7 @@ mod test {
detail: 1, detail: 1,
}, },
vec![" ".to_string()]) vec![" ".to_string()])
.first_word(), .first_word(),
None); None);
assert_eq!(Response::new(Code { assert_eq!(Response::new(Code {
severity: "2".parse::<Severity>().unwrap(), severity: "2".parse::<Severity>().unwrap(),
@@ -573,7 +573,7 @@ mod test {
detail: 1, detail: 1,
}, },
vec!["".to_string()]) vec!["".to_string()])
.first_word(), .first_word(),
None); None);
} }
} }

View File

@@ -108,7 +108,7 @@ impl IntoEmail for SimpleEmail {
/// Simple representation of an email, useful for some transports /// Simple representation of an email, useful for some transports
#[derive(PartialEq,Eq,Clone,Debug,Default)] #[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct SimpleEmail { pub struct SimpleEmail {
from: Option<Mailbox>, from: Option<Mailbox>,
to: Vec<Mailbox>, to: Vec<Mailbox>,
@@ -236,14 +236,14 @@ impl SimpleEmail {
} }
/// Builds a `MimeMessage` structure /// Builds a `MimeMessage` structure
#[derive(PartialEq,Eq,Clone,Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct PartBuilder { pub struct PartBuilder {
/// Message /// Message
message: MimeMessage, message: MimeMessage,
} }
/// Builds an `Email` structure /// Builds an `Email` structure
#[derive(PartialEq,Eq,Clone,Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct EmailBuilder { pub struct EmailBuilder {
/// Message /// Message
message: PartBuilder, message: PartBuilder,
@@ -266,7 +266,7 @@ pub struct EmailBuilder {
} }
/// Simple email enveloppe representation /// Simple email enveloppe representation
#[derive(PartialEq,Eq,Clone,Debug,Default)] #[derive(PartialEq, Eq, Clone, Debug, Default)]
pub struct Envelope { pub struct Envelope {
/// The envelope recipients' addresses /// The envelope recipients' addresses
pub to: Vec<String>, pub to: Vec<String>,
@@ -303,7 +303,7 @@ impl Envelope {
} }
/// Simple email representation /// Simple email representation
#[derive(PartialEq,Eq,Clone,Debug)] #[derive(PartialEq, Eq, Clone, Debug)]
pub struct Email { pub struct Email {
/// Message /// Message
message: MimeMessage, message: MimeMessage,
@@ -828,7 +828,7 @@ mod test {
.headers .headers
.insert(Header::new_with_value("Message-ID".to_string(), .insert(Header::new_with_value("Message-ID".to_string(),
format!("<{}@rust-smtp>", current_message)) format!("<{}@rust-smtp>", current_message))
.unwrap()); .unwrap());
email email
.message .message