From: "Uwe Kleine-König" <ukleinek@informatik.uni-freiburg.de>
To: Git Mailing List <git@vger.kernel.org>
Cc: "Uwe Kleine-König" <ukleinek@informatik.uni-freiburg.de>,
"Jakub Narebski" <jnareb@gmail.com>
Subject: [PATCH] send-email: teach sanitize_address to do rfc2047 quoting
Date: Mon, 6 Aug 2007 22:34:50 +0200 [thread overview]
Message-ID: <11864324902764-git-send-email-ukleinek@informatik.uni-freiburg.de> (raw)
In-Reply-To: <20070806083341.GA6625@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.
I removed the _rfc822 suffix from the function name as it now does more
than rfc822 quoting.
I dug through rfc822 to do the double quoting right. Only if that is not
possible rfc2047 quoting is applied.
Signed-off-by: Uwe Kleine-König <ukleinek@informatik.uni-freiburg.de>
Cc: Jakub Narebski <jnareb@gmail.com>
---
As Jakub critizied now the "easiest" quoting is done.
git-send-email.perl | 39 +++++++++++++++++++++++++++++----------
1 files changed, 29 insertions(+), 10 deletions(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index f43f92f..39e433b 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -289,7 +289,7 @@ sub expand_aliases {
}
@to = expand_aliases(@to);
-@to = (map { sanitize_address_rfc822($_) } @to);
+@to = (map { sanitize_address($_) } @to);
@initial_cc = expand_aliases(@initial_cc);
@bcclist = expand_aliases(@bcclist);
@@ -459,22 +459,41 @@ sub unquote_rfc2047 {
return "$_";
}
-# If an address contains a . in the name portion, the name must be quoted.
-sub sanitize_address_rfc822
+# use the simplest quoting being able to handle the recipient
+sub sanitize_address
{
my ($recipient) = @_;
- my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
- if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
- my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
- $recipient = "\"$name\"$addr";
+ my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
+
+ if (not $recipient_name) {
+ return "$recipient";
+ }
+
+ # if recipient_name is already quoted, do nothing
+ if ($recipient_name =~ /^(".*"|=\?utf-8\?q\?.*\?=)$/) {
+ return $recipient;
+ }
+
+ # rfc2047 is needed if a non-ascii char is included
+ if ($recipient_name =~ /[^[:ascii:]]/) {
+ $recipient_name =~ s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg;
+ $recipient_name =~ s/(.*)/=\?utf-8\?q\?$1\?=/;
}
- return $recipient;
+
+ # double quotes are needed if specials or CTLs are included
+ elsif ($recipient_name =~ /[][()<>@,;:\\".\000-\037\177]/) {
+ $recipient_name =~ s/(["\\\r])/\\$1/;
+ $recipient_name = "\"$recipient_name\"";
+ }
+
+ return "$recipient_name $recipient_addr";
+
}
sub send_message
{
my @recipients = unique_email_list(@to);
- @cc = (map { sanitize_address_rfc822($_) } @cc);
+ @cc = (map { sanitize_address($_) } @cc);
my $to = join (",\n\t", @recipients);
@recipients = unique_email_list(@recipients,@cc,@bcclist);
@recipients = (map { extract_valid_address($_) } @recipients);
@@ -489,7 +508,7 @@ sub send_message
if ($cc ne '') {
$ccline = "\nCc: $cc";
}
- $from = sanitize_address_rfc822($from);
+ $from = sanitize_address($from);
make_message_id();
my $header = "From: $from
--
1.5.3.rc3.13.g7ab3
next prev parent reply other threads:[~2007-08-06 20:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-05 20:09 [PATCH] send-email: let sanitize_address_rfc822 do rfc2047 quoting Uwe Kleine-König
2007-08-06 0:21 ` Jakub Narebski
2007-08-06 8:33 ` Uwe Kleine-König
2007-08-06 20:34 ` Uwe Kleine-König [this message]
2007-08-09 12:10 ` [PATCH] send-email: teach sanitize_address to " Uwe Kleine-König
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=11864324902764-git-send-email-ukleinek@informatik.uni-freiburg.de \
--to=ukleinek@informatik.uni-freiburg.de \
--cc=git@vger.kernel.org \
--cc=jnareb@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).