Skip to content

Commit

Permalink
Merge pull request #311 from stammw/master
Browse files Browse the repository at this point in the history
check email validity before creating any new EmailAddress #308
  • Loading branch information
amousset committed Oct 3, 2018
2 parents fc91bb6 + e08d4e3 commit c988b17
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions lettre/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 5 additions & 2 deletions lettre/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -58,16 +59,18 @@ 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)]
#[cfg_attr(feature = "serde-impls", derive(Serialize, Deserialize))]
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))
}
}
Expand Down

0 comments on commit c988b17

Please sign in to comment.