Skip to content

Commit 5064d66

Browse files
committed
Merge branch 'mm/send-email-cc-cruft'
In addition to "cc: <[email protected]> # cruft", "cc: [email protected] # cruft" was taught to "git send-email" as a valid way to tell it that it needs to also send a carbon copy to <[email protected]> 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 7fbbd3e + cc90750 commit 5064d66

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

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" <[email protected]> [possibly garbage here]
1092+
# Foo Bar <[email protected]> [possibly garbage here]
1093+
return $1;
1094+
}
1095+
if ($addr =~ /^(<[^>]*>).*/) {
1096+
# <[email protected]> [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
149149
150150
151+
152+
151153
EOF
152154
"
153155

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

0 commit comments

Comments
 (0)