Skip to content

Commit bdcaebb

Browse files
committed
Merge branch 'mm/send-email-cc-cruft-after-address'
"git send-email" attempts to pick up valid e-mails from the trailers, but people in real world write non-addresses there, like "Cc: Stable <[email protected]> # 4.8+", which broke the output depending on the availability and vintage of Mail::Address perl module. * mm/send-email-cc-cruft-after-address: Git.pm: add comment pointing to t9000 t9000-addresses: update expected results after fix parse_mailboxes: accept extra text after <...> address
2 parents 24cfb6f + dcfafc5 commit bdcaebb

File tree

3 files changed

+42
-10
lines changed

3 files changed

+42
-10
lines changed

perl/Git.pm

+9-6
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,8 @@ Return an array of mailboxes extracted from a string.
871871
872872
=cut
873873

874+
# Very close to Mail::Address's parser, but we still have minor
875+
# differences in some cases (see t9000 for examples).
874876
sub parse_mailboxes {
875877
my $re_comment = qr/\((?:[^)]*)\)/;
876878
my $re_quote = qr/"(?:[^\"\\]|\\.)*"/;
@@ -879,6 +881,7 @@ sub parse_mailboxes {
879881
# divide the string in tokens of the above form
880882
my $re_token = qr/(?:$re_quote|$re_word|$re_comment|\S)/;
881883
my @tokens = map { $_ =~ /\s*($re_token)\s*/g } @_;
884+
my $end_of_addr_seen = 0;
882885

883886
# add a delimiter to simplify treatment for the last mailbox
884887
push @tokens, ",";
@@ -888,10 +891,10 @@ sub parse_mailboxes {
888891
if ($token =~ /^[,;]$/) {
889892
# if buffer still contains undeterminated strings
890893
# append it at the end of @address or @phrase
891-
if (@address) {
892-
push @address, @buffer;
893-
} else {
894+
if ($end_of_addr_seen) {
894895
push @phrase, @buffer;
896+
} else {
897+
push @address, @buffer;
895898
}
896899

897900
my $str_phrase = join ' ', @phrase;
@@ -915,16 +918,16 @@ sub parse_mailboxes {
915918
push @addr_list, $str_mailbox if ($str_mailbox);
916919

917920
@phrase = @address = @comment = @buffer = ();
921+
$end_of_addr_seen = 0;
918922
} elsif ($token =~ /^\(/) {
919923
push @comment, $token;
920924
} elsif ($token eq "<") {
921925
push @phrase, (splice @address), (splice @buffer);
922926
} elsif ($token eq ">") {
927+
$end_of_addr_seen = 1;
923928
push @address, (splice @buffer);
924-
} elsif ($token eq "@") {
929+
} elsif ($token eq "@" && !$end_of_addr_seen) {
925930
push @address, (splice @buffer), "@";
926-
} elsif ($token eq ".") {
927-
push @address, (splice @buffer), ".";
928931
} else {
929932
push @buffer, $token;
930933
}

t/t9000/test.pl

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
q["Jane\" Doe" <[email protected]>],
3333
q[Doe, jane <[email protected]>],
3434
q["Jane Doe <[email protected]>],
35-
q['Jane 'Doe' <[email protected]>]);
35+
q['Jane 'Doe' <[email protected]>],
36+
q[Jane@:;\.,()<>Doe <[email protected]>],
37+
q[Jane <[email protected]> Doe],
38+
q[<[email protected]> Jane Doe]);
3639

3740
my @known_failure_list = (q[Jane\ Doe <[email protected]>],
3841
q["Doe, Ja"ne <[email protected]>],
3942
q["Doe, Katarina" Jane <[email protected]>],
40-
q[Jane@:;\.,()<>Doe <[email protected]>],
4143
42-
q[<[email protected]> Jane Doe],
43-
q[Jane <[email protected]> Doe],
4444
q["Jane "Kat"a" ri"na" ",Doe" <[email protected]>],
4545
q[Jane Doe],
4646
q[Jane "Doe <[email protected]>"],

t/t9001-send-email.sh

+29
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,35 @@ test_expect_success $PREREQ 'Verify commandline' '
140140
test_cmp expected commandline1
141141
'
142142

143+
test_expect_success $PREREQ 'setup expect for cc trailer' "
144+
cat >expected-cc <<\EOF
145+
146+
147+
148+
149+
150+
151+
152+
EOF
153+
"
154+
155+
test_expect_success $PREREQ 'cc trailer with various syntax' '
156+
test_commit cc-trailer &&
157+
test_when_finished "git reset --hard HEAD^" &&
158+
git commit --amend -F - <<-EOF &&
159+
Test Cc: trailers.
160+
161+
162+
Cc: <[email protected]> # this is part of the name
163+
164+
Cc: "Some # Body" <[email protected]> [part.of.name.too]
165+
EOF
166+
clean_fake_sendmail &&
167+
git send-email -1 [email protected] \
168+
--smtp-server="$(pwd)/fake.sendmail" &&
169+
test_cmp expected-cc commandline1
170+
'
171+
143172
test_expect_success $PREREQ 'setup expect' "
144173
cat >expected-show-all-headers <<\EOF
145174
0001-Second.patch

0 commit comments

Comments
 (0)