Skip to content

Commit 05e408d

Browse files
committed
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
2 parents 6c9d195 + cc90750 commit 05e408d

2 files changed

Lines changed: 29 additions & 8 deletions

File tree

git-send-email.perl

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ sub format_2822_time {
155155
}
156156

157157
my $have_email_valid = eval { require Email::Valid; 1 };
158-
my $have_mail_address = eval { require Mail::Address; 1 };
159158
my $smtp;
160159
my $auth;
161160
my $num_sent = 0;
@@ -490,11 +489,7 @@ sub read_config {
490489
($repocommitter) = Git::ident_person(@repo, 'committer');
491490

492491
sub parse_address_line {
493-
if ($have_mail_address) {
494-
return map { $_->format } Mail::Address->parse($_[0]);
495-
} else {
496-
return Git::parse_mailboxes($_[0]);
497-
}
492+
return Git::parse_mailboxes($_[0]);
498493
}
499494

500495
sub split_addrs {
@@ -1089,6 +1084,26 @@ sub sanitize_address {
10891084

10901085
}
10911086

1087+
sub strip_garbage_one_address {
1088+
my ($addr) = @_;
1089+
chomp $addr;
1090+
if ($addr =~ /^(("[^"]*"|[^"<]*)? *<[^>]*>).*/) {
1091+
# "Foo Bar" <foobar@example.com> [possibly garbage here]
1092+
# Foo Bar <foobar@example.com> [possibly garbage here]
1093+
return $1;
1094+
}
1095+
if ($addr =~ /^(<[^>]*>).*/) {
1096+
# <foo@example.com> [possibly garbage here]
1097+
# if garbage contains other addresses, they are ignored.
1098+
return $1;
1099+
}
1100+
if ($addr =~ /^([^"#,\s]*)/) {
1101+
# address without quoting: remove anything after the address
1102+
return $1;
1103+
}
1104+
return $addr;
1105+
}
1106+
10921107
sub sanitize_address_list {
10931108
return (map { sanitize_address($_) } @_);
10941109
}
@@ -1590,10 +1605,12 @@ sub send_message {
15901605
# Now parse the message body
15911606
while(<$fh>) {
15921607
$message .= $_;
1593-
if (/^(Signed-off-by|Cc): ([^>]*>?)/i) {
1608+
if (/^(Signed-off-by|Cc): (.*)/i) {
15941609
chomp;
15951610
my ($what, $c) = ($1, $2);
1596-
chomp $c;
1611+
# strip garbage for the address we'll use:
1612+
$c = strip_garbage_one_address($c);
1613+
# sanitize a bit more to decide whether to suppress the address:
15971614
my $sc = sanitize_address($c);
15981615
if ($sc eq $sender) {
15991616
next if ($suppress_cc{'self'});

t/t9001-send-email.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ cat >expected-cc <<\EOF
148148
!two@example.com!
149149
!three@example.com!
150150
!four@example.com!
151+
!five@example.com!
152+
!six@example.com!
151153
EOF
152154
"
153155

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

0 commit comments

Comments
 (0)