Fix clippy and formatting

This commit is contained in:
Alexis Mousset
2019-03-17 13:26:14 +01:00
parent 2d4320ea45
commit be50862d55
22 changed files with 190 additions and 124 deletions
+4 -2
View File
@@ -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(),
);
+2 -1
View File
@@ -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(),
);
+9 -5
View File
@@ -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)]
+4 -4
View File
@@ -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<String, Error> {
match *self {
match self {
Mechanism::Plain => match challenge {
Some(_) => Err(Error::Client("This mechanism does not expect a challenge")),
None => Ok(format!(
+2 -2
View File
@@ -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<S: Write + Read> InnerClient<S> {
/// Creates a new SMTP client
///
@@ -165,7 +165,7 @@ impl<S: Connector + Write + Read + Timeout + Debug> InnerClient<S> {
}
/// 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()
}
+2 -2
View File
@@ -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,
+5 -1
View File
@@ -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));
+1 -1
View File
@@ -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
+14 -12
View File
@@ -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));
}
_ => (),
}
},
}
_ => (),
};
}
+28 -17
View File
@@ -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<A: ToSocketAddrs>(addr: A, security: ClientSecurity) -> Result<SmtpClient, Error> {
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);
}
+1 -1
View File
@@ -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,
+54 -42
View File
@@ -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("")
);
}
+3 -2
View File
@@ -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(),
)
+2 -1
View File
@@ -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");
+2 -1
View File
@@ -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(),
);
+2 -1
View File
@@ -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(),
);
+2 -1
View File
@@ -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(),
);
+4 -2
View File
@@ -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(),
);
+2 -1
View File
@@ -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();
+38 -19
View File
@@ -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<EmailBuilder, Error> {
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<Address> 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()
);
}
+7 -5
View File
@@ -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();
}
}
+2 -1
View File
@@ -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");