Skip to content

Commit e3fdbcc

Browse files
moygitster
authored andcommitted
parse_mailboxes: accept extra text after <...> address
The test introduced in this commit succeeds without the patch to Git.pm if Mail::Address is installed, but fails otherwise because our in-house parser does not accept any text after the email address. They succeed both with and without Mail::Address after this commit. Mail::Address accepts extra text and considers it as part of the name, iff the address is surrounded with <...>. The implementation mimics this behavior as closely as possible. This mostly restores the behavior we had before b1c8a11 (send-email: allow multiple emails using --cc, --to and --bcc, 2015-06-30), but we keep the possibility to handle comma-separated lists. Reported-by: Larry Finger <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa5b1aa commit e3fdbcc

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

perl/Git.pm

+7-6
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,7 @@ sub parse_mailboxes {
878878
# divide the string in tokens of the above form
879879
my $re_token = qr/(?:$re_quote|$re_word|$re_comment|\S)/;
880880
my @tokens = map { $_ =~ /\s*($re_token)\s*/g } @_;
881+
my $end_of_addr_seen = 0;
881882

882883
# add a delimiter to simplify treatment for the last mailbox
883884
push @tokens, ",";
@@ -887,10 +888,10 @@ sub parse_mailboxes {
887888
if ($token =~ /^[,;]$/) {
888889
# if buffer still contains undeterminated strings
889890
# append it at the end of @address or @phrase
890-
if (@address) {
891-
push @address, @buffer;
892-
} else {
891+
if ($end_of_addr_seen) {
893892
push @phrase, @buffer;
893+
} else {
894+
push @address, @buffer;
894895
}
895896

896897
my $str_phrase = join ' ', @phrase;
@@ -914,16 +915,16 @@ sub parse_mailboxes {
914915
push @addr_list, $str_mailbox if ($str_mailbox);
915916

916917
@phrase = @address = @comment = @buffer = ();
918+
$end_of_addr_seen = 0;
917919
} elsif ($token =~ /^\(/) {
918920
push @comment, $token;
919921
} elsif ($token eq "<") {
920922
push @phrase, (splice @address), (splice @buffer);
921923
} elsif ($token eq ">") {
924+
$end_of_addr_seen = 1;
922925
push @address, (splice @buffer);
923-
} elsif ($token eq "@") {
926+
} elsif ($token eq "@" && !$end_of_addr_seen) {
924927
push @address, (splice @buffer), "@";
925-
} elsif ($token eq ".") {
926-
push @address, (splice @buffer), ".";
927928
} else {
928929
push @buffer, $token;
929930
}

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)