send-email: teach sanitize_address to do rfc2047 quoting
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,Av(Bnig <ukleinek@informatik.uni-freiburg.de> Cc: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Uwe Kleine-K,Av(Bnig committed
Aug 6, 2007 at 22:34 UTC
5b56aaa29e9d7c0371b6d47bd8a6b12a0c4292dd
1 file changed
+29
-10
git-send-email.perl
+29
-10
@@ -289,7 +289,7 @@ sub expand_aliases {
289
}
290
291
@to = expand_aliases(@to);
292
-@to = (map { sanitize_address_rfc822($_) } @to);
292
+@to = (map { sanitize_address($_) } @to);
293
@initial_cc = expand_aliases(@initial_cc);
294
@bcclist = expand_aliases(@bcclist);
295
@@ -459,22 +459,41 @@ sub unquote_rfc2047 {
459
return "$_";
460
}
461
462
-# If an address contains a . in the name portion, the name must be quoted.
463
-sub sanitize_address_rfc822
462
+# use the simplest quoting being able to handle the recipient
463
+sub sanitize_address
464
{
465
my ($recipient) = @_;
466
- my ($recipient_name) = ($recipient =~ /^(.*?)\s+</);
467
- if ($recipient_name && $recipient_name =~ /\./ && $recipient_name !~ /^".*"$/) {
468
- my ($name, $addr) = ($recipient =~ /^(.*?)(\s+<.*)/);
469
- $recipient = "\"$name\"$addr";
466
+ my ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\s*(<.*)/);
467
+
468
+ if (not $recipient_name) {
469
+ return "$recipient";
470
+ }
471
+
472
+ # if recipient_name is already quoted, do nothing
473
+ if ($recipient_name =~ /^(".*"|=\?utf-8\?q\?.*\?=)$/) {
474
+ return $recipient;
475
+ }
476
+
477
+ # rfc2047 is needed if a non-ascii char is included
478
+ if ($recipient_name =~ /[^[:ascii:]]/) {
479
+ $recipient_name =~ s/([^-a-zA-Z0-9!*+\/])/sprintf("=%02X", ord($1))/eg;
480
+ $recipient_name =~ s/(.*)/=\?utf-8\?q\?$1\?=/;
481
}
471
- return $recipient;
482
+
483
+ # double quotes are needed if specials or CTLs are included
484
+ elsif ($recipient_name =~ /[][()<>@,;:\\".\000-\037\177]/) {
485
+ $recipient_name =~ s/(["\\\r])/\\$1/;
486
+ $recipient_name = "\"$recipient_name\"";
487
+ }
488
+
489
+ return "$recipient_name $recipient_addr";
490
+
491
}
492
493
sub send_message
494
{
495
my @recipients = unique_email_list(@to);
477
- @cc = (map { sanitize_address_rfc822($_) } @cc);
496
+ @cc = (map { sanitize_address($_) } @cc);
497
my $to = join (",\n\t", @recipients);
498
@recipients = unique_email_list(@recipients,@cc,@bcclist);
499
@recipients = (map { extract_valid_address($_) } @recipients);
@@ -489,7 +508,7 @@ sub send_message
508
if ($cc ne '') {
509
$ccline = "\nCc: $cc";
510
}
492
- $from = sanitize_address_rfc822($from);
511
+ $from = sanitize_address($from);
512
make_message_id();
513
514
my $header = "From: $from