diff --git a/src/api/core/sends.rs b/src/api/core/sends.rs index 6b11dbd5..0b45f319 100644 --- a/src/api/core/sends.rs +++ b/src/api/core/sends.rs @@ -535,7 +535,7 @@ async fn update_send_from_data( send.expiration_date = data.expiration_date.map(|d| d.naive_utc()); send.hide_email = data.hide_email.unwrap_or(false); send.disabled = data.disabled; - send.emails = data.emails.map(|e| e.to_lowercase()); + send.emails = data.emails.map(|e| e.trim().to_lowercase()).filter(|e| !e.is_empty()); // Only change the value if it's present if let Some(password) = data.password { diff --git a/src/auth/send.rs b/src/auth/send.rs index c293e01e..c53f577e 100644 --- a/src/auth/send.rs +++ b/src/auth/send.rs @@ -104,8 +104,8 @@ impl SendTokens { if let Some(mut split) = send.emails.as_ref().map(|s| s.split(',')) { let now = Utc::now().naive_utc(); - match email.as_ref() { - Some(e) if split.any(|s| s == e) => { + match email.map(|e| e.trim().to_lowercase()) { + Some(e) if split.any(|s| s.trim() == e) => { if let Some(code) = otp { if let Some(db_otp) = o_otp { if crypto::ct_eq(&code, &db_otp.code) && now < db_otp.expiration_date { @@ -124,8 +124,8 @@ impl SendTokens { } else { // SEND OTP CODE let code = crypto::generate_email_token(CONFIG.email_token_size()); - SendOTP::new(send_id, e, code.clone()).save(conn).await?; - mail::send_sends_otp(e, &code).await?; + SendOTP::new(send_id, &e, code.clone()).save(conn).await?; + mail::send_sends_otp(&e, &code).await?; } return Self::expected_error("Email OTP required", "email_and_otp_required"); } diff --git a/src/db/models/send.rs b/src/db/models/send.rs index b27a7650..5c1677d0 100644 --- a/src/db/models/send.rs +++ b/src/db/models/send.rs @@ -102,7 +102,7 @@ impl Send { max_access_count, access_count: 0, - emails: emails.map(|e| e.to_lowercase()), + emails: emails.map(|e| e.trim().to_lowercase()).filter(|e| !e.is_empty()), creation_date: now, revision_date: now,