diff --git a/lettre/Cargo.toml b/lettre/Cargo.toml index 47c0c25..c51a59f 100644 --- a/lettre/Cargo.toml +++ b/lettre/Cargo.toml @@ -30,6 +30,7 @@ serde_json = { version = "^1.0", optional = true } serde_derive = { version = "^1.0", optional = true } failure = "^0.1" failure_derive = "^0.1" +fast_chemail = "^0.9" [dev-dependencies] env_logger = "^0.5" diff --git a/lettre/src/lib.rs b/lettre/src/lib.rs index 012b9ed..f34ac22 100644 --- a/lettre/src/lib.rs +++ b/lettre/src/lib.rs @@ -31,6 +31,7 @@ extern crate failure; extern crate serde_json; #[macro_use] extern crate failure_derive; +extern crate fast_chemail; pub mod error; #[cfg(feature = "file-transport")] @@ -58,6 +59,7 @@ use std::io; use std::io::Cursor; use std::io::Read; use std::str::FromStr; +use fast_chemail::is_valid_email; /// Email address #[derive(PartialEq, Eq, Clone, Debug)] @@ -65,9 +67,10 @@ use std::str::FromStr; pub struct EmailAddress(String); impl EmailAddress { - /// Creates a new `EmailAddress`. For now it makes no validation. pub fn new(address: String) -> EmailResult { - // TODO make some basic sanity checks + if !is_valid_email(&address) && !address.ends_with("localhost") { + Err(EmailError::InvalidEmailAddress)?; + } Ok(EmailAddress(address)) } }