From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id D52301FF0B7 for ; Fri, 13 Nov 2026 16:15:10 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1ACB821B69; Fri, 13 Nov 2026 16:10:11 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox 27/55] notify: fold mail-forwarder feature into send-impl Date: Fri, 13 Nov 2026 16:08:00 +0100 Message-ID: <20261113150828.756836-28-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261113150828.756836-1-l.wagner@proxmox.com> References: <20261113150828.756836-1-l.wagner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794582526452 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.206 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: VNPSED4I2MX4LQKUA3WYTU2VUNCQIWE5 X-Message-ID-Hash: VNPSED4I2MX4LQKUA3WYTU2VUNCQIWE5 X-MailFrom: l.wagner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In the future, all users of proxmox-notify will use a single notification worker to process queued notifications, which includes forwarded mails as well. Hence it makes sense to merge both features. The subject and body of the forwarded mail is now only parsed when the mail is actually processed by an endpoint implementation, this makes sure that the basic Notification type does not depend on the mail-parser crate. Signed-off-by: Lukas Wagner --- proxmox-notify/Cargo.toml | 3 ++- proxmox-notify/src/endpoints/common/mail.rs | 13 +++++++++++++ proxmox-notify/src/endpoints/gotify.rs | 5 +++-- proxmox-notify/src/endpoints/sendmail.rs | 1 - proxmox-notify/src/endpoints/smtp.rs | 3 --- proxmox-notify/src/endpoints/webhook.rs | 5 +++-- proxmox-notify/src/notification.rs | 16 +--------------- 7 files changed, 22 insertions(+), 24 deletions(-) diff --git a/proxmox-notify/Cargo.toml b/proxmox-notify/Cargo.toml index ca5dc5d45..1971f5b60 100644 --- a/proxmox-notify/Cargo.toml +++ b/proxmox-notify/Cargo.toml @@ -66,6 +66,7 @@ send-impl = [ "dep:lettre", "dep:handlebars", "dep:proxmox-config-digest", + "dep:mail-parser", "dep:percent-encoding", "dep:proxmox-base64", "dep:proxmox-http", @@ -73,9 +74,9 @@ send-impl = [ "dep:proxmox-human-byte", "dep:proxmox-section-config", "dep:proxmox-sendmail", + "proxmox-sendmail/mail-forwarder", "dep:proxmox-sys", ] -mail-forwarder = ["dep:mail-parser", "dep:proxmox-sys", "proxmox-sendmail/mail-forwarder"] pve-context = ["dep:proxmox-sys", "legacy-matchers"] pbs-context = ["dep:proxmox-sys", "legacy-matchers"] legacy-matchers = [] diff --git a/proxmox-notify/src/endpoints/common/mail.rs b/proxmox-notify/src/endpoints/common/mail.rs index 736f2ac66..fac4e759c 100644 --- a/proxmox-notify/src/endpoints/common/mail.rs +++ b/proxmox-notify/src/endpoints/common/mail.rs @@ -1,4 +1,5 @@ use crate::Context; +use crate::Error; /// Get list of email recipients from a list of email addresses and users. /// @@ -34,6 +35,18 @@ pub(crate) fn get_recipients( recipients } +/// Parse raw email message and return subject and plaintext body +pub(crate) fn parse_subject_and_plaintext_body(raw_mail: &[u8]) -> Result<(String, String), Error> { + let message = mail_parser::MessageParser::default() + .parse(raw_mail) + .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?; + + let title = message.subject().unwrap_or_default().into(); + let body = message.body_text(0).unwrap_or_default().into(); + + Ok((title, body)) +} + #[cfg(test)] mod tests { use crate::context::test; diff --git a/proxmox-notify/src/endpoints/gotify.rs b/proxmox-notify/src/endpoints/gotify.rs index cf7d4cc68..bdb1e487d 100644 --- a/proxmox-notify/src/endpoints/gotify.rs +++ b/proxmox-notify/src/endpoints/gotify.rs @@ -7,6 +7,7 @@ use proxmox_http::client::sync::Client; use proxmox_http::{HttpClient, HttpOptions}; use crate::api_types::{GotifyConfig, GotifyPrivateConfig}; +use crate::endpoints::common::mail; use crate::renderer::TemplateType; use crate::{Content, Context, Error, Notification, Severity, renderer}; @@ -48,8 +49,8 @@ impl Endpoint for GotifyEndpoint { (rendered_title, rendered_message) } - #[cfg(feature = "mail-forwarder")] - Content::ForwardedMail { title, body, .. } => (title.clone(), body.clone()), + + Content::ForwardedMail { raw, .. } => mail::parse_subject_and_plaintext_body(raw)?, }; // We don't have a TemplateRenderer::Markdown yet, so simply put everything diff --git a/proxmox-notify/src/endpoints/sendmail.rs b/proxmox-notify/src/endpoints/sendmail.rs index bbed31b4f..0bad792f7 100644 --- a/proxmox-notify/src/endpoints/sendmail.rs +++ b/proxmox-notify/src/endpoints/sendmail.rs @@ -63,7 +63,6 @@ impl Endpoint for SendmailEndpoint { Error::other_with_source("could not send mail via sendmail", err) }) } - #[cfg(feature = "mail-forwarder")] Content::ForwardedMail { raw, uid, .. } => { Mail::forward(&recipients_str, &mailfrom, raw, *uid).map_err(|err| { Error::other_with_source("could not forward mail via sendmail", err) diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs index fa0810fbb..43dc1f7f4 100644 --- a/proxmox-notify/src/endpoints/smtp.rs +++ b/proxmox-notify/src/endpoints/smtp.rs @@ -132,7 +132,6 @@ impl Endpoint for SmtpEndpoint { Error::invalid_config_with_source("could not build email message", err) })? } - #[cfg(feature = "mail-forwarder")] Content::ForwardedMail { raw, .. } => build_forwarded_message(email_builder, raw)?, }; @@ -161,7 +160,6 @@ impl Endpoint for SmtpEndpoint { } /// Construct a lettre `Message` from a raw email message. -#[cfg(feature = "mail-forwarder")] fn build_forwarded_message( email_builder: lettre::message::MessageBuilder, raw: &[u8], @@ -312,7 +310,6 @@ mod tests { ); } - #[cfg(feature = "mail-forwarder")] #[test] fn test_forward_message_from_raw() { use lettre::message::header::Date; diff --git a/proxmox-notify/src/endpoints/webhook.rs b/proxmox-notify/src/endpoints/webhook.rs index da2e189b4..2eaa71633 100644 --- a/proxmox-notify/src/endpoints/webhook.rs +++ b/proxmox-notify/src/endpoints/webhook.rs @@ -21,6 +21,7 @@ use proxmox_http::client::sync::Client; use proxmox_http::{HttpClient, HttpOptions}; use crate::api_types::{HttpMethod, WebhookConfig, WebhookPrivateConfig}; +use crate::endpoints::common::mail; use crate::renderer::TemplateType; use crate::{Content, Context, Error, Notification, renderer}; @@ -93,8 +94,8 @@ impl WebhookEndpoint { (rendered_title, rendered_message) } - #[cfg(feature = "mail-forwarder")] - Content::ForwardedMail { title, body, .. } => (title.clone(), body.clone()), + + Content::ForwardedMail { raw, .. } => mail::parse_subject_and_plaintext_body(raw)?, }; let mut fields = Map::new(); diff --git a/proxmox-notify/src/notification.rs b/proxmox-notify/src/notification.rs index 426a2259a..f5b6ab6a6 100644 --- a/proxmox-notify/src/notification.rs +++ b/proxmox-notify/src/notification.rs @@ -62,15 +62,10 @@ pub enum Content { /// Data that can be used for template rendering. data: Value, }, - #[cfg(feature = "mail-forwarder")] #[serde(rename_all = "kebab-case")] ForwardedMail { /// Raw mail contents raw: Vec, - /// Fallback title - title: String, - /// Fallback body - body: String, /// UID to use when calling sendmail #[allow(dead_code)] // Unused in some feature flag permutations uid: Option, @@ -120,15 +115,8 @@ impl Notification { id: Uuid::generate(), } } - #[cfg(feature = "mail-forwarder")] + pub fn new_forwarded_mail(raw_mail: &[u8], uid: Option) -> Result { - let message = mail_parser::MessageParser::default() - .parse(raw_mail) - .ok_or_else(|| Error::invalid_forwarded_message("could not parse forwarded email"))?; - - let title = message.subject().unwrap_or_default().into(); - let body = message.body_text(0).unwrap_or_default().into(); - let mut additional_fields = HashMap::new(); additional_fields.insert("hostname".into(), proxmox_sys::nodename().into()); additional_fields.insert("type".into(), "system-mail".into()); @@ -139,8 +127,6 @@ impl Notification { // it is not filtered out. content: Content::ForwardedMail { raw: raw_mail.into(), - title, - body, uid, }, metadata: Metadata { -- 2.47.3