all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Shannon Sterz <s.sterz@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver
Date: Wed,  8 Oct 2025 10:50:25 +0200	[thread overview]
Message-ID: <20251008085029.63335-4-s.sterz@proxmox.com> (raw)
In-Reply-To: <20251008085029.63335-1-s.sterz@proxmox.com>

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@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@example.com",
+            "Subject Line",
+            "This is just ascii text.\nNothing too special.",
+        )
+        .with_recipient_and_name("Receiver Name", "receiver@example.com")
+        .with_recipient("two@example.com")
+        .with_recipient_and_name("mäx müstermänn", "mm@example.com")
+        .with_masked_receiver("Example Receiver", "noanswer@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@example.com>
+To: Example Receiver <noanswer@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



_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel

      parent reply	other threads:[~2025-10-08  8:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-08  8:49 [pbs-devel] [PATCH proxmox 0/4] improve mail compatability Shannon Sterz
2025-10-08  8:50 ` [pbs-devel] [PATCH proxmox 1/4] sendmail: encode non-ascii filenames to improve compatability Shannon Sterz
2025-10-08  8:50   ` [pbs-devel] [PATCH proxmox 2/4] sendmail: encode non-ascii bodies as base64 to improve comptability Shannon Sterz
2025-10-08  8:50   ` [pbs-devel] [PATCH proxmox 3/4] sendmail: break content disposition headers for attachments Shannon Sterz
2025-10-08  8:50   ` Shannon Sterz [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251008085029.63335-4-s.sterz@proxmox.com \
    --to=s.sterz@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal