Skip to content

Commit

Permalink
refactor: [#599] extract types for config::v1::mail::Mail
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed May 23, 2024
1 parent 748f357 commit 7edbf7c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/config/v1/mail.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use lettre::message::Mailbox;
use serde::{Deserialize, Serialize};

/// SMTP configuration.
Expand All @@ -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.
Expand All @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions src/mailer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}

Expand Down
4 changes: 2 additions & 2 deletions src/web/api/client/v1/contexts/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl From<DomainMail> 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,
Expand Down
4 changes: 2 additions & 2 deletions tests/common/contexts/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ impl From<DomainMail> 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,
Expand Down

0 comments on commit 7edbf7c

Please sign in to comment.