Merge branch 'mh/send-email-reset-in-reply-to' into maint

Even when running "git send-email" without its own threaded
discussion support, a threading related header in one message is
carried over to the subsequent message to result in an unwanted
threading, which has been corrected.

* mh/send-email-reset-in-reply-to:
  send-email: avoid incorrect header propagation
This commit is contained in:
Junio C Hamano
2021-10-12 13:51:43 -07:00
2 changed files with 62 additions and 9 deletions

View File

@ -1697,7 +1697,6 @@ EOF
$in_reply_to = $initial_in_reply_to; $in_reply_to = $initial_in_reply_to;
$references = $initial_in_reply_to || ''; $references = $initial_in_reply_to || '';
$subject = $initial_subject;
$message_num = 0; $message_num = 0;
# Prepares the email, prompts the user, sends it out # Prepares the email, prompts the user, sends it out
@ -1720,6 +1719,7 @@ sub process_file {
@xh = (); @xh = ();
my $input_format = undef; my $input_format = undef;
my @header = (); my @header = ();
$subject = $initial_subject;
$message = ""; $message = "";
$message_num++; $message_num++;
# First unfold multiline header fields # First unfold multiline header fields
@ -1926,15 +1926,23 @@ sub process_file {
} }
# set up for the next message # set up for the next message
if ($thread && $message_was_sent && if ($thread) {
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 || if ($message_was_sent &&
$message_num == 1)) { ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
$in_reply_to = $message_id; $message_num == 1)) {
if (length $references > 0) { $in_reply_to = $message_id;
$references .= "\n $message_id"; if (length $references > 0) {
} else { $references .= "\n $message_id";
$references = "$message_id"; } else {
$references = "$message_id";
}
} }
} elsif (!defined $initial_in_reply_to) {
# --thread and --in-reply-to manage the "In-Reply-To" header and by
# extension the "References" header. If these commands are not used, reset
# the header values to their defaults.
$in_reply_to = undef;
$references = '';
} }
$message_id = undef; $message_id = undef;
$num_sent++; $num_sent++;

View File

@ -2227,6 +2227,51 @@ test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
test_path_is_file commandline1 test_path_is_file commandline1
' '
test_expect_success $PREREQ 'set up in-reply-to/references patches' '
cat >has-reply.patch <<-\EOF &&
From: A U Thor <author@example.com>
Subject: patch with in-reply-to
Message-ID: <patch.with.in.reply.to@example.com>
In-Reply-To: <replied.to@example.com>
References: <replied.to@example.com>
This is the body.
EOF
cat >no-reply.patch <<-\EOF
From: A U Thor <author@example.com>
Subject: patch without in-reply-to
Message-ID: <patch.without.in.reply.to@example.com>
This is the body.
EOF
'
test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
clean_fake_sendmail &&
git send-email \
--no-thread \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
has-reply.patch no-reply.patch &&
grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
grep "References: <replied.to@example.com>" msgtxt1 &&
! grep replied.to@example.com msgtxt2
'
test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
clean_fake_sendmail &&
git send-email \
--no-thread \
--in-reply-to="<cmdline.reply@example.com>" \
--to=nobody@example.com \
--smtp-server="$(pwd)/fake.sendmail" \
has-reply.patch no-reply.patch &&
grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
grep "References: <cmdline.reply@example.com>" msgtxt1 &&
grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
grep "References: <cmdline.reply@example.com>" msgtxt2
'
test_expect_success $PREREQ 'invoke hook' ' test_expect_success $PREREQ 'invoke hook' '
mkdir -p .git/hooks && mkdir -p .git/hooks &&