From a8324795e5b74c4d57b465bd70006d4cab1be700 Mon Sep 17 00:00:00 2001 From: David Raifaizen Date: Fri, 6 May 2016 20:04:32 -0400 Subject: [PATCH 1/2] style(all): Minor typo/grammar fixes --- src/email/mod.rs | 48 +++++++++++++++++----------------- src/lib.rs | 12 ++++----- src/transport/error.rs | 2 +- src/transport/file/mod.rs | 4 +-- src/transport/mod.rs | 2 +- src/transport/smtp/mod.rs | 8 +++--- src/transport/smtp/response.rs | 2 +- src/transport/stub/mod.rs | 4 +-- 8 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/email/mod.rs b/src/email/mod.rs index 3975e9c..0d1a179 100644 --- a/src/email/mod.rs +++ b/src/email/mod.rs @@ -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, - /// The enveloppe sender address + /// The envelope sender address from: Option, /// 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, - /// 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(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(&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(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(&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(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(&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 { - 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(), }, diff --git a/src/lib.rs b/src/lib.rs index 3cc957d..212b4bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(); //! ``` //! diff --git a/src/transport/error.rs b/src/transport/error.rs index 94fc827..2771673 100644 --- a/src/transport/error.rs +++ b/src/transport/error.rs @@ -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", } diff --git a/src/transport/file/mod.rs b/src/transport/file/mod.rs index fe3da5a..3ac6dfb 100644 --- a/src/transport/file/mod.rs +++ b/src/transport/file/mod.rs @@ -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, } diff --git a/src/transport/mod.rs b/src/transport/mod.rs index 95b4ac7..c371c30 100644 --- a/src/transport/mod.rs +++ b/src/transport/mod.rs @@ -11,6 +11,6 @@ use email::SendableEmail; pub trait EmailTransport { /// Sends the email fn send(&mut self, email: T) -> EmailResult; - /// Close the transport explicitely + /// Close the transport explicitly fn close(&mut self); } diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index ca05510..01a5650 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -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, } @@ -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(); diff --git a/src/transport/smtp/response.rs b/src/transport/smtp/response.rs index e784116..0a9810c 100644 --- a/src/transport/smtp/response.rs +++ b/src/transport/smtp/response.rs @@ -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)] diff --git a/src/transport/stub/mod.rs b/src/transport/stub/mod.rs index 6ca675f..46a9618 100644 --- a/src/transport/stub/mod.rs +++ b/src/transport/stub/mod.rs @@ -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 { From 4f4a1436aea78d3f6c9f756930e748bebdf028c8 Mon Sep 17 00:00:00 2001 From: David Raifaizen Date: Fri, 6 May 2016 20:47:03 -0400 Subject: [PATCH 2/2] refactor(client): Replacing manual unwrap with match statement --- src/transport/smtp/client/mod.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs index 81021cf..cd28019 100644 --- a/src/transport/smtp/client/mod.rs +++ b/src/transport/smtp/client/mod.rs @@ -80,10 +80,9 @@ impl Client { /// 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(()) } }