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 7D3741FF0C0 for ; Wed, 18 Nov 2026 10:51:10 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 6F4DC21D36; Wed, 18 Nov 2026 10:45:10 +0100 (CET) From: Lukas Wagner To: pve-devel@lists.proxmox.com Subject: [PATCH proxmox-mail-forward v2 58/63] use return code to signal permanent or temporary failure Date: Wed, 18 Nov 2026 10:43:42 +0100 Message-ID: <20261118094348.273646-59-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118094348.273646-1-l.wagner@proxmox.com> References: <20261118094348.273646-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: 1794995042411 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.187 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: WKE2W3RILXJEJ6FICPGODD7GKLSTS4SH X-Message-ID-Hash: WKE2W3RILXJEJ6FICPGODD7GKLSTS4SH 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: Previously, we returned 0 if there was an error, giving Postfix no indication that the delivery of the notification failed. By returning EX_TEMPFAIL (75) we signal Postfix to retry later, by returning EX_DATAERR (65), we let the mail bounce. Signed-off-by: Lukas Wagner --- src/main.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index d388134..8a60df9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,6 +24,7 @@ use std::io::Read; use std::path::Path; +use std::process::ExitCode; use anyhow::Context; use anyhow::Error; @@ -42,6 +43,37 @@ use proxmox_notify::Severity; use proxmox_notify::queue::QueueSubmitter; use proxmox_sys::fs::CreateOptions; +enum ForwardError { + Temporary(Error), + Bounce(Error), +} + +impl From for ExitCode { + fn from(value: ForwardError) -> Self { + match value { + // EX_TEMPFAIL -> postfix retries later + ForwardError::Temporary(_) => ExitCode::from(75), + // EX_DATAERR -> mail bounces + ForwardError::Bounce(_) => ExitCode::from(65), + } + } +} + +impl std::fmt::Display for ForwardError { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + ForwardError::Temporary(error) => write!( + f, + "proxmox-mail-forward could not forward email to notification queue, retrying later: {error:#}" + ), + ForwardError::Bounce(error) => write!( + f, + "proxmox-mail-forward could not forward email, dropping email: {error:#}" + ), + } + } +} + /// A Proxmox product whose notifications are processed via a notification queue. #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum Product { @@ -147,11 +179,17 @@ fn drop_privileges(uid: Uid, gid: Gid) -> Result<(), Error> { Ok(()) } -fn forward_mail_from_stdin() -> Result<(), Error> { - let product = installed_product()?; - drop_privileges(product.uid()?, product.gid()?)?; +fn forward_mail_from_stdin() -> Result<(), ForwardError> { + let product = installed_product().map_err(ForwardError::Temporary)?; + drop_privileges( + product.uid().map_err(ForwardError::Temporary)?, + product.gid().map_err(ForwardError::Temporary)?, + ) + .map_err(ForwardError::Temporary)?; - let mail = read_stdin().context("could not read mail from STDIN")?; + let mail = read_stdin() + .context("could not read mail from STDIN") + .map_err(ForwardError::Bounce)?; // Files are created by the queue's owner now, so only the mode needs to be set explicitly. let queue = QueueSubmitter::new( @@ -163,16 +201,18 @@ fn forward_mail_from_stdin() -> Result<(), Error> { .severity(Severity::Unknown) .field("hostname", proxmox_sys::nodename()) .field("type", "system-mail") - .build()?; + .build() + .map_err(|err| ForwardError::Bounce(err.into()))?; queue .submit(¬ification) - .context("could not submit mail to notification queue")?; + .context("could not submit mail to notification queue") + .map_err(ForwardError::Temporary)?; Ok(()) } -fn main() { +fn main() -> ExitCode { if let Err(err) = Logger::from_env("PROXMOX_LOG", LevelFilter::INFO) .journald() .init() @@ -181,6 +221,14 @@ fn main() { } if let Err(err) = forward_mail_from_stdin() { - error!("proxmox-mail-forward could not forward email: {err:#}"); + error!("{err:#}"); + + // Print the error to stderr as well, since that will be shown + // in `mailq` output for deferred emails. + eprintln!("{err:#}"); + + return err.into(); } + + ExitCode::SUCCESS } -- 2.47.3