all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed
@ 2025-06-26 12:54 Lukas Wagner
  2025-07-15 22:46   ` [pve-devel] " Thomas Lamprecht
  0 siblings, 1 reply; 5+ messages in thread
From: Lukas Wagner @ 2025-06-26 12:54 UTC (permalink / raw)
  To: pbs-devel

RFC5322 requires to quote the display name if certain special characters
are used (see diff).

Signed-off-by: Lukas Wagner <l.wagner@proxmox.com>
---

Notes:
    The sendmail endpoint does not seem to need this, apparently sendmail
    does the quoting automatically.

 proxmox-notify/src/endpoints/smtp.rs | 56 ++++++++++++++++++++++++++--
 1 file changed, 53 insertions(+), 3 deletions(-)

diff --git a/proxmox-notify/src/endpoints/smtp.rs b/proxmox-notify/src/endpoints/smtp.rs
index b684d8ca..d4fed237 100644
--- a/proxmox-notify/src/endpoints/smtp.rs
+++ b/proxmox-notify/src/endpoints/smtp.rs
@@ -1,3 +1,4 @@
+use std::borrow::Cow;
 use std::time::Duration;
 
 use lettre::message::header::{HeaderName, HeaderValue};
@@ -213,8 +214,10 @@ impl Endpoint for SmtpEndpoint {
             .clone()
             .unwrap_or_else(|| context().default_sendmail_author());
 
+        let quoted_author = quote_name_if_needed(&author);
+
         let mut email_builder =
-            Message::builder().from(parse_address(&format!("{author} <{mail_from}>"))?);
+            Message::builder().from(parse_address(&format!("{quoted_author} <{mail_from}>"))?);
 
         for recipient in recipients {
             email_builder = email_builder.to(parse_address(&recipient)?);
@@ -377,14 +380,61 @@ fn build_forwarded_message(
     Ok(message)
 }
 
-#[cfg(all(test, feature = "mail-forwarder"))]
+/// Quote mail name if required by RFC5322.
+fn quote_name_if_needed(name: &str) -> Cow<str> {
+    // See https://datatracker.ietf.org/doc/html/rfc5322#section-3.2.3
+    let needs_quotes = name.chars().any(|c| {
+        matches!(
+            c,
+            '(' | ')' | '<' | '>' | '@' | ',' | ';' | ':' | '\\' | '"' | '[' | ']' | '='
+        )
+    });
+
+    if needs_quotes {
+        // Quoted strings may contain all printable chars except \ and ", they need to be
+        // escaped. Non-ASCII UTF-8 characters are later encoded by lettre, we do not
+        // need to care about them here.
+        let mut result = name.replace(r#"\"#, r#"\\"#);
+        result = result.replace(r#"""#, r#"\""#);
+        Cow::Owned(format!("\"{result}\""))
+    } else {
+        Cow::Borrowed(name)
+    }
+}
+
+#[cfg(test)]
 mod tests {
-    use lettre::message::header::Date;
 
     use super::*;
 
+    #[test]
+    fn test_quote_mail_name() {
+        assert_eq!(
+            &quote_name_if_needed("Firstname Lastname"),
+            "Firstname Lastname"
+        );
+
+        assert_eq!(
+            &quote_name_if_needed("Firstname \"Nickname\" Lastname"),
+            "\"Firstname \\\"Nickname\\\" Lastname\""
+        );
+
+        assert_eq!(
+            &quote_name_if_needed("Proxmox VE (somehost)"),
+            "\"Proxmox VE (somehost)\""
+        );
+
+        assert_eq!(
+            &quote_name_if_needed("Firstname \\ Lastname"),
+            "\"Firstname \\\\ Lastname\""
+        );
+    }
+
+    #[cfg(feature = "mail-forwarder")]
     #[test]
     fn test_forward_message_from_raw() {
+        use lettre::message::header::Date;
+
         let input = "testdata/test1.msg";
         let reference = "testdata/test_forward_message_from_raw.ref";
 
-- 
2.39.5



_______________________________________________
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

* Re: [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed
  2025-06-26 12:54 [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed Lukas Wagner
@ 2025-07-15 22:46   ` Thomas Lamprecht
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2025-07-15 22:46 UTC (permalink / raw)
  To: pve-devel, pbs-devel, Lukas Wagner

