* [pbs-devel] [PATCH proxmox 0/4] improve mail compatability @ 2025-10-08 8:49 Shannon Sterz 2025-10-08 8:50 ` [pbs-devel] [PATCH proxmox 1/4] sendmail: encode non-ascii filenames to improve compatability Shannon Sterz 0 siblings, 1 reply; 5+ messages in thread From: Shannon Sterz @ 2025-10-08 8:49 UTC (permalink / raw) To: pbs-devel this series tries to improve compatability with more mail servers. this is done in three ways: - patch 1: base64 encode filenames of attachments - patch 2: check whether the html or text bodies of an email are ascii only. if they are, we can safely declare 7bit encoding which should be more broadly compatability than the previous 8bit encoding. if the text is not ascii only, encode it as base64 and declare base64 encoding. - patch 3: splits the Content-Disposition header of attached files over two lines, to avoid longer files possibly triggering a line length limit. - patch 4: allows setting the masked recipient so that users of this crate can specify somethings more appropriate for their use case. this should specifically make it possible to support mail servers that don't support SMTPUTF8, as now no part of the header or body should contain plain utf8 characters directly. i tested these patches against the following mail clients: - bluemind - Thunderbird - aerc - canary [1] - iOS Mail app - gmail.com - outlook.com all of them seemed to receive the email and display it properly (note that aerc prefers the TXT part of the mime alternative parts even if the html part should be preferred, due to being a terminal based mua). [1]: https://canarymail.io/ Changelog --------- changes since v1: - rebased on current master - added a patch that allows setting the noreply recipient for mails send in undisclosed recipient mode Note: the need for this series was identified internally as some mails send with out internal tools would to be received properly. Shannon Sterz (4): sendmail: encode non-ascii filenames to improve compatability sendmail: encode non-ascii bodies as base64 to improve comptability sendmail: break content disposition headers for attachments sendmail: allow specifying the masked receiver proxmox-sendmail/src/lib.rs | 258 ++++++++++++++++++++++++++++-------- 1 file changed, 206 insertions(+), 52 deletions(-) -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* [pbs-devel] [PATCH proxmox 1/4] sendmail: encode non-ascii filenames to improve compatability 2025-10-08 8:49 [pbs-devel] [PATCH proxmox 0/4] improve mail compatability Shannon Sterz @ 2025-10-08 8:50 ` 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 ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Shannon Sterz @ 2025-10-08 8:50 UTC (permalink / raw) To: pbs-devel otherwise some mail servers that do not support utf8 properly mail not accept the email. Signed-off-by: Shannon Sterz <s.sterz@proxmox.com> --- proxmox-sendmail/src/lib.rs | 95 ++++++++++++++++++++++++++++++++++--- 1 file changed, 89 insertions(+), 6 deletions(-) diff --git a/proxmox-sendmail/src/lib.rs b/proxmox-sendmail/src/lib.rs index 053fc98e..ebbcfe86 100644 --- a/proxmox-sendmail/src/lib.rs +++ b/proxmox-sendmail/src/lib.rs @@ -81,18 +81,23 @@ impl Attachment<'_> { let mut attachment = String::new(); + let encoded_filename = if self.filename.is_ascii() { + &self.filename + } else { + &format!("=?utf-8?B?{}?=", proxmox_base64::encode(&self.filename)) + }; + let _ = writeln!(attachment, "\n--{file_boundary}"); let _ = writeln!( attachment, - "Content-Type: {}; name=\"{}\"", - self.mime, self.filename + "Content-Type: {}; name=\"{encoded_filename}\"", + self.mime, ); // both `filename` and `filename*` are included for additional compatability let _ = writeln!( attachment, - "Content-Disposition: attachment; filename=\"{}\"; filename*=UTF-8''{}", - self.filename, + "Content-Disposition: attachment; filename=\"{encoded_filename}\"; filename*=UTF-8''{}", utf8_percent_encode(&self.filename, RFC5987SET) ); attachment.push_str("Content-Transfer-Encoding: base64\n\n"); @@ -804,8 +809,8 @@ Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v 3q2+796tvu8= ------_=_NextPart_001_1732806251 -Content-Type: image/bmp; name="🐄💀.bin" -Content-Disposition: attachment; filename="🐄💀.bin"; filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin +Content-Type: image/bmp; name="=?utf-8?B?8J+QhPCfkoAuYmlu?=" +Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v @@ -855,4 +860,82 @@ Content-Transfer-Encoding: 8bit ------_=_NextPart_002_1718977850--"#, ); } + + #[test] + fn multipart_plain_text_html_alternative_attachments_ascii_compat() { + let bin: [u8; 62] = [ + 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, + 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, + 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, + 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, 0xde, 0xad, + 0xbe, 0xef, 0xde, 0xad, 0xbe, 0xef, + ]; + + let mail = Mail::new( + "Sender Näme", + "from@example.com", + "Subject Linë", + "Lorem Ipsum Dolor Sit\nAmet", + ) + .with_recipient_and_name("Receiver Näme", "receiver@example.com") + .with_attachment("deadbeef.bin", "application/octet-stream", &bin) + .with_attachment("🐄💀.bin", "image/bmp", &bin) + .with_html_alt("<html lang=\"de-at\"><head></head><body>\n\t<pre>\n\t\tLorem Ipsum Dolor Sit Amet\n\t</pre>\n</body></html>"); + + let body = mail.format_mail(1732806251).expect("could not format mail"); + + assert!(body.is_ascii()); + + assert_lines_equal_ignore_date( + &body, + r#"Content-Type: multipart/mixed; + boundary="----_=_NextPart_001_1732806251" +MIME-Version: 1.0 +Subject: =?utf-8?B?U3ViamVjdCBMaW7Dqw==?= +From: =?utf-8?B?U2VuZGVyIE7DpG1l?= <from@example.com> +To: =?utf-8?B?UmVjZWl2ZXIgTsOkbWU=?= <receiver@example.com> +Date: Thu, 28 Nov 2024 16:04:11 +0100 +Auto-Submitted: auto-generated; + +This is a multi-part message in MIME format. + +------_=_NextPart_001_1732806251 +Content-Type: multipart/alternative; boundary="----_=_NextPart_002_1732806251" +MIME-Version: 1.0 + +------_=_NextPart_002_1732806251 +Content-Type: text/plain; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + +Lorem Ipsum Dolor Sit +Amet +------_=_NextPart_002_1732806251 +Content-Type: text/html; + charset="UTF-8" +Content-Transfer-Encoding: 8bit + +<html lang="de-at"><head></head><body> + <pre> + Lorem Ipsum Dolor Sit Amet + </pre> +</body></html> +------_=_NextPart_002_1732806251-- +------_=_NextPart_001_1732806251 +Content-Type: application/octet-stream; name="deadbeef.bin" +Content-Disposition: attachment; filename="deadbeef.bin"; filename*=UTF-8''deadbeef.bin +Content-Transfer-Encoding: base64 + +3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v +3q2+796tvu8= +------_=_NextPart_001_1732806251 +Content-Type: image/bmp; name="=?utf-8?B?8J+QhPCfkoAuYmlu?=" +Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin +Content-Transfer-Encoding: base64 + +3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v +3q2+796tvu8= +------_=_NextPart_001_1732806251--"#, + ) + } } -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* [pbs-devel] [PATCH proxmox 2/4] sendmail: encode non-ascii bodies as base64 to improve comptability 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 ` 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 ` [pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver Shannon Sterz 2 siblings, 0 replies; 5+ messages in thread From: Shannon Sterz @ 2025-10-08 8:50 UTC (permalink / raw) To: pbs-devel and use 7bit encoding otherwise. this should further improve compatability with older mail servers that don't really handle 8bit utf8 bodies properly. by base64 encoding the bodies that require it and declaring 7bit ascii compatability otherwise, this should work around compatability constraints. Signed-off-by: Shannon Sterz <s.sterz@proxmox.com> --- proxmox-sendmail/src/lib.rs | 111 ++++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 49 deletions(-) diff --git a/proxmox-sendmail/src/lib.rs b/proxmox-sendmail/src/lib.rs index ebbcfe86..fb201007 100644 --- a/proxmox-sendmail/src/lib.rs +++ b/proxmox-sendmail/src/lib.rs @@ -41,6 +41,24 @@ const RFC5987SET: &AsciiSet = &CONTROLS .add(b'{') .add(b'}'); +// base64 encode and hard-wrap the base64 encoded string every 72 characters. this improves +// compatibility. +fn encode_base64_formatted<T: AsRef<[u8]>>(raw: T) -> String { + proxmox_base64::encode(raw) + .chars() + .enumerate() + .flat_map(|(i, c)| { + if i != 0 && i % 72 == 0 { + Some('\n') + } else { + None + } + .into_iter() + .chain(std::iter::once(c)) + }) + .collect::<String>() +} + struct Recipient { name: Option<String>, email: String, @@ -100,25 +118,9 @@ impl Attachment<'_> { "Content-Disposition: attachment; filename=\"{encoded_filename}\"; filename*=UTF-8''{}", utf8_percent_encode(&self.filename, RFC5987SET) ); - attachment.push_str("Content-Transfer-Encoding: base64\n\n"); - // base64 encode the attachment and hard-wrap the base64 encoded string every 72 - // characters. this improves compatability. - attachment.push_str( - &proxmox_base64::encode(self.content) - .chars() - .enumerate() - .flat_map(|(i, c)| { - if i != 0 && i % 72 == 0 { - Some('\n') - } else { - None - } - .into_iter() - .chain(std::iter::once(c)) - }) - .collect::<String>(), - ); + attachment.push_str("Content-Transfer-Encoding: base64\n\n"); + attachment.push_str(&encode_base64_formatted(self.content)); attachment } @@ -400,7 +402,11 @@ impl<'a> Mail<'a> { header.push_str("Content-Type: multipart/alternative;\n"); writeln!(header, "\tboundary=\"{html_boundary}\"")?; header.push_str("MIME-Version: 1.0\n"); - } else if !self.subject.is_ascii() || !self.mail_author.is_ascii() || encoded_to { + } else if !self.subject.is_ascii() + || !self.mail_author.is_ascii() + || !self.body_txt.is_ascii() + || encoded_to + { header.push_str("MIME-Version: 1.0\n"); } @@ -475,15 +481,28 @@ impl<'a> Mail<'a> { body.push_str("Content-Type: text/plain;\n"); body.push_str("\tcharset=\"UTF-8\"\n"); - body.push_str("Content-Transfer-Encoding: 8bit\n\n"); - body.push_str(&self.body_txt); + + if self.body_txt.is_ascii() { + body.push_str("Content-Transfer-Encoding: 7bit\n\n"); + body.push_str(&self.body_txt); + } else { + body.push_str("Content-Transfer-Encoding: base64\n\n"); + body.push_str(&encode_base64_formatted(&self.body_txt)); + } if let Some(html) = &self.body_html { writeln!(body, "\n--{html_boundary}")?; body.push_str("Content-Type: text/html;\n"); body.push_str("\tcharset=\"UTF-8\"\n"); - body.push_str("Content-Transfer-Encoding: 8bit\n\n"); - body.push_str(html); + + if html.is_ascii() { + body.push_str("Content-Transfer-Encoding: 7bit\n\n"); + body.push_str(html); + } else { + body.push_str("Content-Transfer-Encoding: base64\n\n"); + body.push_str(&encode_base64_formatted(html)); + } + write!(body, "\n--{html_boundary}--")?; } @@ -547,7 +566,7 @@ Date: Thu, 01 Jan 1970 01:00:00 +0100 Auto-Submitted: auto-generated; Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is just ascii text. Nothing too special."#, @@ -577,7 +596,7 @@ Date: Thu, 01 Jan 1970 01:00:00 +0100 Auto-Submitted: auto-generated; Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is just ascii text. Nothing too special."#, @@ -609,7 +628,7 @@ Date: Thu, 01 Jan 1970 01:00:00 +0100 Auto-Submitted: auto-generated; Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is just ascii text. Nothing too special."#, @@ -638,12 +657,10 @@ Date: Thu, 28 Nov 2024 16:04:11 +0100 Auto-Submitted: auto-generated; Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: base64 -This utf-8 email should handle emojis -🧑📧 -and weird german characters: öäüß -and more."#, +VGhpcyB1dGYtOCBlbWFpbCBzaG91bGQgaGFuZGxlIGVtb2ppcwrwn6eR8J+TpwphbmQgd2Vp +cmQgZ2VybWFuIGNoYXJhY3RlcnM6IMO2w6TDvMOfCmFuZCBtb3JlLg=="#, ) } @@ -674,14 +691,14 @@ This is a multi-part message in MIME format. ------_=_NextPart_002_1732806251 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Lorem Ipsum Dolor Sit Amet ------_=_NextPart_002_1732806251 Content-Type: text/html; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit <html lang="de-at"><head></head><body> <pre> @@ -728,7 +745,7 @@ This is a multi-part message in MIME format. ------_=_NextPart_001_1732806251 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Lorem Ipsum Dolor Sit Amet @@ -786,14 +803,14 @@ MIME-Version: 1.0 ------_=_NextPart_002_1732806251 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Lorem Ipsum Dolor Sit Amet ------_=_NextPart_002_1732806251 Content-Type: text/html; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit <html lang="de-at"><head></head><body> <pre> @@ -848,13 +865,13 @@ This is a multi-part message in MIME format. ------_=_NextPart_002_1718977850 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the plain body ------_=_NextPart_002_1718977850 Content-Type: text/html; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit <body>This is the HTML body</body> ------_=_NextPart_002_1718977850--"#, @@ -875,12 +892,12 @@ Content-Transfer-Encoding: 8bit "Sender Näme", "from@example.com", "Subject Linë", - "Lorem Ipsum Dolor Sit\nAmet", + "Lorem Ipsum Dolor Sit\nAmët", ) .with_recipient_and_name("Receiver Näme", "receiver@example.com") .with_attachment("deadbeef.bin", "application/octet-stream", &bin) .with_attachment("🐄💀.bin", "image/bmp", &bin) - .with_html_alt("<html lang=\"de-at\"><head></head><body>\n\t<pre>\n\t\tLorem Ipsum Dolor Sit Amet\n\t</pre>\n</body></html>"); + .with_html_alt("<html lang=\"de-at\"><head></head><body>\n\t<pre>\n\t\tLorem Ipsum Dölor Sit Amet\n\t</pre>\n</body></html>"); let body = mail.format_mail(1732806251).expect("could not format mail"); @@ -906,20 +923,16 @@ MIME-Version: 1.0 ------_=_NextPart_002_1732806251 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: base64 -Lorem Ipsum Dolor Sit -Amet +TG9yZW0gSXBzdW0gRG9sb3IgU2l0CkFtw6t0 ------_=_NextPart_002_1732806251 Content-Type: text/html; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: base64 -<html lang="de-at"><head></head><body> - <pre> - Lorem Ipsum Dolor Sit Amet - </pre> -</body></html> +PGh0bWwgbGFuZz0iZGUtYXQiPjxoZWFkPjwvaGVhZD48Ym9keT4KCTxwcmU+CgkJTG9yZW0g +SXBzdW0gRMO2bG9yIFNpdCBBbWV0Cgk8L3ByZT4KPC9ib2R5PjwvaHRtbD4= ------_=_NextPart_002_1732806251-- ------_=_NextPart_001_1732806251 Content-Type: application/octet-stream; name="deadbeef.bin" -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* [pbs-devel] [PATCH proxmox 3/4] sendmail: break content disposition headers for attachments 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 ` Shannon Sterz 2025-10-08 8:50 ` [pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver Shannon Sterz 2 siblings, 0 replies; 5+ messages in thread From: Shannon Sterz @ 2025-10-08 8:50 UTC (permalink / raw) To: pbs-devel this should make it easier to accomodate longer filenames, as line lengths in emails are constraint. Signed-off-by: Shannon Sterz <s.sterz@proxmox.com> --- proxmox-sendmail/src/lib.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/proxmox-sendmail/src/lib.rs b/proxmox-sendmail/src/lib.rs index fb201007..1c5daf0f 100644 --- a/proxmox-sendmail/src/lib.rs +++ b/proxmox-sendmail/src/lib.rs @@ -115,7 +115,7 @@ impl Attachment<'_> { // both `filename` and `filename*` are included for additional compatability let _ = writeln!( attachment, - "Content-Disposition: attachment; filename=\"{encoded_filename}\"; filename*=UTF-8''{}", + "Content-Disposition: attachment; filename=\"{encoded_filename}\";\n\tfilename*=UTF-8''{}", utf8_percent_encode(&self.filename, RFC5987SET) ); @@ -751,7 +751,8 @@ Lorem Ipsum Dolor Sit Amet ------_=_NextPart_001_1732806251 Content-Type: application/octet-stream; name="deadbeef.bin" -Content-Disposition: attachment; filename="deadbeef.bin"; filename*=UTF-8''deadbeef.bin +Content-Disposition: attachment; filename="deadbeef.bin"; + filename*=UTF-8''deadbeef.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v @@ -820,14 +821,16 @@ Content-Transfer-Encoding: 7bit ------_=_NextPart_002_1732806251-- ------_=_NextPart_001_1732806251 Content-Type: application/octet-stream; name="deadbeef.bin" -Content-Disposition: attachment; filename="deadbeef.bin"; filename*=UTF-8''deadbeef.bin +Content-Disposition: attachment; filename="deadbeef.bin"; + filename*=UTF-8''deadbeef.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v 3q2+796tvu8= ------_=_NextPart_001_1732806251 Content-Type: image/bmp; name="=?utf-8?B?8J+QhPCfkoAuYmlu?=" -Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin +Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; + filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v @@ -936,14 +939,16 @@ SXBzdW0gRMO2bG9yIFNpdCBBbWV0Cgk8L3ByZT4KPC9ib2R5PjwvaHRtbD4= ------_=_NextPart_002_1732806251-- ------_=_NextPart_001_1732806251 Content-Type: application/octet-stream; name="deadbeef.bin" -Content-Disposition: attachment; filename="deadbeef.bin"; filename*=UTF-8''deadbeef.bin +Content-Disposition: attachment; filename="deadbeef.bin"; + filename*=UTF-8''deadbeef.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v 3q2+796tvu8= ------_=_NextPart_001_1732806251 Content-Type: image/bmp; name="=?utf-8?B?8J+QhPCfkoAuYmlu?=" -Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin +Content-Disposition: attachment; filename="=?utf-8?B?8J+QhPCfkoAuYmlu?="; + filename*=UTF-8''%F0%9F%90%84%F0%9F%92%80.bin Content-Transfer-Encoding: base64 3q2+796tvu/erb7v3q3erb7v3q2+796tvu/erd6tvu/erb7v3q2+796t3q2+796tvu/erb7v -- 2.47.3 _______________________________________________ pbs-devel mailing list pbs-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel ^ permalink raw reply [flat|nested] 5+ messages in thread
* [pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver 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 2 siblings, 0 replies; 5+ messages in thread From: Shannon Sterz @ 2025-10-08 8:50 UTC (permalink / raw) To: pbs-devel 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 ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-10-08 8:51 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 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 ` [pbs-devel] [PATCH proxmox 4/4] sendmail: allow specifying the masked receiver Shannon Sterz
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox