From be50862d55755fcc47938a5dce3b02f929b727ce Mon Sep 17 00:00:00 2001 From: Alexis Mousset Date: Sun, 17 Mar 2019 13:26:14 +0100 Subject: [PATCH] Fix clippy and formatting --- lettre/benches/transport_smtp.rs | 6 +- lettre/examples/smtp.rs | 3 +- lettre/src/lib.rs | 14 ++-- lettre/src/smtp/authentication.rs | 8 +- lettre/src/smtp/client/mod.rs | 4 +- lettre/src/smtp/client/net.rs | 4 +- lettre/src/smtp/commands.rs | 6 +- lettre/src/smtp/error.rs | 2 +- lettre/src/smtp/extension.rs | 26 +++--- lettre/src/smtp/mod.rs | 45 +++++++---- lettre/src/smtp/r2d2.rs | 2 +- lettre/src/smtp/response.rs | 96 +++++++++++++---------- lettre/tests/r2d2_smtp.rs | 5 +- lettre/tests/skeptic.rs | 3 +- lettre/tests/transport_file.rs | 3 +- lettre/tests/transport_sendmail.rs | 3 +- lettre/tests/transport_smtp.rs | 3 +- lettre/tests/transport_stub.rs | 6 +- lettre_email/examples/local.rs | 3 +- lettre_email/src/lib.rs | 57 +++++++++----- lettre_email/tests/build_with_envelope.rs | 12 +-- lettre_email/tests/skeptic.rs | 3 +- 22 files changed, 190 insertions(+), 124 deletions(-) diff --git a/lettre/benches/transport_smtp.rs b/lettre/benches/transport_smtp.rs index 406adfd..748771d 100644 --- a/lettre/benches/transport_smtp.rs +++ b/lettre/benches/transport_smtp.rs @@ -17,7 +17,8 @@ fn bench_simple_send(b: &mut test::Bencher) { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); @@ -37,7 +38,8 @@ fn bench_reuse_send(b: &mut test::Bencher) { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre/examples/smtp.rs b/lettre/examples/smtp.rs index c75a1fa..09ebb47 100644 --- a/lettre/examples/smtp.rs +++ b/lettre/examples/smtp.rs @@ -10,7 +10,8 @@ fn main() { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre/src/lib.rs b/lettre/src/lib.rs index 2630ecb..42d8735 100644 --- a/lettre/src/lib.rs +++ b/lettre/src/lib.rs @@ -5,8 +5,12 @@ #![doc(html_root_url = "https://docs.rs/lettre/0.9.0")] #![deny( - missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, - unstable_features, unused_import_braces + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces )] #[cfg(feature = "smtp-transport")] extern crate base64; @@ -47,23 +51,23 @@ pub mod stub; use error::EmailResult; use error::Error as EmailError; use failure::Error; +use fast_chemail::is_valid_email; #[cfg(feature = "file-transport")] pub use file::FileTransport; #[cfg(feature = "sendmail-transport")] pub use sendmail::SendmailTransport; #[cfg(feature = "smtp-transport")] pub use smtp::client::net::ClientTlsParameters; -#[cfg(feature = "smtp-transport")] -pub use smtp::{ClientSecurity, SmtpClient, SmtpTransport}; #[cfg(all(feature = "smtp-transport", feature = "connection-pool"))] pub use smtp::r2d2::SmtpConnectionManager; +#[cfg(feature = "smtp-transport")] +pub use smtp::{ClientSecurity, SmtpClient, SmtpTransport}; use std::ffi::OsStr; use std::fmt::{self, Display, Formatter}; use std::io; use std::io::Cursor; use std::io::Read; use std::str::FromStr; -use fast_chemail::is_valid_email; /// Email address #[derive(PartialEq, Eq, Clone, Debug)] diff --git a/lettre/src/smtp/authentication.rs b/lettre/src/smtp/authentication.rs index f6b4a93..541bb08 100644 --- a/lettre/src/smtp/authentication.rs +++ b/lettre/src/smtp/authentication.rs @@ -79,8 +79,8 @@ impl Display for Mechanism { impl Mechanism { /// Does the mechanism supports initial response - pub fn supports_initial_response(&self) -> bool { - match *self { + pub fn supports_initial_response(self) -> bool { + match self { Mechanism::Plain | Mechanism::Xoauth2 => true, Mechanism::Login => false, } @@ -89,11 +89,11 @@ impl Mechanism { /// Returns the string to send to the server, using the provided username, password and /// challenge in some cases pub fn response( - &self, + self, credentials: &Credentials, challenge: Option<&str>, ) -> Result { - match *self { + match self { Mechanism::Plain => match challenge { Some(_) => Err(Error::Client("This mechanism does not expect a challenge")), None => Ok(format!( diff --git a/lettre/src/smtp/client/mod.rs b/lettre/src/smtp/client/mod.rs index 0d5035d..d0c759e 100644 --- a/lettre/src/smtp/client/mod.rs +++ b/lettre/src/smtp/client/mod.rs @@ -88,7 +88,7 @@ macro_rules! return_err ( }) ); -#[cfg_attr(feature = "cargo-clippy", allow(new_without_default_derive))] +#[cfg_attr(feature = "cargo-clippy", allow(clippy::new_without_default_derive))] impl InnerClient { /// Creates a new SMTP client /// @@ -165,7 +165,7 @@ impl InnerClient { } /// Checks if the server is connected using the NOOP SMTP command - #[cfg_attr(feature = "cargo-clippy", allow(wrong_self_convention))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::wrong_self_convention))] pub fn is_connected(&mut self) -> bool { self.stream.is_some() && self.command(NoopCommand).is_ok() } diff --git a/lettre/src/smtp/client/net.rs b/lettre/src/smtp/client/net.rs index 773ef78..12d0375 100644 --- a/lettre/src/smtp/client/net.rs +++ b/lettre/src/smtp/client/net.rs @@ -117,7 +117,7 @@ impl Connector for NetworkStream { } } - #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] fn upgrade_tls(&mut self, tls_parameters: &ClientTlsParameters) -> io::Result<()> { *self = match *self { NetworkStream::Tcp(ref mut stream) => match tls_parameters @@ -134,7 +134,7 @@ impl Connector for NetworkStream { Ok(()) } - #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] fn is_encrypted(&self) -> bool { match *self { NetworkStream::Tcp(_) => false, diff --git a/lettre/src/smtp/commands.rs b/lettre/src/smtp/commands.rs index 10aced5..392424b 100644 --- a/lettre/src/smtp/commands.rs +++ b/lettre/src/smtp/commands.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(clippy::write_with_newline))] + //! SMTP commands use base64; @@ -163,6 +165,7 @@ pub struct VrfyCommand { impl Display for VrfyCommand { fn fmt(&self, f: &mut Formatter) -> fmt::Result { + #[cfg_attr(feature = "cargo-clippy", allow(clippy::write_with_newline))] write!(f, "VRFY {}\r\n", self.argument) } } @@ -217,7 +220,8 @@ pub struct AuthCommand { impl Display for AuthCommand { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - let encoded_response = self.response + let encoded_response = self + .response .as_ref() .map(|r| base64::encode_config(r.as_bytes(), base64::STANDARD)); diff --git a/lettre/src/smtp/error.rs b/lettre/src/smtp/error.rs index 01c60f5..0f46679 100644 --- a/lettre/src/smtp/error.rs +++ b/lettre/src/smtp/error.rs @@ -47,7 +47,7 @@ impl Display for Error { } impl StdError for Error { - #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms))] + #[cfg_attr(feature = "cargo-clippy", allow(clippy::match_same_arms))] fn description(&self) -> &str { match *self { // Try to display the first line of the server's response that usually diff --git a/lettre/src/smtp/extension.rs b/lettre/src/smtp/extension.rs index d294c45..e8f2e0d 100644 --- a/lettre/src/smtp/extension.rs +++ b/lettre/src/smtp/extension.rs @@ -134,20 +134,22 @@ impl ServerInfo { "STARTTLS" => { features.insert(Extension::StartTls); } - "AUTH" => for &mechanism in &split[1..] { - match mechanism { - "PLAIN" => { - features.insert(Extension::Authentication(Mechanism::Plain)); + "AUTH" => { + for &mechanism in &split[1..] { + match mechanism { + "PLAIN" => { + features.insert(Extension::Authentication(Mechanism::Plain)); + } + "LOGIN" => { + features.insert(Extension::Authentication(Mechanism::Login)); + } + "XOAUTH2" => { + features.insert(Extension::Authentication(Mechanism::Xoauth2)); + } + _ => (), } - "LOGIN" => { - features.insert(Extension::Authentication(Mechanism::Login)); - } - "XOAUTH2" => { - features.insert(Extension::Authentication(Mechanism::Xoauth2)); - } - _ => (), } - }, + } _ => (), }; } diff --git a/lettre/src/smtp/mod.rs b/lettre/src/smtp/mod.rs index 5e67523..7a3ffe4 100644 --- a/lettre/src/smtp/mod.rs +++ b/lettre/src/smtp/mod.rs @@ -14,8 +14,9 @@ //! use native_tls::TlsConnector; -use smtp::authentication::{Credentials, Mechanism, DEFAULT_ENCRYPTED_MECHANISMS, - DEFAULT_UNENCRYPTED_MECHANISMS}; +use smtp::authentication::{ + Credentials, Mechanism, DEFAULT_ENCRYPTED_MECHANISMS, DEFAULT_UNENCRYPTED_MECHANISMS, +}; use smtp::client::net::ClientTlsParameters; use smtp::client::net::DEFAULT_TLS_PROTOCOLS; use smtp::client::InnerClient; @@ -106,7 +107,7 @@ impl SmtpClient { /// * No authentication /// * No SMTPUTF8 support /// * A 60 seconds timeout for smtp commands - /// + /// /// Consider using [`SmtpClient::new_simple`] instead, if possible. pub fn new(addr: A, security: ClientSecurity) -> Result { let mut addresses = addr.to_socket_addrs()?; @@ -254,7 +255,10 @@ impl<'a> SmtpTransport { } if self.state.connection_reuse_count > 0 { - info!("connection already established to {}", self.client_info.server_addr); + info!( + "connection already established to {}", + self.client_info.server_addr + ); return Ok(()); } @@ -281,21 +285,21 @@ impl<'a> SmtpTransport { .supports_feature(Extension::StartTls), ) { (&ClientSecurity::Required(_), false) => { - return Err(From::from("Could not encrypt connection, aborting")) + return Err(From::from("Could not encrypt connection, aborting")); } (&ClientSecurity::Opportunistic(_), false) => (), (&ClientSecurity::None, _) => (), (&ClientSecurity::Wrapper(_), _) => (), (&ClientSecurity::Opportunistic(ref tls_parameters), true) - | (&ClientSecurity::Required(ref tls_parameters), true) => { - try_smtp!(self.client.command(StarttlsCommand), self); - try_smtp!(self.client.upgrade_tls_stream(tls_parameters), self); + | (&ClientSecurity::Required(ref tls_parameters), true) => { + try_smtp!(self.client.command(StarttlsCommand), self); + try_smtp!(self.client.upgrade_tls_stream(tls_parameters), self); - debug!("connection encrypted"); + debug!("connection encrypted"); - // Send EHLO again - self.ehlo()?; - } + // Send EHLO again + self.ehlo()?; + } } if self.client_info.credentials.is_some() { @@ -314,7 +318,8 @@ impl<'a> SmtpTransport { }; for mechanism in accepted_mechanisms { - if self.server_info + if self + .server_info .as_ref() .unwrap() .supports_auth_mechanism(mechanism) @@ -370,7 +375,10 @@ impl<'a> Transport<'a> for SmtpTransport { type Result = SmtpResult; /// Sends an email - #[cfg_attr(feature = "cargo-clippy", allow(match_same_arms, cyclomatic_complexity))] + #[cfg_attr( + feature = "cargo-clippy", + allow(clippy::match_same_arms, clippy::cyclomatic_complexity) + )] fn send(&mut self, email: SendableEmail) -> SmtpResult { let message_id = email.message_id().to_string(); @@ -381,7 +389,8 @@ impl<'a> Transport<'a> for SmtpTransport { // Mail let mut mail_options = vec![]; - if self.server_info + if self + .server_info .as_ref() .unwrap() .supports_feature(Extension::EightBitMime) @@ -389,10 +398,12 @@ impl<'a> Transport<'a> for SmtpTransport { mail_options.push(MailParameter::Body(MailBodyParameter::EightBitMime)); } - if self.server_info + if self + .server_info .as_ref() .unwrap() - .supports_feature(Extension::SmtpUtfEight) && self.client_info.smtp_utf8 + .supports_feature(Extension::SmtpUtfEight) + && self.client_info.smtp_utf8 { mail_options.push(MailParameter::SmtpUtfEight); } diff --git a/lettre/src/smtp/r2d2.rs b/lettre/src/smtp/r2d2.rs index 41e1afe..cca4a57 100644 --- a/lettre/src/smtp/r2d2.rs +++ b/lettre/src/smtp/r2d2.rs @@ -1,6 +1,6 @@ use r2d2::ManageConnection; -use smtp::{ConnectionReuseParameters, SmtpClient, SmtpTransport}; use smtp::error::Error; +use smtp::{ConnectionReuseParameters, SmtpClient, SmtpTransport}; pub struct SmtpConnectionManager { transport_builder: SmtpClient, diff --git a/lettre/src/smtp/response.rs b/lettre/src/smtp/response.rs index 821b46c..e2a0f11 100644 --- a/lettre/src/smtp/response.rs +++ b/lettre/src/smtp/response.rs @@ -331,20 +331,19 @@ mod test { #[test] fn test_response_is_positive() { - assert!( - Response::new( - Code { - severity: Severity::PositiveCompletion, - category: Category::MailSystem, - detail: Detail::Zero, - }, - vec![ - "me".to_string(), - "8BITMIME".to_string(), - "SIZE 42".to_string(), - ], - ).is_positive() - ); + assert!(Response::new( + Code { + severity: Severity::PositiveCompletion, + category: Category::MailSystem, + detail: Detail::Zero, + }, + vec![ + "me".to_string(), + "8BITMIME".to_string(), + "SIZE 42".to_string(), + ], + ) + .is_positive()); assert!(!Response::new( Code { severity: Severity::TransientNegativeCompletion, @@ -356,25 +355,25 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).is_positive()); + ) + .is_positive()); } #[test] fn test_response_has_code() { - assert!( - Response::new( - Code { - severity: Severity::TransientNegativeCompletion, - category: Category::MailSystem, - detail: Detail::One, - }, - vec![ - "me".to_string(), - "8BITMIME".to_string(), - "SIZE 42".to_string(), - ], - ).has_code(451) - ); + assert!(Response::new( + Code { + severity: Severity::TransientNegativeCompletion, + category: Category::MailSystem, + detail: Detail::One, + }, + vec![ + "me".to_string(), + "8BITMIME".to_string(), + "SIZE 42".to_string(), + ], + ) + .has_code(451)); assert!(!Response::new( Code { severity: Severity::TransientNegativeCompletion, @@ -386,7 +385,8 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).has_code(251)); + ) + .has_code(251)); } #[test] @@ -403,7 +403,8 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).first_word(), + ) + .first_word(), Some("me") ); assert_eq!( @@ -418,7 +419,8 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).first_word(), + ) + .first_word(), Some("me") ); assert_eq!( @@ -429,7 +431,8 @@ mod test { detail: Detail::One, }, vec![], - ).first_word(), + ) + .first_word(), None ); assert_eq!( @@ -440,7 +443,8 @@ mod test { detail: Detail::One, }, vec![" ".to_string()], - ).first_word(), + ) + .first_word(), None ); assert_eq!( @@ -451,7 +455,8 @@ mod test { detail: Detail::One, }, vec![" ".to_string()], - ).first_word(), + ) + .first_word(), None ); assert_eq!( @@ -462,7 +467,8 @@ mod test { detail: Detail::One, }, vec!["".to_string()], - ).first_word(), + ) + .first_word(), None ); } @@ -481,7 +487,8 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).first_line(), + ) + .first_line(), Some("me") ); assert_eq!( @@ -496,7 +503,8 @@ mod test { "8BITMIME".to_string(), "SIZE 42".to_string(), ], - ).first_line(), + ) + .first_line(), Some("me mo") ); assert_eq!( @@ -507,7 +515,8 @@ mod test { detail: Detail::One, }, vec![], - ).first_line(), + ) + .first_line(), None ); assert_eq!( @@ -518,7 +527,8 @@ mod test { detail: Detail::One, }, vec![" ".to_string()], - ).first_line(), + ) + .first_line(), Some(" ") ); assert_eq!( @@ -529,7 +539,8 @@ mod test { detail: Detail::One, }, vec![" ".to_string()], - ).first_line(), + ) + .first_line(), Some(" ") ); assert_eq!( @@ -540,7 +551,8 @@ mod test { detail: Detail::One, }, vec!["".to_string()], - ).first_line(), + ) + .first_line(), Some("") ); } diff --git a/lettre/tests/r2d2_smtp.rs b/lettre/tests/r2d2_smtp.rs index 055fdbe..49daa8a 100644 --- a/lettre/tests/r2d2_smtp.rs +++ b/lettre/tests/r2d2_smtp.rs @@ -3,8 +3,8 @@ mod test { extern crate lettre; extern crate r2d2; - use self::lettre::{SmtpConnectionManager, Transport}; use self::lettre::{ClientSecurity, EmailAddress, Envelope, SendableEmail, SmtpClient}; + use self::lettre::{SmtpConnectionManager, Transport}; use self::r2d2::Pool; use std::sync::mpsc; use std::thread; @@ -14,7 +14,8 @@ mod test { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), message.to_string().into_bytes(), ) diff --git a/lettre/tests/skeptic.rs b/lettre/tests/skeptic.rs index 0b61213..29358ba 100644 --- a/lettre/tests/skeptic.rs +++ b/lettre/tests/skeptic.rs @@ -52,7 +52,8 @@ fn skeptic_test(path: &Path) { .arg(&depdir) .arg(path); - let result = cmd.spawn() + let result = cmd + .spawn() .expect("Failed to spawn process") .wait() .expect("Failed to run process"); diff --git a/lettre/tests/transport_file.rs b/lettre/tests/transport_file.rs index 2f1bb12..a6aa1bc 100644 --- a/lettre/tests/transport_file.rs +++ b/lettre/tests/transport_file.rs @@ -18,7 +18,8 @@ mod test { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre/tests/transport_sendmail.rs b/lettre/tests/transport_sendmail.rs index 41d86f8..6437581 100644 --- a/lettre/tests/transport_sendmail.rs +++ b/lettre/tests/transport_sendmail.rs @@ -13,7 +13,8 @@ mod test { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre/tests/transport_smtp.rs b/lettre/tests/transport_smtp.rs index ff7c31c..0ea1c24 100644 --- a/lettre/tests/transport_smtp.rs +++ b/lettre/tests/transport_smtp.rs @@ -11,7 +11,8 @@ mod test { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre/tests/transport_stub.rs b/lettre/tests/transport_stub.rs index 1265952..f237bda 100644 --- a/lettre/tests/transport_stub.rs +++ b/lettre/tests/transport_stub.rs @@ -11,7 +11,8 @@ fn stub_transport() { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); @@ -19,7 +20,8 @@ fn stub_transport() { Envelope::new( Some(EmailAddress::new("user@localhost".to_string()).unwrap()), vec![EmailAddress::new("root@localhost".to_string()).unwrap()], - ).unwrap(), + ) + .unwrap(), "id".to_string(), "Hello ß☺ example".to_string().into_bytes(), ); diff --git a/lettre_email/examples/local.rs b/lettre_email/examples/local.rs index cb97a80..d614028 100644 --- a/lettre_email/examples/local.rs +++ b/lettre_email/examples/local.rs @@ -14,7 +14,8 @@ fn main() { .from("user@example.com") .subject("Hi, Hello world") .text("Hello world.") - .attachment_from_file(Path::new("Cargo.toml"), None, &mime::TEXT_PLAIN).unwrap() + .attachment_from_file(Path::new("Cargo.toml"), None, &mime::TEXT_PLAIN) + .unwrap() .build() .unwrap(); diff --git a/lettre_email/src/lib.rs b/lettre_email/src/lib.rs index 43211f8..b06303f 100644 --- a/lettre_email/src/lib.rs +++ b/lettre_email/src/lib.rs @@ -3,8 +3,14 @@ #![doc(html_root_url = "https://docs.rs/lettre_email/0.9.0")] #![deny( - missing_docs, missing_debug_implementations, missing_copy_implementations, trivial_casts, - trivial_numeric_casts, unsafe_code, unstable_features, unused_import_braces + missing_docs, + missing_debug_implementations, + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces )] extern crate failure; @@ -254,9 +260,11 @@ impl EmailBuilder { ) -> Result { self.attachment( fs::read(path)?.as_slice(), - filename.unwrap_or(path.file_name() - .and_then(|x| x.to_str()) - .ok_or(EmailError::CannotParseFilename)?), + filename.unwrap_or( + path.file_name() + .and_then(|x| x.to_str()) + .ok_or(EmailError::CannotParseFilename)?, + ), content_type, ) } @@ -388,9 +396,11 @@ impl EmailBuilder { for receiver in self.to.iter().chain(self.cc.iter()).chain(self.bcc.iter()) { match *receiver { Address::Mailbox(ref m) => to.push(EmailAddress::from_str(&m.address)?), - Address::Group(_, ref ms) => for m in ms.iter() { - to.push(EmailAddress::from_str(&m.address.clone())?); - }, + Address::Group(_, ref ms) => { + for m in ms.iter() { + to.push(EmailAddress::from_str(&m.address.clone())?); + } + } } } let from = Some(EmailAddress::from_str(&match self.sender { @@ -424,15 +434,18 @@ impl EmailBuilder { // Add the collected addresses as mailbox-list all at once. // The unwraps are fine because the conversions for Vec
never errs. if !self.to.is_empty() { - self.message = self.message + self.message = self + .message .header(Header::new_with_value("To".into(), self.to).unwrap()); } if !self.from.is_empty() { - self.message = self.message + self.message = self + .message .header(Header::new_with_value("From".into(), self.from).unwrap()); } else if let Some(from) = envelope.from() { let from = vec![Address::new_mailbox(from.to_string())]; - self.message = self.message + self.message = self + .message .header(Header::new_with_value("From".into(), from).unwrap()); } else { Err(EmailError::Envelope { @@ -440,24 +453,29 @@ impl EmailBuilder { })?; } if !self.cc.is_empty() { - self.message = self.message + self.message = self + .message .header(Header::new_with_value("Cc".into(), self.cc).unwrap()); } if !self.reply_to.is_empty() { - self.message = self.message + self.message = self + .message .header(Header::new_with_value("Reply-To".into(), self.reply_to).unwrap()); } if !self.in_reply_to.is_empty() { - self.message = self.message - .header(Header::new_with_value("In-Reply-To".into(), self.in_reply_to.join(" ")).unwrap()); + self.message = self.message.header( + Header::new_with_value("In-Reply-To".into(), self.in_reply_to.join(" ")).unwrap(), + ); } if !self.references.is_empty() { - self.message = self.message - .header(Header::new_with_value("References".into(), self.references.join(" ")).unwrap()); + self.message = self.message.header( + Header::new_with_value("References".into(), self.references.join(" ")).unwrap(), + ); } if !self.date_issued { - self.message = self.message + self.message = self + .message .header(("Date", Tm::rfc822z(&now()).to_string().as_ref())); } @@ -580,7 +598,8 @@ mod test { EmailAddress::new("user@localhost".to_string()).unwrap(), EmailAddress::new("cc@localhost".to_string()).unwrap(), EmailAddress::new("bcc@localhost".to_string()).unwrap(), - ].as_slice() + ] + .as_slice() ); } diff --git a/lettre_email/tests/build_with_envelope.rs b/lettre_email/tests/build_with_envelope.rs index a2f1571..767f9f3 100644 --- a/lettre_email/tests/build_with_envelope.rs +++ b/lettre_email/tests/build_with_envelope.rs @@ -1,14 +1,15 @@ -extern crate lettre_email; extern crate lettre; -use lettre_email::EmailBuilder; +extern crate lettre_email; use lettre::{EmailAddress, Envelope}; +use lettre_email::EmailBuilder; #[test] fn build_with_envelope_test() { let e = Envelope::new( Some(EmailAddress::new("from@example.org".to_string()).unwrap()), vec![EmailAddress::new("to@example.org".to_string()).unwrap()], - ).unwrap(); + ) + .unwrap(); let _email = EmailBuilder::new() .envelope(e) .subject("subject") @@ -22,11 +23,12 @@ fn build_with_envelope_without_from_test() { let e = Envelope::new( None, vec![EmailAddress::new("to@example.org".to_string()).unwrap()], - ).unwrap(); + ) + .unwrap(); let _email = EmailBuilder::new() .envelope(e) .subject("subject") .text("message") .build() .unwrap_err(); -} \ No newline at end of file +} diff --git a/lettre_email/tests/skeptic.rs b/lettre_email/tests/skeptic.rs index 0d8a896..462fa1c 100644 --- a/lettre_email/tests/skeptic.rs +++ b/lettre_email/tests/skeptic.rs @@ -36,7 +36,8 @@ fn skeptic_test(path: &Path) { .arg(&depdir) .arg(path); - let result = cmd.spawn() + let result = cmd + .spawn() .expect("Failed to spawn process") .wait() .expect("Failed to run process");