[pve-devel] [PATCH v4 proxmox 19/69] notify: sendmail: query default author/mailfrom from context

Lukas Wagner l.wagner at proxmox.com
Thu Jul 20 16:31:46 CEST 2023


Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 proxmox-notify/src/context.rs            |  2 ++
 proxmox-notify/src/endpoints/sendmail.rs | 18 +++++++++++++-----
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/proxmox-notify/src/context.rs b/proxmox-notify/src/context.rs
index c31a243b..4643f987 100644
--- a/proxmox-notify/src/context.rs
+++ b/proxmox-notify/src/context.rs
@@ -3,6 +3,8 @@ use std::fmt::Debug;
 
 pub trait Context: Send + Sync + Debug {
     fn lookup_email_for_user(&self, user: &str) -> Option<String>;
+    fn default_sendmail_author(&self) -> String;
+    fn default_sendmail_from(&self) -> String;
 }
 
 static CONTEXT: OnceCell<&'static dyn Context> = OnceCell::new();
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index 4e412a43..aba7150c 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -112,9 +112,17 @@ impl Endpoint for SendmailEndpoint {
         let text_part =
             renderer::render_template(TemplateRenderer::Plaintext, &notification.body, properties)?;
 
-        // proxmox_sys::email::sendmail will set the author to
-        // "Proxmox Backup Server" if it is not set.
-        let author = self.config.author.as_deref().or(Some(""));
+        let author = self
+            .config
+            .author
+            .clone()
+            .unwrap_or_else(|| context().default_sendmail_author());
+
+        let mailfrom = self
+            .config
+            .from_address
+            .clone()
+            .unwrap_or_else(|| context().default_sendmail_from());
 
         let recipients_str: Vec<&str> = recipients.iter().map(String::as_str).collect();
 
@@ -123,8 +131,8 @@ impl Endpoint for SendmailEndpoint {
             &subject,
             Some(&text_part),
             Some(&html_part),
-            self.config.from_address.as_deref(),
-            author,
+            Some(&mailfrom),
+            Some(&author),
         )
         .map_err(|err| Error::NotifyFailed(self.config.name.clone(), err.into()))
     }
-- 
2.39.2






More information about the pve-devel mailing list