From c852531f451331eb9d5ba57d154b0e150246a438 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cs=C3=B3k=C3=A1s=2C=20Bence?= Date: Mon, 1 Jul 2024 11:01:16 +0200 Subject: [PATCH] git-send-email: use sanitized address when reading mbox body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- git-send-email.perl | 4 ++-- t/t9001-send-email.sh | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 821b2b3a13..c351bb0d98 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1844,9 +1844,9 @@ sub pre_process_file { $what, $_) unless $quiet; next; } - push @cc, $c; + push @cc, $sc; printf(__("(body) Adding cc: %s from line '%s'\n"), - $c, $_) unless $quiet; + $sc, $_) unless $quiet; } } close $fh; diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 5a771000c9..4d7e61af6f 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1299,6 +1299,49 @@ test_expect_success $PREREQ 'utf8 sender is not duplicated' ' test_line_count = 1 msgfrom ' +test_expect_success $PREREQ 'setup expect for cc list' " +cat >expected-cc <<\EOF +!recipient@example.com! +!author@example.com! +!one@example.com! +!os@example.com! +!odd_?=mail@example.com! +!doug@example.com! +!codev@example.com! +!thor.au@example.com! +EOF +" + +test_expect_success $PREREQ 'cc list is sanitized' ' + clean_fake_sendmail && + test_commit weird_cc_body && + test_when_finished "git reset --hard HEAD^" && + git commit --amend -F - <<-EOF && + Test Cc: sanitization. + + Cc: Person, One + Cc: Ronnie O${SQ}Sullivan + Reviewed-by: Füñný Nâmé + Reported-by: bugger on Jira + Reported-by: Douglas Reporter [from Jira profile] + BugID: 12345 + Co-developed-by: "C. O. Developer" + Signed-off-by: A. U. Thor + EOF + git send-email -1 --to=recipient@example.com \ + --smtp-server="$(pwd)/fake.sendmail" >actual-show-all-headers && + test_cmp expected-cc commandline1 && + test_grep "^(body) Adding cc: \"Person, One\" " actual-show-all-headers && + test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan " actual-show-all-headers && + test_grep "^(body) Adding cc: =?UTF-8?q?F=C3=BC=C3=B1n=C3=BD=20N=C3=A2m=C3=A9?="\ +" " actual-show-all-headers && + test_grep "^(body) Ignoring Reported-by .* bugger on Jira" actual-show-all-headers && + test_grep "^(body) Adding cc: Douglas Reporter " actual-show-all-headers && + test_grep ! "12345" actual-show-all-headers && + test_grep "^(body) Adding cc: \"C. O. Developer\" " actual-show-all-headers && + test_grep "^(body) Adding cc: \"A. U. Thor\" " actual-show-all-headers +' + test_expect_success $PREREQ 'sendemail.composeencoding works' ' clean_fake_sendmail && git config sendemail.composeencoding iso-8859-1 &&