send-email: make --suppress-cc=self sanitize input

--suppress-cc=self fails to filter sender address in many cases where it needs to be sanitized in some way, for example quoted: "A U. Thor" <author@example.com> To fix, make send-email sanitize both sender and the address it is compared against. Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael S. Tsirkin committed Jun 5, 2013 at 21:11 UTC da18759e86bb1a7ee718c79a0c6cb15fbcbdf3c2
1 file changed +15 -8
git-send-email.perl
+15 -8
@@ -759,6 +759,11 @@ if (!defined $sender) {
759 $sender = $repoauthor || $repocommitter || '';
760 }
761
762 +# $sender could be an already sanitized address
763 +# (e.g. sendemail.from could be manually sanitized by user).
764 +# But it's a no-op to run sanitize_address on an already sanitized address.
765 +$sender = sanitize_address($sender);
766 +
767 my $prompting = 0;
768 if (!@initial_to && !defined $to_cmd) {
769 my $to = ask("Who should the emails be sent to (if any)? ",
@@ -1071,10 +1076,9 @@ sub send_message {
1076 if ($cc ne '') {
1077 $ccline = "\nCc: $cc";
1078 }
1074 - my $sanitized_sender = sanitize_address($sender);
1079 make_message_id() unless defined($message_id);
1080
1077 - my $header = "From: $sanitized_sender
1081 + my $header = "From: $sender
1082 To: $to${ccline}
1083 Subject: $subject
1084 Date: $date
@@ -1091,7 +1095,7 @@ X-Mailer: git-send-email $gitversion
1095 }
1096
1097 my @sendmail_parameters = ('-i', @recipients);
1094 - my $raw_from = $sanitized_sender;
1098 + my $raw_from = $sender;
1099 if (defined $envelope_sender && $envelope_sender ne "auto") {
1100 $raw_from = $envelope_sender;
1101 }
@@ -1292,8 +1296,9 @@ foreach my $t (@files) {
1296 }
1297 elsif (/^From:\s+(.*)$/i) {
1298 ($author, $author_encoding) = unquote_rfc2047($1);
1299 + my $sauthor = sanitize_address($author);
1300 next if $suppress_cc{'author'};
1296 - next if $suppress_cc{'self'} and $author eq $sender;
1301 + next if $suppress_cc{'self'} and $sauthor eq $sender;
1302 printf("(mbox) Adding cc: %s from line '%s'\n",
1303 $1, $_) unless $quiet;
1304 push @cc, $1;
@@ -1307,7 +1312,9 @@ foreach my $t (@files) {
1312 }
1313 elsif (/^Cc:\s+(.*)$/i) {
1314 foreach my $addr (parse_address_line($1)) {
1310 - if (unquote_rfc2047($addr) eq $sender) {
1315 + my $qaddr = unquote_rfc2047($addr);
1316 + my $saddr = sanitize_address($qaddr);
1317 + if ($saddr eq $sender) {
1318 next if ($suppress_cc{'self'});
1319 } else {
1320 next if ($suppress_cc{'cc'});
@@ -1354,7 +1361,8 @@ foreach my $t (@files) {
1361 chomp;
1362 my ($what, $c) = ($1, $2);
1363 chomp $c;
1357 - if ($c eq $sender) {
1364 + my $sc = sanitize_address($c);
1365 + if ($sc eq $sender) {
1366 next if ($suppress_cc{'self'});
1367 } else {
1368 next if $suppress_cc{'sob'} and $what =~ /Signed-off-by/i;
@@ -1438,7 +1446,6 @@ foreach my $t (@files) {
1446 sub recipients_cmd {
1447 my ($prefix, $what, $cmd, $file) = @_;
1448
1441 - my $sanitized_sender = sanitize_address($sender);
1449 my @addresses = ();
1450 open my $fh, "-|", "$cmd \Q$file\E"
1451 or die "($prefix) Could not execute '$cmd'";
@@ -1446,7 +1453,7 @@ sub recipients_cmd {
1453 $address =~ s/^\s*//g;
1454 $address =~ s/\s*$//g;
1455 $address = sanitize_address($address);
1449 - next if ($address eq $sanitized_sender and $suppress_cc{'self'});
1456 + next if ($address eq $sender and $suppress_cc{'self'});
1457 push @addresses, $address;
1458 printf("($prefix) Adding %s: %s from: '%s'\n",
1459 $what, $address, $cmd) unless $quiet;