style(all): Move to rustfmt-nightly

This commit is contained in:
Alexis Mousset
2017-07-18 15:50:24 +02:00
parent 59d47dfdf5
commit 66836b0522
15 changed files with 126 additions and 135 deletions

View File

@@ -1,6 +1,6 @@
extern crate lettre;
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail, SecurityLevel, SmtpTransport};
use lettre::{EmailAddress, EmailTransport, SecurityLevel, SimpleSendableEmail, SmtpTransport};
fn main() {
let email = SimpleSendableEmail::new(

View File

@@ -74,9 +74,7 @@ impl EmailTransport<FileResult> for FileEmailTransport {
email.message(),
);
f.write_all(
serde_json::to_string(&simple_email)?.as_bytes(),
)?;
f.write_all(serde_json::to_string(&simple_email)?.as_bytes())?;
Ok(())
}

View File

@@ -29,15 +29,15 @@ pub mod stub;
#[cfg(feature = "file-transport")]
pub mod file;
pub use smtp::SmtpTransport;
pub use smtp::SecurityLevel;
#[cfg(feature = "file-transport")]
pub use file::FileEmailTransport;
pub use stub::StubEmailTransport;
pub use sendmail::SendmailTransport;
pub use smtp::SecurityLevel;
pub use smtp::SmtpTransport;
use std::fmt;
use std::fmt::{Display, Formatter};
pub use stub::StubEmailTransport;
/// Email address
#[derive(PartialEq, Eq, Clone, Debug)]

View File

@@ -33,12 +33,16 @@ pub struct SendmailTransport {
impl SendmailTransport {
/// Creates a new transport with the default `/usr/sbin/sendmail` command
pub fn new() -> SendmailTransport {
SendmailTransport { command: "/usr/sbin/sendmail".to_string() }
SendmailTransport {
command: "/usr/sbin/sendmail".to_string(),
}
}
/// Creates a new transport to the given sendmail command
pub fn new_with_command<S: Into<String>>(command: S) -> SendmailTransport {
SendmailTransport { command: command.into() }
SendmailTransport {
command: command.into(),
}
}
}
@@ -47,21 +51,21 @@ impl EmailTransport<SendmailResult> for SendmailTransport {
// Spawn the sendmail command
let to_addresses: Vec<String> = email.to().iter().map(|x| x.to_string()).collect();
let mut process = Command::new(&self.command)
.args(
&[
"-i",
"-f",
&email.from().to_string(),
&to_addresses.join(" "),
],
)
.args(&[
"-i",
"-f",
&email.from().to_string(),
&to_addresses.join(" "),
])
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
match process.stdin.as_mut().unwrap().write_all(
email.message().as_bytes(),
) {
match process
.stdin
.as_mut()
.unwrap()
.write_all(email.message().as_bytes()) {
Ok(_) => (),
Err(error) => return Err(From::from(error)),
}

View File

@@ -21,7 +21,8 @@ pub const DEFAULT_ENCRYPTED_MECHANISMS: &'static [Mechanism] =
/// Accepted authentication mecanisms on an encrypted connection
/// Trying LOGIN last as it is deprecated.
#[cfg(not(feature = "crammd5-auth"))]
pub const DEFAULT_ENCRYPTED_MECHANISMS: &'static [Mechanism] = &[Mechanism::Plain, Mechanism::Login];
pub const DEFAULT_ENCRYPTED_MECHANISMS: &'static [Mechanism] =
&[Mechanism::Plain, Mechanism::Login];
/// Accepted authentication mecanisms on an unencrypted connection
#[cfg(feature = "crammd5-auth")]
@@ -212,7 +213,7 @@ mod test {
mechanism
.response(
&credentials,
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg=="),
Some("PDE3ODkzLjEzMjA2NzkxMjNAdGVzc2VyYWN0LnN1c2FtLmluPg==")
)
.unwrap(),
"alice a540ebe4ef2304070bbc3c456c1f64c0"

View File

@@ -156,9 +156,8 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
// TODO
let mut challenges = 10;
let mut response = self.smtp_command(
AuthCommand::new(mechanism, credentials.clone(), None)?,
)?;
let mut response =
self.smtp_command(AuthCommand::new(mechanism, credentials.clone(), None)?)?;
while challenges > 0 && response.has_code(334) {
challenges -= 1;

View File

@@ -27,7 +27,9 @@ impl Display for EhloCommand {
impl EhloCommand {
/// Creates a EHLO command
pub fn new(client_id: ClientId) -> EhloCommand {
EhloCommand { client_id: client_id }
EhloCommand {
client_id: client_id,
}
}
}
@@ -231,11 +233,7 @@ impl Display for AuthCommand {
};
if self.mechanism.supports_initial_response() {
write!(f,
"AUTH {} {}",
self.mechanism,
encoded_response.unwrap(),
)?;
write!(f, "AUTH {} {}", self.mechanism, encoded_response.unwrap(),)?;
} else {
match encoded_response {
Some(response) => f.write_str(&response)?,
@@ -254,10 +252,10 @@ impl AuthCommand {
challenge: Option<String>,
) -> Result<AuthCommand, Error> {
let response = if mechanism.supports_initial_response() || challenge.is_some() {
Some(mechanism.response(
&credentials,
challenge.as_ref().map(String::as_str),
)?)
Some(
mechanism
.response(&credentials, challenge.as_ref().map(String::as_str))?,
)
} else {
None
};
@@ -299,10 +297,10 @@ impl AuthCommand {
debug!("auth decoded challenge: {}", decoded_challenge);
let response = Some(mechanism.response(
&credentials,
Some(decoded_challenge.as_ref()),
)?);
let response = Some(
mechanism
.response(&credentials, Some(decoded_challenge.as_ref()))?,
);
Ok(AuthCommand {
mechanism: mechanism,

View File

@@ -153,9 +153,8 @@ impl ServerInfo {
/// Checks if the server supports an ESMTP feature
pub fn supports_auth_mechanism(&self, mechanism: Mechanism) -> bool {
self.features.contains(
&Extension::Authentication(mechanism),
)
self.features
.contains(&Extension::Authentication(mechanism))
}
}
@@ -350,13 +349,9 @@ mod test {
let mut features2 = HashSet::new();
assert!(features2.insert(Extension::EightBitMime));
assert!(features2.insert(
Extension::Authentication(Mechanism::Plain),
));
assert!(features2.insert(Extension::Authentication(Mechanism::Plain),));
#[cfg(feature = "crammd5-auth")]
assert!(features2.insert(
Extension::Authentication(Mechanism::CramMd5),
));
assert!(features2.insert(Extension::Authentication(Mechanism::CramMd5),));
let server_info2 = ServerInfo {
name: "me".to_string(),

View File

@@ -29,7 +29,8 @@
//!
//! // Open a local connection on port 25
//! let mut mailer =
//! SmtpTransport::builder_localhost().unwrap().security_level(SecurityLevel::Opportunistic).build();
//! SmtpTransport::builder_localhost().unwrap()
//! .security_level(SecurityLevel::Opportunistic).build();
//! // Send the email
//! let result = mailer.send(email);
//!
@@ -59,7 +60,9 @@
//! // Add credentials for authentication
//! .credentials(Credentials::new("username".to_string(), "password".to_string()))
//! // Specify a TLS security level. You can also specify an TlsConnector with
//! // .tls_connector(TlsConnector::builder().unwrap().supported_protocols(vec![Protocol::Tlsv12]).build().unwrap())
//! // .tls_connector(TlsConnector::builder().unwrap()
//! // .supported_protocols(&vec![Protocol::Tlsv12])
//! // .build().unwrap())
//! .security_level(SecurityLevel::AlwaysEncrypt)
//! // Enable SMTPUTF8 if the server supports it
//! .smtp_utf8(true)
@@ -95,8 +98,12 @@
//! let mut email_client: Client<NetworkStream> = Client::new();
//! let _ = email_client.connect(&("localhost", SMTP_PORT), None);
//! let _ = email_client.smtp_command(EhloCommand::new(ClientId::new("my_hostname".to_string())));
//! let _ = email_client.smtp_command(MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![]));
//! let _ = email_client.smtp_command(RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![]));
//! let _ = email_client.smtp_command(
//! MailCommand::new(Some(EmailAddress::new("user@example.com".to_string())), vec![])
//! );
//! let _ = email_client.smtp_command(
//! RcptCommand::new(EmailAddress::new("user@example.org".to_string()), vec![])
//! );
//! let _ = email_client.smtp_command(DataCommand);
//! let _ = email_client.message("Test email");
//! let _ = email_client.smtp_command(QuitCommand);
@@ -341,7 +348,7 @@ impl SmtpTransport {
pub fn builder<A: ToSocketAddrs>(addr: A) -> Result<SmtpTransportBuilder, Error> {
SmtpTransportBuilder::new(addr)
}
/// Creates a new local SMTP client to port 25
/// Creates a new local SMTP client to port 25
pub fn builder_localhost() -> Result<SmtpTransportBuilder, Error> {
SmtpTransportBuilder::new(("localhost", SMTP_PORT))
}
@@ -381,7 +388,7 @@ impl SmtpTransport {
let ehlo_response = try_smtp!(
self.client.smtp_command(EhloCommand::new(
ClientId::new(self.client_info.hello_name.to_string()),
)),
),),
self
);
@@ -425,9 +432,10 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
match (
&self.client_info.security_level,
self.server_info.as_ref().unwrap().supports_feature(
Extension::StartTls,
),
self.server_info
.as_ref()
.unwrap()
.supports_feature(Extension::StartTls),
) {
(&SecurityLevel::AlwaysEncrypt, false) => {
return Err(From::from("Could not encrypt connection, aborting"))
@@ -438,9 +446,8 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
(_, true) => {
try_smtp!(self.client.smtp_command(StarttlsCommand), self);
try_smtp!(
self.client.upgrade_tls_stream(
&self.client_info.tls_connector,
),
self.client
.upgrade_tls_stream(&self.client_info.tls_connector,),
self
);
@@ -467,16 +474,15 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
};
for mechanism in accepted_mechanisms {
if self.server_info.as_ref().unwrap().supports_auth_mechanism(
mechanism,
)
if self.server_info
.as_ref()
.unwrap()
.supports_auth_mechanism(mechanism)
{
found = true;
try_smtp!(
self.client.auth(
mechanism,
self.client_info.credentials.as_ref().unwrap(),
),
self.client
.auth(mechanism, self.client_info.credentials.as_ref().unwrap(),),
self
);
break;
@@ -492,25 +498,25 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
// Mail
let mut mail_options = vec![];
if self.server_info.as_ref().unwrap().supports_feature(
Extension::EightBitMime,
)
if self.server_info
.as_ref()
.unwrap()
.supports_feature(Extension::EightBitMime)
{
mail_options.push(MailParameter::Body(MailBodyParameter::EightBitMime));
}
if self.server_info.as_ref().unwrap().supports_feature(
Extension::SmtpUtfEight,
)
if self.server_info
.as_ref()
.unwrap()
.supports_feature(Extension::SmtpUtfEight)
{
mail_options.push(MailParameter::SmtpUtfEight);
}
try_smtp!(
self.client.smtp_command(MailCommand::new(
Some(email.from().clone()),
mail_options,
)),
self.client
.smtp_command(MailCommand::new(Some(email.from().clone()), mail_options,),),
self
);
@@ -520,9 +526,8 @@ impl EmailTransport<SmtpResult> for SmtpTransport {
// Recipient
for to_address in &email.to() {
try_smtp!(
self.client.smtp_command(
RcptCommand::new(to_address.clone(), vec![]),
),
self.client
.smtp_command(RcptCommand::new(to_address.clone(), vec![]),),
self
);
// Log the rcpt command

View File

@@ -209,7 +209,7 @@ impl ResponseParser {
if code.to_string() != line[0..3] {
return Err(Error::ResponseParsing(
"Response code has changed during a \
reponse",
reponse",
));
}
}
@@ -231,7 +231,7 @@ impl ResponseParser {
None => {
Err(Error::ResponseParsing(
"Incomplete response, could not read response \
code",
code",
))
}
}
@@ -274,9 +274,9 @@ impl Response {
/// Returns only the first word of the message if possible
pub fn first_word(&self) -> Option<&str> {
self.message.get(0).and_then(
|line| line.split_whitespace().next(),
)
self.message
.get(0)
.and_then(|line| line.split_whitespace().next())
}
/// Returns only the line of the message if possible

View File

@@ -39,8 +39,7 @@ mod tests {
("bjørn", "bjørn"),
("Ø+= ❤️‰", "Ø+2B+3D+20❤"),
("+", "+2B"),
]
{
] {
assert_eq!(format!("{}", XText(input)), expect);
}
}

View File

@@ -34,7 +34,7 @@ mod test {
assert_eq!(
buffer,
"{\"to\":[\"root@localhost\"],\"from\":\"user@localhost\",\
\"message_id\":\"file_id\",\"message\":\"Hello file\"}"
\"message_id\":\"file_id\",\"message\":\"Hello file\"}"
);
remove_file(file).unwrap();

View File

@@ -1,7 +1,7 @@
extern crate lettre;
extern crate lettre_email;
use lettre::{SmtpTransport, EmailTransport};
use lettre::{EmailTransport, SmtpTransport};
use lettre_email::email::EmailBuilder;
fn main() {

View File

@@ -330,7 +330,9 @@ impl Display for Email {
impl PartBuilder {
/// Creates a new empty part
pub fn new() -> PartBuilder {
PartBuilder { message: MimeMessage::new_blank_message() }
PartBuilder {
message: MimeMessage::new_blank_message(),
}
}
/// Adds a generic header
@@ -513,9 +515,8 @@ impl EmailBuilder {
/// Adds a `Subject` header
pub fn set_subject<S: Into<String>>(&mut self, subject: S) {
self.message.add_header(
("Subject".to_string(), subject.into()),
);
self.message
.add_header(("Subject".to_string(), subject.into()));
}
/// Adds a `Date` header with the given date
@@ -526,9 +527,8 @@ impl EmailBuilder {
/// Adds a `Date` header with the given date
pub fn set_date(&mut self, date: &Tm) {
self.message.add_header(
("Date", Tm::rfc822z(date).to_string()),
);
self.message
.add_header(("Date", Tm::rfc822z(date).to_string()));
self.date_issued = true;
}
@@ -578,10 +578,8 @@ impl EmailBuilder {
/// Sets the email body to HTML content
pub fn set_html<S: Into<String>>(&mut self, body: S) {
self.message.set_body(body);
self.message.add_header((
"Content-Type",
format!("{}", mime::TEXT_HTML).as_ref(),
));
self.message
.add_header(("Content-Type", format!("{}", mime::TEXT_HTML).as_ref()));
}
/// Sets the email content
@@ -666,9 +664,10 @@ impl EmailBuilder {
// we need to generate the envelope
let mut e = Envelope::new();
// add all receivers in to_header and cc_header
for receiver in self.to_header.iter().chain(self.cc_header.iter()).chain(
self.bcc_header.iter(),
)
for receiver in self.to_header
.iter()
.chain(self.cc_header.iter())
.chain(self.bcc_header.iter())
{
match *receiver {
Address::Mailbox(ref m) => e.add_to(m.address.clone()),
@@ -709,12 +708,8 @@ impl EmailBuilder {
// Add the collected addresses as mailbox-list all at once.
// The unwraps are fine because the conversions for Vec<Address> never errs.
if !self.to_header.is_empty() {
self.message.add_header(
Header::new_with_value(
"To".into(),
self.to_header,
).unwrap(),
);
self.message
.add_header(Header::new_with_value("To".into(), self.to_header).unwrap());
}
if !self.from_header.is_empty() {
self.message.add_header(
@@ -724,12 +719,8 @@ impl EmailBuilder {
return Err(Error::MissingFrom);
}
if !self.cc_header.is_empty() {
self.message.add_header(
Header::new_with_value(
"Cc".into(),
self.cc_header,
).unwrap(),
);
self.message
.add_header(Header::new_with_value("Cc".into(), self.cc_header).unwrap());
}
if !self.reply_to_header.is_empty() {
self.message.add_header(
@@ -738,10 +729,8 @@ impl EmailBuilder {
}
if !self.date_issued {
self.message.add_header((
"Date",
Tm::rfc822z(&now()).to_string().as_ref(),
));
self.message
.add_header(("Date", Tm::rfc822z(&now()).to_string().as_ref()));
}
self.message.add_header(("MIME-Version", "1.0"));
@@ -751,8 +740,7 @@ impl EmailBuilder {
if let Ok(header) = Header::new_with_value(
"Message-ID".to_string(),
format!("<{}.lettre@localhost>", message_id),
)
{
) {
self.message.add_header(header)
}
@@ -766,7 +754,11 @@ impl EmailBuilder {
impl SendableEmail for Email {
fn to(&self) -> Vec<EmailAddress> {
self.envelope.to.iter().map(|x| EmailAddress::new(x.clone())).collect()
self.envelope
.to
.iter()
.map(|x| EmailAddress::new(x.clone()))
.collect()
}
fn from(&self) -> EmailAddress {
@@ -838,10 +830,10 @@ mod test {
format!("{}", email),
format!(
"Subject: Hello\r\nContent-Type: text/plain; \
charset=utf-8\r\nX-test: value\r\nTo: <user@localhost>\r\nFrom: \
<user@localhost>\r\nCc: \"Alias\" <cc@localhost>\r\nReply-To: \
<reply@localhost>\r\nDate: {}\r\nMIME-Version: 1.0\r\nMessage-ID: \
<{}.lettre@localhost>\r\n\r\nHello World!\r\n",
charset=utf-8\r\nX-test: value\r\nTo: <user@localhost>\r\nFrom: \
<user@localhost>\r\nCc: \"Alias\" <cc@localhost>\r\nReply-To: \
<reply@localhost>\r\nDate: {}\r\nMIME-Version: 1.0\r\nMessage-ID: \
<{}.lettre@localhost>\r\n\r\nHello World!\r\n",
date_now.rfc822z(),
email.message_id()
)
@@ -869,8 +861,7 @@ mod test {
);
email.message.headers.insert(
Header::new_with_value("To".to_string(), "to@example.com".to_string())
.unwrap(),
Header::new_with_value("To".to_string(), "to@example.com".to_string()).unwrap(),
);
email.message.body = "body".to_string();
@@ -902,9 +893,9 @@ mod test {
format!("{}", email),
format!(
"Date: {}\r\nSubject: Invitation\r\nSender: \
<dieter@example.com>\r\nTo: <anna@example.com>\r\nFrom: \
<dieter@example.com>, <joachim@example.com>\r\nMIME-Version: \
1.0\r\nMessage-ID: <{}.lettre@localhost>\r\n\r\nWe invite you!\r\n",
<dieter@example.com>\r\nTo: <anna@example.com>\r\nFrom: \
<dieter@example.com>, <joachim@example.com>\r\nMIME-Version: \
1.0\r\nMessage-ID: <{}.lettre@localhost>\r\n\r\nWe invite you!\r\n",
date_now.rfc822z(),
email.message_id()
)
@@ -933,10 +924,10 @@ mod test {
format!("{}", email),
format!(
"Date: {}\r\nSubject: Hello\r\nX-test: value\r\nSender: \
<sender@localhost>\r\nTo: <user@localhost>\r\nFrom: \
<user@localhost>\r\nCc: \"Alias\" <cc@localhost>\r\nReply-To: \
<reply@localhost>\r\nMIME-Version: 1.0\r\nMessage-ID: \
<{}.lettre@localhost>\r\n\r\nHello World!\r\n",
<sender@localhost>\r\nTo: <user@localhost>\r\nFrom: \
<user@localhost>\r\nCc: \"Alias\" <cc@localhost>\r\nReply-To: \
<reply@localhost>\r\nMIME-Version: 1.0\r\nMessage-ID: \
<{}.lettre@localhost>\r\n\r\nHello World!\r\n",
date_now.rfc822z(),
email.message_id()
)

View File

@@ -1,2 +1,3 @@
write_mode = "Overwrite"
reorder_imports = true
reorder_imported_names = true