[pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver

Shannon Sterz s.sterz at proxmox.com
Wed Oct 8 10:50:25 CEST 2025


otherwise some receiver would still just use the `reply-all` function
of their mua, which would then also reply to the `noreply` address
here. so instead just allow applications to specify this according to
their needs.

Signed-off-by: Shannon Sterz <s.sterz at proxmox.com>
---
 proxmox-sendmail/src/lib.rs | 65 +++++++++++++++++++++++++++++++++----
 1 file changed, 59 insertions(+), 6 deletions(-)

diff --git a/proxmox-sendmail/src/lib.rs b/proxmox-sendmail/src/lib.rs
index 1c5daf0f..4a7d827d 100644
--- a/proxmox-sendmail/src/lib.rs
+++ b/proxmox-sendmail/src/lib.rs
@@ -136,6 +136,7 @@ pub struct Mail<'a> {
     body_html: Option<String>,
     attachments: Vec<Attachment<'a>>,
     mask_participants: bool,
+    noreply: Option<Recipient>,
 }
 
 impl<'a> Mail<'a> {
@@ -153,6 +154,7 @@ impl<'a> Mail<'a> {
             body_html: None,
             attachments: Vec::new(),
             mask_participants: true,
+            noreply: None,
         }
     }
 
@@ -265,6 +267,22 @@ impl<'a> Mail<'a> {
         self
     }
 
+    /// Set the receiver that is used when the mail is send in masked mode. `Undisclosed <noreply>`
+    /// by default.
+    pub fn set_masked_mail_and_name(&mut self, name: &str, email: &str) {
+        self.noreply = Some(Recipient {
+            email: email.to_owned(),
+            name: Some(name.to_owned()),
+        });
+    }
+
+    /// Builder-style method to set the receiver when the mail is send in masked mode. `Undisclosed
+    /// <noreply>` by default.
+    pub fn with_masked_receiver(mut self, name: &str, email: &str) -> Self {
+        self.set_masked_mail_and_name(name, email);
+        self
+    }
+
     /// Sends the email. This will fail if no recipients have been added.
     ///
     /// Note: An `Auto-Submitted: auto-generated` header is added to avoid triggering OOO and
@@ -433,12 +451,16 @@ impl<'a> Mail<'a> {
 
         let to = if self.to.len() > 1 && self.mask_participants {
             // don't disclose all recipients if the mail goes out to multiple
-            let recipient = Recipient {
-                name: Some("Undisclosed".to_string()),
-                email: "noreply".to_string(),
-            };
-
-            recipient.format_recipient()
+            self.noreply
+                .as_ref()
+                .map(|f| f.format_recipient())
+                .unwrap_or_else(|| {
+                    Recipient {
+                        name: Some("Undisclosed".to_string()),
+                        email: "noreply".to_string(),
+                    }
+                    .format_recipient()
+                })
         } else {
             self.to
                 .iter()
@@ -630,6 +652,37 @@ Content-Type: text/plain;
 	charset="UTF-8"
 Content-Transfer-Encoding: 7bit
 
+This is just ascii text.
+Nothing too special."#,
+        )
+    }
+
+    #[test]
+    fn multiple_receiver_custom_masked() {
+        let mail = Mail::new(
+            "Sender Name",
+            "mailfrom at example.com",
+            "Subject Line",
+            "This is just ascii text.\nNothing too special.",
+        )
+        .with_recipient_and_name("Receiver Name", "receiver at example.com")
+        .with_recipient("two at example.com")
+        .with_recipient_and_name("mäx müstermänn", "mm at example.com")
+        .with_masked_receiver("Example Receiver", "noanswer at example.com");
+
+        let body = mail.format_mail(0).expect("could not format mail");
+
+        assert_lines_equal_ignore_date(
+            &body,
+            r#"Subject: Subject Line
+From: Sender Name <mailfrom at example.com>
+To: Example Receiver <noanswer at example.com>
+Date: Thu, 01 Jan 1970 01:00:00 +0100
+Auto-Submitted: auto-generated;
+Content-Type: text/plain;
+	charset="UTF-8"
+Content-Transfer-Encoding: 7bit
+
 This is just ascii text.
 Nothing too special."#,
         )
-- 
2.47.3





More information about the pbs-devel mailing list