git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] send-email: extend sanitize_address_rfc822 to do rfc2047 quoting

From
Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>
Date
Jul 10, 2007, 17:02 UTC
Message-ID
<11840869641759-git-send-email-ukleinek@informatik.uni-freiburg.de>

Without this patch I'm not able to properly send emails as I have a non-ascii character in my name.

Signed-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>
---
As I'm not a perl profi, someone wants to check this code.
Actually this series is a test, as it is sended with the patched send-email.
I hope it works :-)
Uwe
 git-send-email.perl |   24 +++++++++++++++++++-----
 1 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 89f7c36..8b3d450 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -459,16 +459,30 @@ sub unquote_rfc2047 {
 	return "$_";
 }
 
-# If an address contains a . in the name portion, the name must be quoted.
+# If an address contains a non-ascii char in the name port, quote it according
+# to rfc2047.
+# If an address contains a . in the name portion, the name must be quoted using
+# double quotes.
 sub sanitize_address_rfc822
 {
 	my ($recipient) = @_;
-	my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
+	my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
+
+	if ($recipient_name && $recipient_name =~ /[^-a-zA-Z0-9!*+\/ ]/ && $recipient_name !~ /=\?utf-8\?q?.*\?=/) {
+		$recipient_name =~ s/([^-a-zA-Z0-9!*+ ])/sprintf("=%02X", ord($1))/eg;
+		$recipient_name =~ s/ /_/;
+		$recipient_name =~ s/(.*)/=\?utf-8\?q\?$1\?=/;
+	}
+
 	if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
-		my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
-		$recipient = "\"$name\"$addr";
+		$recipient_name = "\"$recipient_name\"";
+	}
+
+	if ($recipient_name) {
+		return "$recipient_name$recipient_addr";
+	} else {
+		return "$recipient";
 	}
-	return $recipient;
 }
 
 sub send_message
-- 
1.5.3.rc0.823.gdedbf
Next: Uwe Kleine-König
Message 1 of 7 in “send-email: extend sanitize_address_rfc822 to do rfc2047 quoting”
  1. send-email: extend sanitize_address_rfc822 to do rfc2047 quotingUwe Kleine-König, Jul 10, 2007
  2. [RFC] send-email: honor --suppress-from --signed-off-ccUwe Kleine-König, Jul 10, 2007
  3. Uwe Kleine-KönigJul 11, 2007
  4. Sven VerdoolaegeJul 11, 2007
  5. Uwe Kleine-KönigJul 11, 2007
  6. Sven VerdoolaegeJul 11, 2007
  7. Sven VerdoolaegeJul 11, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.