From 86baa0c2b7bb8542360a5eef7ffcc5cbf7178486 Mon Sep 17 00:00:00 2001 From: Mani Chandra Dulam Date: Mon, 18 Nov 2024 18:40:41 +0530 Subject: [PATCH] feat: add `to_lowercase` in `UserEmail` --- crates/router/src/types/domain/user.rs | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/crates/router/src/types/domain/user.rs b/crates/router/src/types/domain/user.rs index c48fe3320f3..35e9dd85496 100644 --- a/crates/router/src/types/domain/user.rs +++ b/crates/router/src/types/domain/user.rs @@ -103,7 +103,7 @@ impl UserEmail { pub fn new(email: Secret) -> UserResult { use validator::ValidateEmail; - let email_string = email.expose(); + let email_string = email.expose().to_lowercase(); let email = pii::Email::from_str(&email_string).change_context(UserErrors::EmailParsingError)?; @@ -123,21 +123,8 @@ impl UserEmail { } pub fn from_pii_email(email: pii::Email) -> UserResult { - use validator::ValidateEmail; - - let email_string = email.peek(); - if email_string.validate_email() { - let (_username, domain) = match email_string.split_once('@') { - Some((u, d)) => (u, d), - None => return Err(UserErrors::EmailParsingError.into()), - }; - if BLOCKED_EMAIL.contains(domain) { - return Err(UserErrors::InvalidEmailError.into()); - } - Ok(Self(email)) - } else { - Err(UserErrors::EmailParsingError.into()) - } + let email_string = email.expose().map(|inner| inner.to_lowercase()); + Self::new(email_string) } pub fn into_inner(self) -> pii::Email {