1
0
mirror of https://github.com/git/git.git synced 2024-11-19 09:33:59 +01:00

Merge branch 'mm/send-email-cc-cruft' into maint

In addition to "cc: <a@dd.re.ss> # cruft", "cc: a@dd.re.ss # cruft"
was taught to "git send-email" as a valid way to tell it that it
needs to also send a carbon copy to <a@dd.re.ss> in the trailer
section.

* mm/send-email-cc-cruft:
  send-email: don't use Mail::Address, even if available
  send-email: fix garbage removal after address
This commit is contained in:
Junio C Hamano 2017-10-18 14:18:58 +09:00
commit 05e408dd1a
2 changed files with 29 additions and 8 deletions

@ -155,7 +155,6 @@ sub format_2822_time {
}
my $have_email_valid = eval { require Email::Valid; 1 };
my $have_mail_address = eval { require Mail::Address; 1 };
my $smtp;
my $auth;
my $num_sent = 0;
@ -490,11 +489,7 @@ my ($repoauthor, $repocommitter);
($repocommitter) = Git::ident_person(@repo, 'committer');
sub parse_address_line {
if ($have_mail_address) {
return map { $_->format } Mail::Address->parse($_[0]);
} else {
return Git::parse_mailboxes($_[0]);
}
return Git::parse_mailboxes($_[0]);
}
sub split_addrs {
@ -1089,6 +1084,26 @@ sub sanitize_address {
}
sub strip_garbage_one_address {
my ($addr) = @_;
chomp $addr;
if ($addr =~ /^(("[^"]*"|[^"<]*)? *<[^>]*>).*/) {
# "Foo Bar" <foobar@example.com> [possibly garbage here]
# Foo Bar <foobar@example.com> [possibly garbage here]
return $1;
}
if ($addr =~ /^(<[^>]*>).*/) {
# <foo@example.com> [possibly garbage here]
# if garbage contains other addresses, they are ignored.
return $1;
}
if ($addr =~ /^([^"#,\s]*)/) {
# address without quoting: remove anything after the address
return $1;
}
return $addr;
}
sub sanitize_address_list {
return (map { sanitize_address($_) } @_);
}
@ -1590,10 +1605,12 @@ foreach my $t (@files) {
# Now parse the message body
while(<$fh>) {
$message .= $_;
if (/^(Signed-off-by|Cc): ([^>]*>?)/i) {
if (/^(Signed-off-by|Cc): (.*)/i) {
chomp;
my ($what, $c) = ($1, $2);
chomp $c;
# strip garbage for the address we'll use:
$c = strip_garbage_one_address($c);
# sanitize a bit more to decide whether to suppress the address:
my $sc = sanitize_address($c);
if ($sc eq $sender) {
next if ($suppress_cc{'self'});

@ -148,6 +148,8 @@ cat >expected-cc <<\EOF
!two@example.com!
!three@example.com!
!four@example.com!
!five@example.com!
!six@example.com!
EOF
"
@ -161,6 +163,8 @@ test_expect_success $PREREQ 'cc trailer with various syntax' '
Cc: <two@example.com> # trailing comments are ignored
Cc: <three@example.com>, <not.four@example.com> one address per line
Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
Cc: five@example.com # not.six@example.com
Cc: six@example.com, not.seven@example.com
EOF
clean_fake_sendmail &&
git send-email -1 --to=recipient@example.com \