Update dependencies and improve style
This commit is contained in:
@@ -18,8 +18,8 @@ travis-ci = { repository = "lettre/lettre" }
|
||||
log = "^0.3"
|
||||
bufstream = { version = "^0.1", optional = true }
|
||||
native-tls = { version = "^0.1", optional = true }
|
||||
base64 = { version = "^0.7", optional = true }
|
||||
hex = { version = "^0.2", optional = true }
|
||||
base64 = { version = "^0.8", optional = true }
|
||||
hex = { version = "^0.3", optional = true }
|
||||
rust-crypto = { version = "^0.2", optional = true }
|
||||
serde = { version = "^1.0", optional = true }
|
||||
serde_json = { version = "^1.0", optional = true }
|
||||
|
||||
@@ -37,7 +37,7 @@ pub use file::FileEmailTransport;
|
||||
#[cfg(feature = "sendmail-transport")]
|
||||
pub use sendmail::SendmailTransport;
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
pub use smtp::{SmtpTransport, ClientSecurity};
|
||||
pub use smtp::{ClientSecurity, SmtpTransport};
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
pub use smtp::client::net::ClientTlsParameters;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
@@ -7,7 +7,7 @@ use crypto::mac::Mac;
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
use crypto::md5::Md5;
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
use hex::ToHex;
|
||||
use hex;
|
||||
use smtp::NUL;
|
||||
use smtp::error::Error;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
@@ -160,7 +160,7 @@ impl Mechanism {
|
||||
Ok(format!(
|
||||
"{} {}",
|
||||
credentials.username,
|
||||
hmac.result().code().to_hex()
|
||||
hex::encode(hmac.result().code())
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@ impl MockStream {
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn next_vec(&mut self, vec: Vec<u8>) {
|
||||
pub fn next_vec(&mut self, vec: &[u8]) {
|
||||
let mut cursor = self.reader.lock().unwrap();
|
||||
cursor.set_position(0);
|
||||
cursor.get_mut().clear();
|
||||
cursor.get_mut().extend_from_slice(vec.as_slice());
|
||||
cursor.get_mut().extend_from_slice(vec);
|
||||
}
|
||||
|
||||
pub fn swap(&mut self) {
|
||||
|
||||
@@ -188,7 +188,7 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
response = self.smtp_command(AuthCommand::new_from_response(
|
||||
mechanism,
|
||||
credentials.clone(),
|
||||
response,
|
||||
&response,
|
||||
)?)?;
|
||||
}
|
||||
|
||||
@@ -209,8 +209,11 @@ impl<S: Connector + Write + Read + Timeout + Debug> Client<S> {
|
||||
out_buf.clear();
|
||||
|
||||
let consumed = match message_reader.fill_buf() {
|
||||
Ok(bytes) => { codec.encode(bytes, &mut out_buf)?; bytes.len() },
|
||||
Err(ref err) => panic!("Failed with: {}", err)
|
||||
Ok(bytes) => {
|
||||
codec.encode(bytes, &mut out_buf)?;
|
||||
bytes.len()
|
||||
}
|
||||
Err(ref err) => panic!("Failed with: {}", err),
|
||||
};
|
||||
message_reader.consume(consumed);
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//! A trait to represent a stream
|
||||
|
||||
use native_tls::{TlsConnector, TlsStream, Protocol};
|
||||
use native_tls::{Protocol, TlsConnector, TlsStream};
|
||||
use smtp::client::mock::MockStream;
|
||||
use std::io::{self, ErrorKind, Read, Write};
|
||||
use std::net::{Ipv4Addr, Shutdown, SocketAddr, SocketAddrV4, TcpStream};
|
||||
@@ -27,7 +27,7 @@ impl ClientTlsParameters {
|
||||
|
||||
/// Accepted protocols by default.
|
||||
/// This removes TLS 1.0 compared to tls-native defaults.
|
||||
pub const DEFAULT_TLS_PROTOCOLS : &'static [Protocol] = &[Protocol::Tlsv11, Protocol::Tlsv12];
|
||||
pub const DEFAULT_TLS_PROTOCOLS: &'static [Protocol] = &[Protocol::Tlsv11, Protocol::Tlsv12];
|
||||
|
||||
#[derive(Debug)]
|
||||
/// Represents the different types of underlying network streams
|
||||
|
||||
@@ -269,7 +269,7 @@ impl AuthCommand {
|
||||
pub fn new_from_response(
|
||||
mechanism: Mechanism,
|
||||
credentials: Credentials,
|
||||
response: Response,
|
||||
response: &Response,
|
||||
) -> Result<AuthCommand, Error> {
|
||||
if !response.has_code(334) {
|
||||
return Err(Error::ResponseParsing("Expecting a challenge"));
|
||||
@@ -418,7 +418,7 @@ mod test {
|
||||
AuthCommand::new_from_response(
|
||||
Mechanism::CramMd5,
|
||||
credentials.clone(),
|
||||
Response::new(Code::from_str("334").unwrap(), vec!["dGVzdAo=".to_string()]),
|
||||
&Response::new(Code::from_str("334").unwrap(), vec!["dGVzdAo=".to_string()]),
|
||||
).unwrap()
|
||||
),
|
||||
"dXNlciA1NTIzNThiMzExOWFjOWNkYzM2YWRiN2MxNWRmMWJkNw==\r\n"
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
|
||||
use self::Error::*;
|
||||
use base64::DecodeError;
|
||||
use native_tls;
|
||||
use smtp::response::{Response, Severity};
|
||||
use std::error::Error as StdError;
|
||||
use std::fmt;
|
||||
use std::fmt::{Display, Formatter};
|
||||
use std::io;
|
||||
use std::string::FromUtf8Error;
|
||||
use native_tls;
|
||||
|
||||
/// An enum of all error kinds.
|
||||
#[derive(Debug)]
|
||||
|
||||
@@ -40,7 +40,6 @@
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
//! use lettre::smtp::SUBMISSION_PORT;
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport};
|
||||
//! use lettre::smtp::extension::ClientId;
|
||||
//! use lettre::smtp::ConnectionReuseParameters;
|
||||
@@ -54,7 +53,7 @@
|
||||
//! );
|
||||
//!
|
||||
//! // Connect to a remote server on a custom port
|
||||
//! let mut mailer = SmtpTransport::simple_builder("server.tld".to_string()).unwrap()
|
||||
//! let mut mailer = SmtpTransport::simple_builder("server.tld").unwrap()
|
||||
//! // Set the name sent during EHLO/HELO, default is `localhost`
|
||||
//! .hello_name(ClientId::Domain("my.hostname.tld".to_string()))
|
||||
//! // Add credentials for authentication
|
||||
@@ -111,9 +110,9 @@ use smtp::authentication::{Credentials, DEFAULT_ENCRYPTED_MECHANISMS,
|
||||
DEFAULT_UNENCRYPTED_MECHANISMS, Mechanism};
|
||||
use smtp::client::Client;
|
||||
use smtp::client::net::ClientTlsParameters;
|
||||
use smtp::client::net::DEFAULT_TLS_PROTOCOLS;
|
||||
use smtp::commands::*;
|
||||
use smtp::error::{Error, SmtpResult};
|
||||
use smtp::client::net::DEFAULT_TLS_PROTOCOLS;
|
||||
use smtp::extension::{ClientId, Extension, MailBodyParameter, MailParameter, ServerInfo};
|
||||
use std::io::Read;
|
||||
use std::net::{SocketAddr, ToSocketAddrs};
|
||||
@@ -140,19 +139,19 @@ pub const SUBMISSION_PORT: u16 = 587;
|
||||
// Useful strings and characters
|
||||
|
||||
/// The word separator for SMTP transactions
|
||||
pub const SP: &'static str = " ";
|
||||
pub const SP: &str = " ";
|
||||
|
||||
/// The line ending for SMTP transactions (carriage return + line feed)
|
||||
pub const CRLF: &'static str = "\r\n";
|
||||
pub const CRLF: &str = "\r\n";
|
||||
|
||||
/// Colon
|
||||
pub const COLON: &'static str = ":";
|
||||
pub const COLON: &str = ":";
|
||||
|
||||
/// The ending of message content
|
||||
pub const MESSAGE_ENDING: &'static str = "\r\n.\r\n";
|
||||
pub const MESSAGE_ENDING: &str = "\r\n.\r\n";
|
||||
|
||||
/// NUL unicode character
|
||||
pub const NUL: &'static str = "\0";
|
||||
pub const NUL: &str = "\0";
|
||||
|
||||
/// How to apply TLS to a client connection
|
||||
#[derive(Clone)]
|
||||
@@ -322,18 +321,16 @@ impl<'a> SmtpTransport {
|
||||
/// Simple and secure transport, should be used when possible.
|
||||
/// Creates an encrypted transport over submission port, using the provided domain
|
||||
/// to validate TLS certificates.
|
||||
pub fn simple_builder(domain: String) -> Result<SmtpTransportBuilder, Error> {
|
||||
pub fn simple_builder(domain: &str) -> Result<SmtpTransportBuilder, Error> {
|
||||
|
||||
let mut tls_builder = TlsConnector::builder()?;
|
||||
tls_builder.supported_protocols(DEFAULT_TLS_PROTOCOLS)?;
|
||||
|
||||
let tls_parameters = ClientTlsParameters::new(
|
||||
domain.clone(),
|
||||
tls_builder.build().unwrap(),
|
||||
);
|
||||
let tls_parameters =
|
||||
ClientTlsParameters::new(domain.to_string(), tls_builder.build().unwrap());
|
||||
|
||||
SmtpTransportBuilder::new(
|
||||
(domain.as_ref(), SUBMISSION_PORT),
|
||||
(domain, SUBMISSION_PORT),
|
||||
ClientSecurity::Required(tls_parameters),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -41,9 +41,7 @@ impl StubEmailTransport {
|
||||
|
||||
/// Creates a new transport that always returns a success response
|
||||
pub fn new_positive() -> StubEmailTransport {
|
||||
StubEmailTransport {
|
||||
response: Ok(()),
|
||||
}
|
||||
StubEmailTransport { response: Ok(()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
.from("user@example.com")
|
||||
.subject("Hi, Hello world")
|
||||
.text("Hello world.")
|
||||
.attachment(Path::new("Cargo.toml"), None, mime::TEXT_PLAIN).unwrap()
|
||||
.attachment(Path::new("Cargo.toml"), None, &mime::TEXT_PLAIN).unwrap()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
use self::Error::*;
|
||||
use std::error::Error as StdError;
|
||||
use std::io;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io;
|
||||
|
||||
/// An enum of all error kinds.
|
||||
#[derive(Debug)]
|
||||
@@ -40,4 +40,3 @@ impl From<io::Error> for Error {
|
||||
Io(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,11 +66,11 @@ pub use email_format::{Address, Header, Mailbox, MimeMessage, MimeMultipartType}
|
||||
use error::Error;
|
||||
use lettre::{EmailAddress, SendableEmail};
|
||||
use mime::Mime;
|
||||
use std::fs::File;
|
||||
use std::io::Read;
|
||||
use std::path::Path;
|
||||
use time::{Tm, now};
|
||||
use uuid::Uuid;
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::io::Read;
|
||||
|
||||
/// Converts an address or an address with an alias to a `Header`
|
||||
pub trait IntoHeader {
|
||||
@@ -434,13 +434,13 @@ impl PartBuilder {
|
||||
}
|
||||
|
||||
/// Adds a `ContentType` header with the given MIME type
|
||||
pub fn content_type(mut self, content_type: Mime) -> PartBuilder {
|
||||
pub fn content_type(mut self, content_type: &Mime) -> PartBuilder {
|
||||
self.set_content_type(content_type);
|
||||
self
|
||||
}
|
||||
|
||||
/// Adds a `ContentType` header with the given MIME type
|
||||
pub fn set_content_type(&mut self, content_type: Mime) {
|
||||
pub fn set_content_type(&mut self, content_type: &Mime) {
|
||||
self.add_header(("Content-Type", format!("{}", content_type).as_ref()));
|
||||
}
|
||||
|
||||
@@ -600,15 +600,25 @@ impl EmailBuilder {
|
||||
}
|
||||
|
||||
/// Adds an attachment to the email
|
||||
pub fn attachment(mut self, path: &Path, filename: Option<&str>, content_type: Mime) -> Result<EmailBuilder, Error> {
|
||||
pub fn attachment(
|
||||
mut self,
|
||||
path: &Path,
|
||||
filename: Option<&str>,
|
||||
content_type: &Mime,
|
||||
) -> Result<EmailBuilder, Error> {
|
||||
self.set_attachment(path, filename, content_type)?;
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
/// Adds an attachment to the email
|
||||
/// If filename is not provided, the name of the file will be used.
|
||||
pub fn set_attachment(&mut self, path: &Path, filename: Option<&str>, content_type: Mime) -> Result<(), Error> {
|
||||
let file = File::open(path);
|
||||
pub fn set_attachment(
|
||||
&mut self,
|
||||
path: &Path,
|
||||
filename: Option<&str>,
|
||||
content_type: &Mime,
|
||||
) -> Result<(), Error> {
|
||||
let file = File::open(path);
|
||||
let body = match file {
|
||||
Ok(mut f) => {
|
||||
let mut data = String::new();
|
||||
@@ -627,18 +637,25 @@ impl EmailBuilder {
|
||||
|
||||
let actual_filename = match filename {
|
||||
Some(name) => name,
|
||||
None => match path.file_name() {
|
||||
Some(name) => match name.to_str() {
|
||||
Some(name) => name,
|
||||
None => {
|
||||
match path.file_name() {
|
||||
Some(name) => {
|
||||
match name.to_str() {
|
||||
Some(name) => name,
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
}
|
||||
}
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
},
|
||||
None => return Err(Error::CannotParseFilename),
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let content = PartBuilder::new()
|
||||
.body(body)
|
||||
.header(("Content-Disposition", format!("attachment; filename=\"{}\"", actual_filename)))
|
||||
.header((
|
||||
"Content-Disposition",
|
||||
format!("attachment; filename=\"{}\"", actual_filename),
|
||||
))
|
||||
.header(("Content-Type", content_type.to_string()))
|
||||
.build();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user