Skip to content

Commit 3ece9bf

Browse files
committed
send-email: clear the $message_id after validation
Recently git-send-email started parsing the same message twice, once to validate _all_ the message before sending even the first one, and then after the validation hook is happy and each message gets sent, to read the contents to find out where to send to etc. Unfortunately, the effect of reading the messages for validation lingered even after the validation is done. Namely $message_id gets assigned if exists in the input files but the variable is global, and it is not cleared before pre_process_file runs. This causes reading a message without a message-id followed by reading a message with a message-id to misbehave---the sub reports as if the message had the same id as the previously written one. Clear the variable before starting to read the headers in pre_process_file. Tested-by: Douglas Anderson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8022c5 commit 3ece9bf

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

git-send-email.perl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,8 @@ sub pre_process_file {
17681768
$subject = $initial_subject;
17691769
$message = "";
17701770
$message_num++;
1771+
undef $message_id;
1772+
17711773
# First unfold multiline header fields
17721774
while(<$fh>) {
17731775
last if /^\s*$/;

t/t9001-send-email.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ clean_fake_sendmail () {
4747

4848
test_expect_success $PREREQ 'Extract patches' '
4949
patches=$(git format-patch -s --cc="One <[email protected]>" [email protected] -n HEAD^1) &&
50-
threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1)
50+
threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1)
5151
'
5252

5353
# Test no confirm early to ensure remaining tests will not hang
@@ -588,6 +588,21 @@ test_expect_success $PREREQ "--validate hook supports header argument" '
588588
outdir/000?-*.patch
589589
'
590590

591+
test_expect_success $PREREQ 'clear message-id before parsing a new message' '
592+
clean_fake_sendmail &&
593+
echo true | write_script my-hooks/sendemail-validate &&
594+
test_config core.hooksPath my-hooks &&
595+
GIT_SEND_EMAIL_NOTTY=1 \
596+
git send-email --validate [email protected] \
597+
--smtp-server="$(pwd)/fake.sendmail" \
598+
$patches $threaded_patches &&
599+
id0=$(grep "^Message-ID: " $threaded_patches) &&
600+
id1=$(grep "^Message-ID: " msgtxt1) &&
601+
id2=$(grep "^Message-ID: " msgtxt2) &&
602+
test "z$id0" = "z$id2" &&
603+
test "z$id1" != "z$id2"
604+
'
605+
591606
for enc in 7bit 8bit quoted-printable base64
592607
do
593608
test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '

0 commit comments

Comments
 (0)