On Thu, 26 Jun 2025 14:54:29 +0200, Lukas Wagner wrote:
> RFC5322 requires to quote the display name if certain special characters
> are used (see diff).
> 
> 

Applied, thanks!

This would need a dedicated backport to be applyable to stable-bookworm, FWICT.

[1/1] fix #6188: notify: smtp: quote sender's display name if needed
      commit: 7262fae25c7cd25df9443158e3542ad58e7c0ebe


_______________________________________________
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

* Re: [pve-devel] [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed
@ 2025-07-15 22:46   ` Thomas Lamprecht
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Lamprecht @ 2025-07-15 22:46 UTC (permalink / raw)
  To: pve-devel, pbs-devel, Lukas Wagner

On Thu, 26 Jun 2025 14:54:29 +0200, Lukas Wagner wrote:
> RFC5322 requires to quote the display name if certain special characters
> are used (see diff).
> 
> 

Applied, thanks!

This would need a dedicated backport to be applyable to stable-bookworm, FWICT.

[1/1] fix #6188: notify: smtp: quote sender's display name if needed
      commit: 7262fae25c7cd25df9443158e3542ad58e7c0ebe


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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed
  2025-07-15 22:46   ` [pve-devel] " Thomas Lamprecht
@ 2025-07-16  9:33     ` Lukas Wagner
  -1 siblings, 0 replies; 5+ messages in thread
From: Lukas Wagner @ 2025-07-16  9:33 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel, pbs-devel



On  2025-07-16 00:46, Thomas Lamprecht wrote:
> On Thu, 26 Jun 2025 14:54:29 +0200, Lukas Wagner wrote:
>> RFC5322 requires to quote the display name if certain special characters
>> are used (see diff).
>>
>>
> 
> Applied, thanks!
> 
> This would need a dedicated backport to be applyable to stable-bookworm, FWICT.
> 

Sent a separate patch for the backport onto stable-bookworm just now:

https://lore.proxmox.com/pve-devel/20250716091326.144240-1-l.wagner@proxmox.com/T/#u

-- 
- Lukas



_______________________________________________
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

* Re: [pve-devel] [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed
@ 2025-07-16  9:33     ` Lukas Wagner
  0 siblings, 0 replies; 5+ messages in thread
From: Lukas Wagner @ 2025-07-16  9:33 UTC (permalink / raw)
  To: Thomas Lamprecht, pve-devel, pbs-devel



On  2025-07-16 00:46, Thomas Lamprecht wrote:
> On Thu, 26 Jun 2025 14:54:29 +0200, Lukas Wagner wrote:
>> RFC5322 requires to quote the display name if certain special characters
>> are used (see diff).
>>
>>
> 
> Applied, thanks!
> 
> This would need a dedicated backport to be applyable to stable-bookworm, FWICT.
> 

Sent a separate patch for the backport onto stable-bookworm just now:

https://lore.proxmox.com/pve-devel/20250716091326.144240-1-l.wagner@proxmox.com/T/#u

-- 
- Lukas



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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-07-16  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-26 12:54 [pbs-devel] [PATCH proxmox] fix #6188: notify: smtp: quote sender's display name if needed Lukas Wagner
2025-07-15 22:46 ` Thomas Lamprecht
2025-07-15 22:46   ` [pve-devel] " Thomas Lamprecht
2025-07-16  9:33   ` Lukas Wagner
2025-07-16  9:33     ` [pve-devel] " Lukas Wagner

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