[pve-devel] [PATCH v3 proxmox 17/66] notify: sendmail: query default author/mailfrom from context
Lukas Wagner
l.wagner at proxmox.com
Mon Jul 17 17:00:02 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 25be949a..8b55a2d0 100644
--- a/proxmox-notify/src/context.rs
+++ b/proxmox-notify/src/context.rs
@@ -2,6 +2,8 @@ use std::sync::Mutex;
pub trait Context: Send + Sync {
fn lookup_email_for_user(&self, user: &str) -> Option<String>;
+ fn default_sendmail_author(&self) -> String;
+ fn default_sendmail_from(&self) -> String;
}
static CONTEXT: Mutex<Option<&'static dyn Context>> = Mutex::new(None);
diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs
index c2b44b2d..850f48f8 100644
--- a/proxmox-notify/src/endpoints/sendmail.rs
+++ b/proxmox-notify/src/endpoints/sendmail.rs
@@ -111,9 +111,17 @@ impl Endpoint for SendmailEndpoint {
let text_part =
renderer::render_template(TemplateRenderer::Plaintext, ¬ification.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();
@@ -122,8 +130,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