diff options
Diffstat (limited to 'src/mail.rs')
-rw-r--r-- | src/mail.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/mail.rs b/src/mail.rs index 7017654..d7df246 100644 --- a/src/mail.rs +++ b/src/mail.rs @@ -7,7 +7,6 @@ use tokio::process::Command; use crate::model::config::Config; static FROM_NAME: &str = "Budget"; -static FROM_ADDRESS: &str = "budget@guyonvarch.me"; #[derive(Clone)] pub struct Recipient { @@ -21,15 +20,15 @@ pub async fn send( subject: &str, message: &str, ) -> bool { - let headers = format_headers(recipients.clone(), subject); + let headers = format_headers(config, recipients.clone(), subject); log::info!( "Sending mail{}\n{}", - if config.mock_mails { " (MOCK)" } else { "" }, + if config.mails_mock { " (MOCK)" } else { "" }, headers.clone() ); - if config.mock_mails { + if config.mails_mock { true } else { let recipient_addresses = recipients @@ -41,7 +40,7 @@ pub async fn send( // https://github.com/NixOS/nixpkgs/issues/90248 let mut command = Command::new("/run/wrappers/bin/sendmail"); command.kill_on_drop(true); - command.arg("-f").arg(FROM_ADDRESS); + command.arg("-f").arg(config.mails_from.clone()); command.arg("--").args(recipient_addresses); command .stdin(Stdio::piped()) @@ -72,7 +71,11 @@ pub async fn send( } } -fn format_headers(recipients: Vec<Recipient>, subject: &str) -> String { +fn format_headers( + config: &Config, + recipients: Vec<Recipient>, + subject: &str, +) -> String { let recipients = recipients .into_iter() .map(|r| format_address(&r.name, &r.address)) @@ -82,7 +85,7 @@ fn format_headers(recipients: Vec<Recipient>, subject: &str) -> String { format!( "Date: {}\nFrom: {}\nTo: {}\nSubject: {}", Utc::now().to_rfc2822(), - format_address(FROM_NAME, FROM_ADDRESS), + format_address(FROM_NAME, &config.mails_from), recipients, subject, ) |