Merge pull request #311 from stammw/master
check email validity before creating any new EmailAddress #308
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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<EmailAddress> {
|
||||
// TODO make some basic sanity checks
|
||||
if !is_valid_email(&address) && !address.ends_with("localhost") {
|
||||
Err(EmailError::InvalidEmailAddress)?;
|
||||
}
|
||||
Ok(EmailAddress(address))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user