Skip to content

Commit c852531

Browse files
Csókás, Bencegitster
authored andcommitted
git-send-email: use sanitized address when reading mbox body
Addresses that are mentioned on the trailers in the commit log messages (e.g., "Reviewed-by") are added to the "Cc:" list by "git send-email". These hand-written addresses, however, may be malformed (e.g., having unquoted "." and other punctutation marks in the display-name part) and can upset MTA. The code does use the sanitize_address() helper on these address-looking strings to turn them into valid addresses, but it is used only to see if the address should be suppressed. The original string taken from the message is added to the @cc list if the code decides the address is not suppressed. Because the addresses on trailer lines are hand-written and more likely to contain malformed addresses, when adding to the @cc list, use the result from sanitize_address, not the original. Note that we do not modify the behaviour for addresses taken from the e-mail headers, as they are more likely to be machine generated and well-formed. Signed-off-by: Csókás, Bence <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 786a3e4 commit c852531

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

git-send-email.perl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1844,9 +1844,9 @@ sub pre_process_file {
18441844
$what, $_) unless $quiet;
18451845
next;
18461846
}
1847-
push @cc, $c;
1847+
push @cc, $sc;
18481848
printf(__("(body) Adding cc: %s from line '%s'\n"),
1849-
$c, $_) unless $quiet;
1849+
$sc, $_) unless $quiet;
18501850
}
18511851
}
18521852
close $fh;

t/t9001-send-email.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,6 +1299,49 @@ test_expect_success $PREREQ 'utf8 sender is not duplicated' '
12991299
test_line_count = 1 msgfrom
13001300
'
13011301

1302+
test_expect_success $PREREQ 'setup expect for cc list' "
1303+
cat >expected-cc <<\EOF
1304+
1305+
1306+
1307+
1308+
1309+
1310+
1311+
1312+
EOF
1313+
"
1314+
1315+
test_expect_success $PREREQ 'cc list is sanitized' '
1316+
clean_fake_sendmail &&
1317+
test_commit weird_cc_body &&
1318+
test_when_finished "git reset --hard HEAD^" &&
1319+
git commit --amend -F - <<-EOF &&
1320+
Test Cc: sanitization.
1321+
1322+
Cc: Person, One <[email protected]>
1323+
Cc: Ronnie O${SQ}Sullivan <[email protected]>
1324+
Reviewed-by: Füñný Nâmé <[email protected]>
1325+
Reported-by: bugger on Jira
1326+
Reported-by: Douglas Reporter <[email protected]> [from Jira profile]
1327+
BugID: 12345
1328+
Co-developed-by: "C. O. Developer" <[email protected]>
1329+
Signed-off-by: A. U. Thor <[email protected]>
1330+
EOF
1331+
git send-email -1 [email protected] \
1332+
--smtp-server="$(pwd)/fake.sendmail" >actual-show-all-headers &&
1333+
test_cmp expected-cc commandline1 &&
1334+
test_grep "^(body) Adding cc: \"Person, One\" <[email protected]>" actual-show-all-headers &&
1335+
test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan <[email protected]>" actual-show-all-headers &&
1336+
test_grep "^(body) Adding cc: =?UTF-8?q?F=C3=BC=C3=B1n=C3=BD=20N=C3=A2m=C3=A9?="\
1337+
" <[email protected]>" actual-show-all-headers &&
1338+
test_grep "^(body) Ignoring Reported-by .* bugger on Jira" actual-show-all-headers &&
1339+
test_grep "^(body) Adding cc: Douglas Reporter <[email protected]>" actual-show-all-headers &&
1340+
test_grep ! "12345" actual-show-all-headers &&
1341+
test_grep "^(body) Adding cc: \"C. O. Developer\" <[email protected]>" actual-show-all-headers &&
1342+
test_grep "^(body) Adding cc: \"A. U. Thor\" <[email protected]>" actual-show-all-headers
1343+
'
1344+
13021345
test_expect_success $PREREQ 'sendemail.composeencoding works' '
13031346
clean_fake_sendmail &&
13041347
git config sendemail.composeencoding iso-8859-1 &&

0 commit comments

Comments
 (0)