diff --git a/rustfmt.toml b/rustfmt.toml index 44148a2..0a6378c 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,2 @@ reorder_imports = true +reorder_imported_names = true \ No newline at end of file diff --git a/src/email/error.rs b/src/email/error.rs index 5ce7650..e0929a3 100644 --- a/src/email/error.rs +++ b/src/email/error.rs @@ -1,6 +1,5 @@ //! Error and result type for emails - use self::Error::*; use std::error::Error as StdError; use std::fmt; diff --git a/src/email/mod.rs b/src/email/mod.rs index b35847e..d04dd02 100644 --- a/src/email/mod.rs +++ b/src/email/mod.rs @@ -1,9 +1,9 @@ //! Simple email representation + pub mod error; use email::error::Error; - -use email_format::{Header, Mailbox, Address, MimeMessage, MimeMultipartType}; +use email_format::{Address, Header, Mailbox, MimeMessage, MimeMultipartType}; use mime::Mime; use std::fmt; use std::fmt::{Display, Formatter}; @@ -11,95 +11,101 @@ use time::{Tm, now}; use uuid::Uuid; /// Converts an address or an address with an alias to a `Header` -pub trait ToHeader { +pub trait IntoHeader { /// Converts to a `Header` struct - fn to_header(&self) -> Header; + fn into_header(self) -> Header; } -impl ToHeader for Header { - fn to_header(&self) -> Header { - self.clone() +impl IntoHeader for Header { + fn into_header(self) -> Header { + self } } -impl<'a> ToHeader for (&'a str, &'a str) { - fn to_header(&self) -> Header { - let (name, value) = *self; - Header::new(name.to_string(), value.to_string()) +impl, T: Into> IntoHeader for (S, T) { + fn into_header(self) -> Header { + let (name, value) = self; + Header::new(name.into(), value.into()) } } /// Converts an adress or an address with an alias to a `Mailbox` -pub trait ToMailbox { +pub trait IntoMailbox { /// Converts to a `Mailbox` struct - fn to_mailbox(&self) -> Mailbox; + fn into_mailbox(self) -> Mailbox; } -impl ToMailbox for Mailbox { - fn to_mailbox(&self) -> Mailbox { - (*self).clone() +impl IntoMailbox for Mailbox { + fn into_mailbox(self) -> Mailbox { + self } } -impl<'a> ToMailbox for &'a str { - fn to_mailbox(&self) -> Mailbox { - Mailbox::new(self.to_string()) +impl<'a> IntoMailbox for &'a str { + fn into_mailbox(self) -> Mailbox { + Mailbox::new(self.into()) } } -impl<'a> ToMailbox for (&'a str, &'a str) { - fn to_mailbox(&self) -> Mailbox { - let (address, alias) = *self; - Mailbox::new_with_name(alias.to_string(), address.to_string()) +impl IntoMailbox for String { + fn into_mailbox(self) -> Mailbox { + Mailbox::new(self) + } +} + +impl, T: Into> IntoMailbox for (S, T) { + fn into_mailbox(self) -> Mailbox { + let (address, alias) = self; + Mailbox::new_with_name(alias.into(), address.into()) } } /// Can be transformed to a sendable email pub trait IntoEmail { /// Builds an email - fn into_email(&self) -> Result; + fn into_email(self) -> Result; } impl IntoEmail for SimpleEmail { - fn into_email(&self) -> Result { + fn into_email(self) -> Result { let mut builder = EmailBuilder::new(); if self.from.is_some() { - builder.add_from(self.from.as_ref().unwrap().as_str().to_mailbox()); + builder.add_from(self.from.unwrap()); } - for to_address in self.to.as_slice() { - builder.add_to(to_address.as_str().to_mailbox()); + for to_address in self.to { + builder.add_to(to_address.into_mailbox()); } - for cc_address in self.cc.as_slice() { - builder.add_cc(cc_address.as_str().to_mailbox()); + for cc_address in self.cc { + builder.add_cc(cc_address.into_mailbox()); } // No bcc for now if self.reply_to.is_some() { - builder.add_reply_to(self.reply_to.as_ref().unwrap().as_str().to_mailbox()); + builder.add_reply_to(self.reply_to.unwrap().into_mailbox()); } if self.subject.is_some() { - builder.set_subject(self.subject.as_ref().unwrap().as_str()); + builder.set_subject(self.subject.unwrap()); } // No date for now - match (self.text.as_ref(), self.html.as_ref()) { - (Some(text), Some(html)) => builder.set_alternative(html.as_str(), text.as_str()), - (Some(text), None) => builder.set_text(text.as_str()), - (None, Some(html)) => builder.set_html(html.as_str()), + match (self.text, self.html) { + (Some(text), Some(html)) => builder.set_alternative(html, text), + (Some(text), None) => builder.set_text(text), + (None, Some(html)) => builder.set_html(html), (None, None) => (), } - for header in self.headers.as_slice() { - builder.add_header(header.to_header()); + for header in self.headers { + builder.add_header(header.into_header()); } - Ok(builder.build().unwrap()) + builder.build() } } @@ -107,11 +113,11 @@ impl IntoEmail for SimpleEmail { /// Simple representation of an email, useful for some transports #[derive(PartialEq,Eq,Clone,Debug,Default)] pub struct SimpleEmail { - from: Option, - to: Vec, - cc: Vec, - // bcc: Vec, - reply_to: Option, + from: Option, + to: Vec, + cc: Vec, + bcc: Vec, + reply_to: Option, subject: Option, date: Option, html: Option, @@ -122,106 +128,113 @@ pub struct SimpleEmail { impl SimpleEmail { /// Adds a generic header - pub fn header(mut self, header: A) -> SimpleEmail { + pub fn header(mut self, header: A) -> SimpleEmail { self.add_header(header); self } /// Adds a generic header - pub fn add_header(&mut self, header: A) { - self.headers.push(header.to_header()); + pub fn add_header(&mut self, header: A) { + self.headers.push(header.into_header()); } /// Adds a `From` header and stores the sender address - pub fn from(mut self, address: A) -> SimpleEmail { + pub fn from(mut self, address: A) -> SimpleEmail { self.add_from(address); self } /// Adds a `From` header and stores the sender address - pub fn add_from(&mut self, address: A) { - let mailbox = address.to_mailbox(); - self.from = Some(mailbox.address); + pub fn add_from(&mut self, address: A) { + self.from = Some(address.into_mailbox()); } /// Adds a `To` header and stores the recipient address - pub fn to(mut self, address: A) -> SimpleEmail { + pub fn to(mut self, address: A) -> SimpleEmail { self.add_to(address); self } /// Adds a `To` header and stores the recipient address - pub fn add_to(&mut self, address: A) { - let mailbox = address.to_mailbox(); - self.to.push(mailbox.address); + pub fn add_to(&mut self, address: A) { + self.to.push(address.into_mailbox()); } /// Adds a `Cc` header and stores the recipient address - pub fn cc(mut self, address: A) -> SimpleEmail { + pub fn cc(mut self, address: A) -> SimpleEmail { self.add_cc(address); self } /// Adds a `Cc` header and stores the recipient address - pub fn add_cc(&mut self, address: A) { - let mailbox = address.to_mailbox(); - self.cc.push(mailbox.address); + pub fn add_cc(&mut self, address: A) { + self.cc.push(address.into_mailbox()); + } + + /// Adds a `Bcc` header and stores the recipient address + pub fn bcc(mut self, address: A) -> SimpleEmail { + self.add_bcc(address); + self + } + + /// Adds a `Bcc` header and stores the recipient address + pub fn add_bcc(&mut self, address: A) { + self.bcc.push(address.into_mailbox()); } /// Adds a `Reply-To` header - pub fn reply_to(mut self, address: A) -> SimpleEmail { + pub fn reply_to(mut self, address: A) -> SimpleEmail { self.add_reply_to(address); self } /// Adds a `Reply-To` header - pub fn add_reply_to(&mut self, address: A) { - let mailbox = address.to_mailbox(); - self.reply_to = Some(mailbox.address); + pub fn add_reply_to(&mut self, address: A) { + self.reply_to = Some(address.into_mailbox()); } /// Adds a `Subject` header - pub fn subject(mut self, subject: &str) -> SimpleEmail { + pub fn subject>(mut self, subject: S) -> SimpleEmail { self.set_subject(subject); self } /// Adds a `Subject` header - pub fn set_subject(&mut self, subject: &str) { - self.subject = Some(subject.to_string()); + pub fn set_subject>(&mut self, subject: S) { + self.subject = Some(subject.into()); } /// Adds a `Date` header with the given date - pub fn date(mut self, date: &Tm) -> SimpleEmail { + pub fn date(mut self, date: Tm) -> SimpleEmail { self.set_date(date); self } /// Adds a `Date` header with the given date - pub fn set_date(&mut self, date: &Tm) { - self.date = Some(date.clone()); + pub fn set_date(&mut self, date: Tm) { + self.date = Some(date); } /// Sets the email body to plain text content - pub fn text(mut self, body: &str) -> SimpleEmail { + pub fn text>(mut self, body: S) -> SimpleEmail { self.set_text(body); self } /// Sets the email body to plain text content - pub fn set_text(&mut self, body: &str) { - self.text = Some(body.to_string()); + pub fn set_text>(&mut self, body: S) { + self.text = Some(body.into()); } /// Sets the email body to HTML content - pub fn html(mut self, body: &str) -> SimpleEmail { + pub fn html>(mut self, body: S) -> SimpleEmail { self.set_html(body); self } /// Sets the email body to HTML content - pub fn set_html(&mut self, body: &str) { - self.html = Some(body.to_string()); + pub fn set_html>(&mut self, body: S) { + self.html = Some(body.into()); } } @@ -243,6 +256,8 @@ pub struct EmailBuilder { from_header: Vec
, /// The Cc addresses for the mail header cc_header: Vec
, + /// The Bcc addresses for the mail header + bcc_header: Vec
, /// The Reply-To addresses for the mail header reply_to_header: Vec
, /// The sender address for the mail header @@ -314,28 +329,27 @@ impl PartBuilder { } /// Adds a generic header - pub fn header(mut self, header: A) -> PartBuilder { + pub fn header(mut self, header: A) -> PartBuilder { self.add_header(header); self } /// Adds a generic header - pub fn add_header(&mut self, header: A) { - self.message.headers.insert(header.to_header()); + pub fn add_header(&mut self, header: A) { + self.message.headers.insert(header.into_header()); } /// Sets the body - pub fn body(mut self, body: &str) -> PartBuilder { + pub fn body>(mut self, body: S) -> PartBuilder { self.set_body(body); self } /// Sets the body - pub fn set_body(&mut self, body: &str) { - self.message.body = body.to_string(); + pub fn set_body>(&mut self, body: S) { + self.message.body = body.into(); } - /// Defines a `MimeMultipartType` value pub fn message_type(mut self, mime_type: MimeMultipartType) -> PartBuilder { self.set_message_type(mime_type); @@ -384,6 +398,7 @@ impl EmailBuilder { to_header: vec![], from_header: vec![], cc_header: vec![], + bcc_header: vec![], reply_to_header: vec![], sender_header: None, envelope: None, @@ -392,96 +407,108 @@ impl EmailBuilder { } /// Sets the email body - pub fn body(mut self, body: &str) -> EmailBuilder { + pub fn body>(mut self, body: S) -> EmailBuilder { self.message.set_body(body); self } /// Sets the email body - pub fn set_body(&mut self, body: &str) { + pub fn set_body>(&mut self, body: S) { self.message.set_body(body); } /// Add a generic header - pub fn header(mut self, header: A) -> EmailBuilder { + pub fn header(mut self, header: A) -> EmailBuilder { self.message.add_header(header); self } /// Add a generic header - pub fn add_header(&mut self, header: A) { + pub fn add_header(&mut self, header: A) { self.message.add_header(header); } /// Adds a `From` header and stores the sender address - pub fn from(mut self, address: A) -> EmailBuilder { + pub fn from(mut self, address: A) -> EmailBuilder { self.add_from(address); self } /// Adds a `From` header and stores the sender address - pub fn add_from(&mut self, address: A) { - let mailbox = address.to_mailbox(); + pub fn add_from(&mut self, address: A) { + let mailbox = address.into_mailbox(); self.from_header.push(Address::Mailbox(mailbox)); } /// Adds a `To` header and stores the recipient address - pub fn to(mut self, address: A) -> EmailBuilder { + pub fn to(mut self, address: A) -> EmailBuilder { self.add_to(address); self } /// Adds a `To` header and stores the recipient address - pub fn add_to(&mut self, address: A) { - let mailbox = address.to_mailbox(); + pub fn add_to(&mut self, address: A) { + let mailbox = address.into_mailbox(); self.to_header.push(Address::Mailbox(mailbox)); } /// Adds a `Cc` header and stores the recipient address - pub fn cc(mut self, address: A) -> EmailBuilder { + pub fn cc(mut self, address: A) -> EmailBuilder { self.add_cc(address); self } /// Adds a `Cc` header and stores the recipient address - pub fn add_cc(&mut self, address: A) { - let mailbox = address.to_mailbox(); + pub fn add_cc(&mut self, address: A) { + let mailbox = address.into_mailbox(); self.cc_header.push(Address::Mailbox(mailbox)); } + /// Adds a `Bcc` header and stores the recipient address + pub fn bcc(mut self, address: A) -> EmailBuilder { + self.add_bcc(address); + self + } + + /// Adds a `Bcc` header and stores the recipient address + pub fn add_bcc(&mut self, address: A) { + let mailbox = address.into_mailbox(); + self.bcc_header.push(Address::Mailbox(mailbox)); + } + /// Adds a `Reply-To` header - pub fn reply_to(mut self, address: A) -> EmailBuilder { + pub fn reply_to(mut self, address: A) -> EmailBuilder { self.add_reply_to(address); self } /// Adds a `Reply-To` header - pub fn add_reply_to(&mut self, address: A) { - let mailbox = address.to_mailbox(); + pub fn add_reply_to(&mut self, address: A) { + let mailbox = address.into_mailbox(); self.reply_to_header.push(Address::Mailbox(mailbox)); } /// Adds a `Sender` header - pub fn sender(mut self, address: A) -> EmailBuilder { + pub fn sender(mut self, address: A) -> EmailBuilder { self.set_sender(address); self } /// Adds a `Sender` header - pub fn set_sender(&mut self, address: A) { - let mailbox = address.to_mailbox(); + pub fn set_sender(&mut self, address: A) { + let mailbox = address.into_mailbox(); self.sender_header = Some(mailbox); } /// Adds a `Subject` header - pub fn subject(mut self, subject: &str) -> EmailBuilder { + pub fn subject>(mut self, subject: S) -> EmailBuilder { self.set_subject(subject); self } /// Adds a `Subject` header - pub fn set_subject(&mut self, subject: &str) { - self.message.add_header(("Subject", subject)); + pub fn set_subject>(&mut self, subject: S) { + self.message.add_header(("Subject".to_string(), subject.into())); } /// Adds a `Date` header with the given date @@ -492,7 +519,7 @@ 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().as_ref())); + self.message.add_header(("Date", Tm::rfc822z(date).to_string())); self.date_issued = true; } @@ -519,39 +546,44 @@ impl EmailBuilder { } /// Sets the email body to plain text content - pub fn text(mut self, body: &str) -> EmailBuilder { + pub fn text>(mut self, body: S) -> EmailBuilder { self.set_text(body); self } /// Sets the email body to plain text content - pub fn set_text(&mut self, body: &str) { + pub fn set_text>(&mut self, body: S) { self.message.set_body(body); self.message .add_header(("Content-Type", format!("{}", mime!(Text/Plain; Charset=Utf8)).as_ref())); } /// Sets the email body to HTML content - pub fn html(mut self, body: &str) -> EmailBuilder { + pub fn html>(mut self, body: S) -> EmailBuilder { self.set_html(body); self } /// Sets the email body to HTML content - pub fn set_html(&mut self, body: &str) { + pub fn set_html>(&mut self, body: S) { self.message.set_body(body); self.message .add_header(("Content-Type", format!("{}", mime!(Text/Html; Charset=Utf8)).as_ref())); } /// Sets the email content - pub fn alternative(mut self, body_html: &str, body_text: &str) -> EmailBuilder { + pub fn alternative, T: Into>(mut self, + body_html: S, + body_text: T) + -> EmailBuilder { self.set_alternative(body_html, body_text); self } /// Sets the email content - pub fn set_alternative(&mut self, body_html: &str, body_text: &str) { + pub fn set_alternative, T: Into>(&mut self, + body_html: S, + body_text: T) { let mut alternate = PartBuilder::new(); alternate.set_message_type(MimeMultipartType::Alternative); @@ -615,7 +647,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()) { + 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()), Address::Group(_, ref ms) => { @@ -667,12 +702,11 @@ impl EmailBuilder { 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(Header::new_with_value("Reply-To".into(), - self.reply_to_header) - .unwrap()); + self.message + .add_header(Header::new_with_value("Reply-To".into(), self.reply_to_header) + .unwrap()); } - if !self.date_issued { self.message.add_header(("Date", Tm::rfc822z(&now()).to_string().as_ref())); } @@ -700,13 +734,14 @@ pub trait SendableEmail { fn from_address(&self) -> String; /// To addresses fn to_addresses(&self) -> Vec; - /// Message content - fn message(&self) -> String; /// Message ID fn message_id(&self) -> String; + /// Message content + fn message(self) -> String; } /// Minimal email structure +#[derive(Debug)] pub struct SimpleSendableEmail { /// From address from: String, @@ -718,11 +753,14 @@ pub struct SimpleSendableEmail { impl SimpleSendableEmail { /// Returns a new email - pub fn new(from_address: &str, to_address: Vec, message: &str) -> SimpleSendableEmail { + pub fn new(from_address: String, + to_address: Vec, + message: String) + -> SimpleSendableEmail { SimpleSendableEmail { - from: from_address.to_string(), + from: from_address, to: to_address, - message: message.to_string(), + message: message, } } } @@ -736,13 +774,13 @@ impl SendableEmail for SimpleSendableEmail { self.to.clone() } - fn message(&self) -> String { - self.message.clone() - } - fn message_id(&self) -> String { format!("{}", Uuid::new_v4()) } + + fn message(self) -> String { + self.message + } } impl SendableEmail for Email { @@ -754,24 +792,50 @@ impl SendableEmail for Email { self.envelope.from.clone() } - fn message(&self) -> String { - format!("{}", self) - } - fn message_id(&self) -> String { format!("{}", self.message_id) } + + fn message(self) -> String { + self.to_string() + } } #[cfg(test)] mod test { use email_format::{Header, MimeMessage}; - use super::{Email, EmailBuilder, Envelope, SendableEmail}; + use super::{Email, EmailBuilder, Envelope, IntoEmail, SendableEmail, SimpleEmail}; use time::now; use uuid::Uuid; + #[test] + fn test_simple_email_builder() { + let email_builder = SimpleEmail::default(); + let date_now = now(); + + let email = email_builder.to("user@localhost") + .from("user@localhost") + .cc(("cc@localhost", "Alias")) + .reply_to("reply@localhost") + .text("Hello World!") + .date(date_now.clone()) + .subject("Hello") + .header(("X-test", "value")) + .into_email() + .unwrap(); + + assert_eq!(format!("{}", email), + format!("Subject: Hello\r\nContent-Type: text/plain; \ + charset=utf-8\r\nX-test: value\r\nTo: \r\nFrom: \ + \r\nCc: \"Alias\" \r\nReply-To: \ + \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())); + } + #[test] fn test_email_display() { let current_message = Uuid::new_v4(); @@ -825,7 +889,7 @@ mod test { } #[test] - fn test_simple_email_builder() { + fn test_email_builder() { let email_builder = EmailBuilder::new(); let date_now = now(); @@ -859,6 +923,7 @@ mod test { let email = email_builder.to("user@localhost") .from("user@localhost") .cc(("cc@localhost", "Alias")) + .bcc("bcc@localhost") .reply_to("reply@localhost") .sender("sender@localhost") .body("Hello World!") @@ -870,8 +935,11 @@ mod test { assert_eq!(email.from_address(), "sender@localhost".to_string()); assert_eq!(email.to_addresses(), - vec!["user@localhost".to_string(), "cc@localhost".to_string()]); - assert_eq!(email.message(), format!("{}", email)); + vec!["user@localhost".to_string(), + "cc@localhost".to_string(), + "bcc@localhost".to_string()]); + let content = format!("{}", email); + assert_eq!(email.message(), content); } } diff --git a/src/lib.rs b/src/lib.rs index 25ed52b..1029c49 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,8 +248,7 @@ //! Hello World! //! ``` - -#![deny(missing_docs, unsafe_code, unstable_features)] +#![deny(missing_docs, unsafe_code, unstable_features, warnings, missing_debug_implementations)] #[macro_use] extern crate log; diff --git a/src/transport/file/error.rs b/src/transport/file/error.rs index 694e3d7..e74f566 100644 --- a/src/transport/file/error.rs +++ b/src/transport/file/error.rs @@ -1,6 +1,5 @@ //! Error and result type for file transport - use self::Error::*; use std::error::Error as StdError; use std::fmt; diff --git a/src/transport/file/mod.rs b/src/transport/file/mod.rs index e5bc778..61dac35 100644 --- a/src/transport/file/mod.rs +++ b/src/transport/file/mod.rs @@ -5,13 +5,13 @@ use email::SendableEmail; use std::fs::File; use std::io::prelude::*; use std::path::{Path, PathBuf}; - use transport::EmailTransport; use transport::file::error::FileResult; pub mod error; /// Writes the content and the envelope information to a file +#[derive(Debug)] pub struct FileEmailTransport { path: PathBuf, } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index e884bb8..36d7998 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -1,4 +1,5 @@ //! Represents an Email transport + pub mod smtp; pub mod stub; pub mod file; diff --git a/src/transport/smtp/authentication.rs b/src/transport/smtp/authentication.rs index 9f75262..e119d44 100644 --- a/src/transport/smtp/authentication.rs +++ b/src/transport/smtp/authentication.rs @@ -3,12 +3,10 @@ use crypto::hmac::Hmac; use crypto::mac::Mac; use crypto::md5::Md5; - use rustc_serialize::base64::{self, FromBase64, ToBase64}; use rustc_serialize::hex::ToHex; use std::fmt; use std::fmt::{Display, Formatter}; - use transport::smtp::NUL; use transport::smtp::error::Error; diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs index 4a73f04..5cc4970 100644 --- a/src/transport/smtp/client/mod.rs +++ b/src/transport/smtp/client/mod.rs @@ -1,6 +1,5 @@ //! SMTP client - use bufstream::BufStream; use openssl::ssl::SslContext; use std::fmt::Debug; @@ -11,8 +10,7 @@ use std::string::String; use transport::smtp::{CRLF, MESSAGE_ENDING}; use transport::smtp::authentication::Mechanism; use transport::smtp::client::net::{Connector, NetworkStream}; - -use transport::smtp::error::{SmtpResult, Error}; +use transport::smtp::error::{Error, SmtpResult}; use transport::smtp::response::ResponseParser; pub mod net; diff --git a/src/transport/smtp/client/net.rs b/src/transport/smtp/client/net.rs index 3d340b1..2c91185 100644 --- a/src/transport/smtp/client/net.rs +++ b/src/transport/smtp/client/net.rs @@ -1,6 +1,5 @@ //! A trait to represent a stream - use openssl::ssl::{SslContext, SslStream}; use std::fmt; use std::fmt::{Debug, Formatter}; diff --git a/src/transport/smtp/error.rs b/src/transport/smtp/error.rs index 4cac2a6..ba04702 100644 --- a/src/transport/smtp/error.rs +++ b/src/transport/smtp/error.rs @@ -6,7 +6,6 @@ use std::error::Error as StdError; use std::fmt; use std::fmt::{Display, Formatter}; use std::io; - use transport::smtp::response::{Response, Severity}; /// An enum of all error kinds. diff --git a/src/transport/smtp/extension.rs b/src/transport/smtp/extension.rs index beb8e22..d2de9da 100644 --- a/src/transport/smtp/extension.rs +++ b/src/transport/smtp/extension.rs @@ -5,7 +5,6 @@ use std::fmt; use std::fmt::{Display, Formatter}; use std::result::Result; use transport::smtp::authentication::Mechanism; - use transport::smtp::error::Error; use transport::smtp::response::Response; diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index a9325d4..9df2ea9 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -1,15 +1,13 @@ //! This transport sends emails using the SMTP protocol use email::SendableEmail; - use openssl::ssl::{SslContext, SslMethod}; use std::net::{SocketAddr, ToSocketAddrs}; use std::string::String; use transport::EmailTransport; use transport::smtp::authentication::Mechanism; use transport::smtp::client::Client; - -use transport::smtp::error::{SmtpResult, Error}; +use transport::smtp::error::{Error, SmtpResult}; use transport::smtp::extension::{Extension, ServerInfo}; pub mod extension; @@ -65,6 +63,7 @@ pub enum SecurityLevel { } /// Contains client configuration +#[derive(Debug)] pub struct SmtpTransportBuilder { /// Maximum connection reuse /// @@ -152,8 +151,8 @@ impl SmtpTransportBuilder { } /// Set the name used during HELO or EHLO - pub fn hello_name(mut self, name: &str) -> SmtpTransportBuilder { - self.hello_name = name.to_string(); + pub fn hello_name>(mut self, name: S) -> SmtpTransportBuilder { + self.hello_name = name.into(); self } @@ -170,8 +169,11 @@ impl SmtpTransportBuilder { } /// Set the client credentials - pub fn credentials(mut self, username: &str, password: &str) -> SmtpTransportBuilder { - self.credentials = Some((username.to_string(), password.to_string())); + pub fn credentials>(mut self, + username: S, + password: S) + -> SmtpTransportBuilder { + self.credentials = Some((username.into(), password.into())); self } @@ -199,6 +201,7 @@ struct State { } /// Structure that implements the high level SMTP client +#[derive(Debug)] pub struct SmtpTransport { /// Information about the server /// Value is None before HELO/EHLO diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs index bcafb22..2c5dcef 100644 --- a/src/transport/smtp/response.rs +++ b/src/transport/smtp/response.rs @@ -2,14 +2,12 @@ //! message use self::Category::*; - use self::Severity::*; use std::fmt::{Display, Formatter, Result}; use std::result; use std::str::FromStr; use transport::smtp::error::{Error, SmtpResult}; - /// First digit indicates severity #[derive(PartialEq,Eq,Copy,Clone,Debug)] pub enum Severity { diff --git a/src/transport/stub/mod.rs b/src/transport/stub/mod.rs index c102979..df2caa0 100644 --- a/src/transport/stub/mod.rs +++ b/src/transport/stub/mod.rs @@ -7,6 +7,7 @@ use transport::EmailTransport; pub mod error; /// This transport does nothing except logging the message envelope +#[derive(Debug)] pub struct StubEmailTransport; /// SMTP result type