From 7edbf7cf2026cdb28f0c3817d0dc412922e286fb Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Wed, 22 May 2024 13:56:52 +0100 Subject: [PATCH] refactor: [#599] extract types for config::v1::mail::Mail --- src/config/v1/mail.rs | 9 +++++---- src/mailer.rs | 4 ++-- src/web/api/client/v1/contexts/settings/mod.rs | 4 ++-- tests/common/contexts/settings/mod.rs | 4 ++-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/config/v1/mail.rs b/src/config/v1/mail.rs index 4e166281..45ed6145 100644 --- a/src/config/v1/mail.rs +++ b/src/config/v1/mail.rs @@ -1,3 +1,4 @@ +use lettre::message::Mailbox; use serde::{Deserialize, Serialize}; /// SMTP configuration. @@ -6,9 +7,9 @@ pub struct Mail { /// Whether or not to enable email verification on signup. pub email_verification_enabled: bool, /// The email address to send emails from. - pub from: String, + pub from: Mailbox, /// The email address to reply to. - pub reply_to: String, + pub reply_to: Mailbox, /// The username to use for SMTP authentication. pub username: String, /// The password to use for SMTP authentication. @@ -23,8 +24,8 @@ impl Default for Mail { fn default() -> Self { Self { email_verification_enabled: false, - from: "example@email.com".to_string(), - reply_to: "noreply@email.com".to_string(), + from: "example@email.com".parse().expect("valid mailbox"), + reply_to: "noreply@email.com".parse().expect("valid mailbox"), username: String::default(), password: String::default(), server: String::default(), diff --git a/src/mailer.rs b/src/mailer.rs index 39c1d0d4..d260729e 100644 --- a/src/mailer.rs +++ b/src/mailer.rs @@ -121,8 +121,8 @@ impl Service { let settings = self.cfg.settings.read().await; Message::builder() - .from(settings.mail.from.parse().unwrap()) - .reply_to(settings.mail.reply_to.parse().unwrap()) + .from(settings.mail.from.clone()) + .reply_to(settings.mail.reply_to.clone()) .to(to.parse().unwrap()) } diff --git a/src/web/api/client/v1/contexts/settings/mod.rs b/src/web/api/client/v1/contexts/settings/mod.rs index 44ba0b80..3b97b4b7 100644 --- a/src/web/api/client/v1/contexts/settings/mod.rs +++ b/src/web/api/client/v1/contexts/settings/mod.rs @@ -152,8 +152,8 @@ impl From for Mail { fn from(mail: DomainMail) -> Self { Self { email_verification_enabled: mail.email_verification_enabled, - from: mail.from, - reply_to: mail.reply_to, + from: mail.from.to_string(), + reply_to: mail.reply_to.to_string(), username: mail.username, password: mail.password, server: mail.server, diff --git a/tests/common/contexts/settings/mod.rs b/tests/common/contexts/settings/mod.rs index 4007e796..4a3b92cd 100644 --- a/tests/common/contexts/settings/mod.rs +++ b/tests/common/contexts/settings/mod.rs @@ -151,8 +151,8 @@ impl From for Mail { fn from(mail: DomainMail) -> Self { Self { email_verification_enabled: mail.email_verification_enabled, - from: mail.from, - reply_to: mail.reply_to, + from: mail.from.to_string(), + reply_to: mail.reply_to.to_string(), username: mail.username, password: mail.password, server: mail.server,