Merge pull request #64 from craftytrickster/improvements

Improvements
This commit is contained in:
Alexis Mousset
2016-05-07 08:02:34 +02:00
9 changed files with 44 additions and 45 deletions
+24 -24
View File
@@ -8,7 +8,7 @@ use mime::Mime;
use time::{Tm, now};
use uuid::Uuid;
/// Converts an adress or an address with an alias to a `Address`
/// Converts an address or an address with an alias to a `Header`
pub trait ToHeader {
/// Converts to a `Header` struct
fn to_header(&self) -> Header;
@@ -16,7 +16,7 @@ pub trait ToHeader {
impl ToHeader for Header {
fn to_header(&self) -> Header {
(*self).clone()
self.clone()
}
}
@@ -64,9 +64,9 @@ pub struct PartBuilder {
pub struct EmailBuilder {
/// Message
message: PartBuilder,
/// The enveloppe recipients addresses
/// The envelope recipients' addresses
to: Vec<String>,
/// The enveloppe sender address
/// The envelope sender address
from: Option<String>,
/// Date issued
date_issued: bool,
@@ -74,10 +74,10 @@ pub struct EmailBuilder {
/// todo
#[derive(PartialEq,Eq,Clone,Debug)]
pub struct Enveloppe {
/// The enveloppe recipients addresses
pub struct Envelope {
/// The envelope recipients' addresses
to: Vec<String>,
/// The enveloppe sender address
/// The envelope sender address
from: String,
}
@@ -86,8 +86,8 @@ pub struct Enveloppe {
pub struct Email {
/// Message
message: MimeMessage,
/// Enveloppe
enveloppe: Enveloppe,
/// Envelope
envelope: Envelope,
/// Message-ID
message_id: Uuid,
}
@@ -202,39 +202,39 @@ impl EmailBuilder {
self.message.add_header(header);
}
/// Adds a `From` header and store the sender address
/// Adds a `From` header and stores the sender address
pub fn from<A: ToMailbox>(mut self, address: A) -> EmailBuilder {
self.add_from(address);
self
}
/// Adds a `From` header and store the sender address
/// Adds a `From` header and stores the sender address
pub fn add_from<A: ToMailbox>(&mut self, address: A) {
let mailbox = address.to_mailbox();
self.message.add_header(("From", mailbox.to_string().as_ref()));
self.from = Some(mailbox.address);
}
/// Adds a `To` header and store the recipient address
/// Adds a `To` header and stores the recipient address
pub fn to<A: ToMailbox>(mut self, address: A) -> EmailBuilder {
self.add_to(address);
self
}
/// Adds a `To` header and store the recipient address
/// Adds a `To` header and stores the recipient address
pub fn add_to<A: ToMailbox>(&mut self, address: A) {
let mailbox = address.to_mailbox();
self.message.add_header(("To", mailbox.to_string().as_ref()));
self.to.push(mailbox.address);
}
/// Adds a `Cc` header and store the recipient address
/// Adds a `Cc` header and stores the recipient address
pub fn cc<A: ToMailbox>(mut self, address: A) -> EmailBuilder {
self.add_cc(address);
self
}
/// Adds a `Cc` header and store the recipient address
/// Adds a `Cc` header and stores the recipient address
pub fn add_cc<A: ToMailbox>(&mut self, address: A) {
let mailbox = address.to_mailbox();
self.message.add_header(("Cc", mailbox.to_string().as_ref()));
@@ -311,26 +311,26 @@ impl EmailBuilder {
self.message.add_child(child);
}
/// Sets the email body to a plain text content
/// Sets the email body to plain text content
pub fn text(mut self, body: &str) -> EmailBuilder {
self.set_text(body);
self
}
/// Sets the email body to a plain text content
/// Sets the email body to plain text content
pub fn set_text(&mut self, body: &str) {
self.message.set_body(body);
self.message
.add_header(("Content-Type", format!("{}", mime!(Text/Plain; Charset=Utf8)).as_ref()));
}
/// Sets the email body to a HTML contect
/// Sets the email body to HTML content
pub fn html(mut self, body: &str) -> EmailBuilder {
self.set_html(body);
self
}
/// Sets the email body to a HTML contect
/// Sets the email body to HTML content
pub fn set_html(&mut self, body: &str) {
self.message.set_body(body);
self.message
@@ -392,7 +392,7 @@ impl EmailBuilder {
Ok(Email {
message: self.message.build(),
enveloppe: Enveloppe {
envelope: Envelope {
to: self.to,
from: self.from.unwrap(),
},
@@ -454,11 +454,11 @@ impl SendableEmail for SimpleSendableEmail {
impl SendableEmail for Email {
fn to_addresses(&self) -> Vec<String> {
self.enveloppe.to.clone()
self.envelope.to.clone()
}
fn from_address(&self) -> String {
self.enveloppe.from.clone()
self.envelope.from.clone()
}
fn message(&self) -> String {
@@ -477,7 +477,7 @@ mod test {
use uuid::Uuid;
use email_format::{Header, MimeMessage};
use super::{Email, EmailBuilder, Enveloppe, SendableEmail};
use super::{Email, EmailBuilder, Envelope, SendableEmail};
#[test]
fn test_email_display() {
@@ -485,7 +485,7 @@ mod test {
let mut email = Email {
message: MimeMessage::new_blank_message(),
enveloppe: Enveloppe {
envelope: Envelope {
to: vec![],
from: "".to_string(),
},
+6 -6
View File
@@ -18,7 +18,7 @@
//!
//! // Create an email
//! let email = EmailBuilder::new()
//! // Addresses can be specified by the couple (email, alias)
//! // Addresses can be specified by the tuple (email, alias)
//! .to(("user@example.org", "Firstname Lastname"))
//! // ... or by an address only
//! .from("user@example.com")
@@ -34,7 +34,7 @@
//! then generate an `Email` that can be sent.
//!
//! The `text()` method will create a plain text email, while the `html()` method will create an
//! HTML email. You can use the `alternative()` method to provide both version, using plain text
//! HTML email. You can use the `alternative()` method to provide both versions, using plain text
//! as fallback for the HTML version.
//!
//! Below is a more complete example, not using method chaining:
@@ -61,7 +61,7 @@
//!
//! ## Sending messages
//!
//! The following sections describe the available transport methods to treat emails.
//! The following sections describe the available transport methods to handle emails.
//!
//! * The `SmtpTransport` uses the SMTP protocol to send the message over the network. It is
//! the prefered way of sending emails.
@@ -142,9 +142,9 @@
//! // Specify a TLS security level. You can also specify an SslContext with
//! // .ssl_context(SslContext::Ssl23)
//! .security_level(SecurityLevel::AlwaysEncrypt)
//! // Enable SMTPUTF8 is the server supports it
//! // Enable SMTPUTF8 if the server supports it
//! .smtp_utf8(true)
//! // Configure accepted authetication mechanisms
//! // Configure accepted authentication mechanisms
//! .authentication_mechanisms(vec![Mechanism::CramMd5])
//! // Enable connection reuse
//! .connection_reuse(true).build();
@@ -156,7 +156,7 @@
//! let result_2 = mailer.send(email);
//! assert!(result_2.is_ok());
//!
//! // Explicitely close the SMTP transaction as we enabled connection reuse
//! // Explicitly close the SMTP transaction as we enabled connection reuse
//! mailer.close();
//! ```
//!
+1 -1
View File
@@ -45,7 +45,7 @@ impl StdError for Error {
PermanentError(_) => "a permanent error occured during the SMTP transaction",
ResponseParsingError(_) => "an error occured while parsing an SMTP response",
ChallengeParsingError(_) => "an error occured while parsing a CRAM-MD5 challenge",
ResolutionError => "Could no resolve hostname",
ResolutionError => "could not resolve hostname",
ClientError(_) => "an unknown error occured",
IoError(_) => "an I/O error occured",
}
+2 -2
View File
@@ -1,4 +1,4 @@
//! This transport creates a file for each email, containing the enveloppe information and the email
//! This transport creates a file for each email, containing the envelope information and the email
//! itself.
use std::path::{Path, PathBuf};
@@ -11,7 +11,7 @@ use transport::smtp::response::Response;
use transport::smtp::response::{Category, Code, Severity};
use email::SendableEmail;
/// Writes the content and the enveloppe information to a file
/// Writes the content and the envelope information to a file
pub struct FileEmailTransport {
path: PathBuf,
}
+1 -1
View File
@@ -11,6 +11,6 @@ use email::SendableEmail;
pub trait EmailTransport {
/// Sends the email
fn send<T: SendableEmail>(&mut self, email: T) -> EmailResult;
/// Close the transport explicitely
/// Close the transport explicitly
fn close(&mut self);
}
+3 -4
View File
@@ -80,10 +80,9 @@ impl<S: Connector + Write + Read + Debug + Clone> Client<S> {
/// Upgrades the underlying connection to SSL/TLS
pub fn upgrade_tls_stream(&mut self, ssl_context: &SslContext) -> io::Result<()> {
if self.stream.is_some() {
self.stream.as_mut().unwrap().get_mut().upgrade_tls(ssl_context)
} else {
Ok(())
match self.stream {
Some(ref mut stream) => stream.get_mut().upgrade_tls(ssl_context),
None => Ok(())
}
}
+4 -4
View File
@@ -77,13 +77,13 @@ pub struct SmtpTransportBuilder {
credentials: Option<(String, String)>,
/// Socket we are connecting to
server_addr: SocketAddr,
/// SSL contexyt to use
/// SSL context to use
ssl_context: SslContext,
/// TLS security level
security_level: SecurityLevel,
/// Enable UTF8 mailboxes in enveloppe or headers
/// Enable UTF8 mailboxes in envelope or headers
smtp_utf8: bool,
/// List of authentication mechanism, sorted by priority
/// List of authentication mechanisms, sorted by priority
authentication_mechanisms: Vec<Mechanism>,
}
@@ -228,7 +228,7 @@ macro_rules! try_smtp (
impl SmtpTransport {
/// Creates a new SMTP client
///
/// It does not connects to the server, but only creates the `SmtpTransport`
/// It does not connect to the server, but only creates the `SmtpTransport`
pub fn new(builder: SmtpTransportBuilder) -> SmtpTransport {
let client = Client::new();
+1 -1
View File
@@ -202,7 +202,7 @@ impl ResponseParser {
}
}
/// Contains an SMTP reply, with separed code and message
/// Contains an SMTP reply, with separated code and message
///
/// The text message is optional, only the code is mandatory
#[derive(PartialEq,Eq,Clone,Debug)]
+2 -2
View File
@@ -1,12 +1,12 @@
//! This transport is a stub that only logs the message, and always returns
//! succes
//! success
use transport::error::EmailResult;
use transport::smtp::response::{Category, Code, Response, Severity};
use transport::EmailTransport;
use email::SendableEmail;
/// This transport does nothing except logging the message enveloppe
/// This transport does nothing except logging the message envelope
pub struct StubEmailTransport;
impl EmailTransport for StubEmailTransport {