Skip to content

Commit 7edbf7c

Browse files
committed
refactor: [#599] extract types for config::v1::mail::Mail
1 parent 748f357 commit 7edbf7c

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

src/config/v1/mail.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use lettre::message::Mailbox;
12
use serde::{Deserialize, Serialize};
23

34
/// SMTP configuration.
@@ -6,9 +7,9 @@ pub struct Mail {
67
/// Whether or not to enable email verification on signup.
78
pub email_verification_enabled: bool,
89
/// The email address to send emails from.
9-
pub from: String,
10+
pub from: Mailbox,
1011
/// The email address to reply to.
11-
pub reply_to: String,
12+
pub reply_to: Mailbox,
1213
/// The username to use for SMTP authentication.
1314
pub username: String,
1415
/// The password to use for SMTP authentication.
@@ -23,8 +24,8 @@ impl Default for Mail {
2324
fn default() -> Self {
2425
Self {
2526
email_verification_enabled: false,
26-
from: "[email protected]".to_string(),
27-
reply_to: "[email protected]".to_string(),
27+
from: "[email protected]".parse().expect("valid mailbox"),
28+
reply_to: "[email protected]".parse().expect("valid mailbox"),
2829
username: String::default(),
2930
password: String::default(),
3031
server: String::default(),

src/mailer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ impl Service {
121121
let settings = self.cfg.settings.read().await;
122122

123123
Message::builder()
124-
.from(settings.mail.from.parse().unwrap())
125-
.reply_to(settings.mail.reply_to.parse().unwrap())
124+
.from(settings.mail.from.clone())
125+
.reply_to(settings.mail.reply_to.clone())
126126
.to(to.parse().unwrap())
127127
}
128128

src/web/api/client/v1/contexts/settings/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ impl From<DomainMail> for Mail {
152152
fn from(mail: DomainMail) -> Self {
153153
Self {
154154
email_verification_enabled: mail.email_verification_enabled,
155-
from: mail.from,
156-
reply_to: mail.reply_to,
155+
from: mail.from.to_string(),
156+
reply_to: mail.reply_to.to_string(),
157157
username: mail.username,
158158
password: mail.password,
159159
server: mail.server,

tests/common/contexts/settings/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ impl From<DomainMail> for Mail {
151151
fn from(mail: DomainMail) -> Self {
152152
Self {
153153
email_verification_enabled: mail.email_verification_enabled,
154-
from: mail.from,
155-
reply_to: mail.reply_to,
154+
from: mail.from.to_string(),
155+
reply_to: mail.reply_to.to_string(),
156156
username: mail.username,
157157
password: mail.password,
158158
server: mail.server,

0 commit comments

Comments
 (0)