diff --git a/src/address.rs b/src/address.rs index 03d3794..fd779d7 100644 --- a/src/address.rs +++ b/src/address.rs @@ -4,7 +4,7 @@ use idna::domain_to_ascii; use once_cell::sync::Lazy; use regex::Regex; use std::{ - convert::TryFrom, + convert::{TryFrom, TryInto}, error::Error, ffi::OsStr, fmt::{Display, Formatter, Result as FmtResult}, @@ -36,7 +36,16 @@ where fn try_from(from: (U, D)) -> Result { let (user, domain) = from; - Self::new(user, domain) + let user = user.into(); + Address::check_user(&user)?; + let domain = domain.into(); + Address::check_domain(&domain)?; + let complete = format!("{}@{}", &user, &domain); + Ok(Address { + user, + domain, + complete, + }) } } @@ -58,19 +67,10 @@ impl Address { /// Create email address from parts #[inline] pub fn new, D: Into>(user: U, domain: D) -> Result { - let user = user.into(); - Address::check_user(&user)?; - let domain = domain.into(); - Address::check_domain(&domain)?; - let complete = format!("{}@{}", &user, &domain); - Ok(Address { - user, - domain, - complete, - }) + (user, domain).try_into() } - pub fn check_user(user: &str) -> Result<(), AddressError> { + fn check_user(user: &str) -> Result<(), AddressError> { if USER_RE.is_match(user) { Ok(()) } else { @@ -78,7 +78,7 @@ impl Address { } } - pub fn check_domain(domain: &str) -> Result<(), AddressError> { + fn check_domain(domain: &str) -> Result<(), AddressError> { Address::check_domain_ascii(domain).or_else(|_| { domain_to_ascii(domain) .map_err(|_| AddressError::InvalidDomain) @@ -280,3 +280,5 @@ pub mod serde { } } } + +// FIXME test serializer deserializer diff --git a/src/error.rs b/src/error.rs index 125aa6e..6c8c6c4 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ use std::{ fmt::{self, Display, Formatter}, }; +// FIXME message-specific errors /// Error type for email content #[derive(Debug)] pub enum Error { @@ -45,8 +46,4 @@ impl From for Error { } } -impl StdError for Error { - fn source(&self) -> Option<&(dyn StdError + 'static)> { - None - } -} +impl StdError for Error {} diff --git a/src/transport/smtp/mod.rs b/src/transport/smtp/mod.rs index f3b67b6..477d31c 100644 --- a/src/transport/smtp/mod.rs +++ b/src/transport/smtp/mod.rs @@ -36,6 +36,8 @@ use std::{ time::Duration, }; use uuid::Uuid; +#[cfg(feature = "rustls")] +use webpki_roots::TLS_SERVER_ROOTS; pub mod authentication; pub mod client; @@ -168,7 +170,12 @@ impl SmtpClient { #[cfg(feature = "rustls")] pub fn new_simple(domain: &str) -> Result { - let tls_parameters = ClientTlsParameters::new(domain.to_string(), ClientConfig::new()); + let mut tls = ClientConfig::new(); + tls.config + .root_store + .add_server_trust_anchors(&TLS_SERVER_ROOTS); + + let tls_parameters = ClientTlsParameters::new(domain.to_string(), tls); SmtpClient::new( (domain, SUBMISSIONS_PORT),