# [PATCH] send-email: avoid duplicate In-Reply-To/References

3 messages from 2018-04-17 to 2018-04-18. Participants: Stefan Agner, Eric Wong.
Thread: https://gitlist.dev/t/48315

## Stefan Agner, 2018-04-17 21:16

Subject: [PATCH] send-email: avoid duplicate In-Reply-To/References
Message-ID: <20180417211630.22873-1-stefan@agner.ch>
URL: https://gitlist.dev/e/20180417211630.22873-1-stefan%40agner.ch

```
In case a patch already has In-Reply-To or References in the header
(e.g. when the patch has been created with format-patch --thread)
git-send-email should not add another pair of those headers.
This is also not allowed according to RFC 5322 Section 3.6:
https://tools.ietf.org/html/rfc5322#section-3.6

Avoid the second pair by reading the current headers into the
appropriate variables.

Signed-off-by: Stefan Agner <stefan@agner.ch>
---
This addresses the issue reported here:
https://public-inbox.org/git/997160314bbafb3088a401f1c09ccb08@agner.ch/

 git-send-email.perl | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 2fa7818ca..7157397fd 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1642,10 +1642,15 @@ foreach my $t (@files) {
 			elsif (/^Content-Transfer-Encoding: (.*)/i) {
 				$xfer_encoding = $1 if not defined $xfer_encoding;
 			}
+			elsif (/^In-Reply-To: (.*)/i) {
+				$in_reply_to = $1;
+			}
+			elsif (/^References: (.*)/i) {
+				$references = $1;
+			}
 			elsif (!/^Date:\s/i && /^[-A-Za-z]+:\s+\S/) {
 				push @xh, $_;
 			}
-
 		} else {
 			# In the traditional
 			# "send lots of email" format,
-- 
2.17.0


```

## Eric Wong, 2018-04-18 00:54

Subject: Re: [PATCH] send-email: avoid duplicate In-Reply-To/References
Message-ID: <20180418005415.GA31588@dcvr>
URL: https://gitlist.dev/e/20180418005415.GA31588%40dcvr
In-Reply-To: <20180417211630.22873-1-stefan@agner.ch>

```
Stefan Agner <stefan@agner.ch> wrote:
> This addresses the issue reported here:
> https://public-inbox.org/git/997160314bbafb3088a401f1c09ccb08@agner.ch/

Thanks for bringing this up.

> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -1642,10 +1642,15 @@ foreach my $t (@files) {
>  			elsif (/^Content-Transfer-Encoding: (.*)/i) {
>  				$xfer_encoding = $1 if not defined $xfer_encoding;
>  			}
> +			elsif (/^In-Reply-To: (.*)/i) {
> +				$in_reply_to = $1;
> +			}
> +			elsif (/^References: (.*)/i) {
> +				$references = $1;
> +			}

References: can span multiple lines with --thread=deep in format-patch
(technically any header can be, but References: is common)

```

## Stefan Agner, 2018-04-18 07:38

Subject: Re: [PATCH] send-email: avoid duplicate In-Reply-To/References
Message-ID: <d218005b0c44b7f8a61c82d060352eee@agner.ch>
URL: https://gitlist.dev/e/d218005b0c44b7f8a61c82d060352eee%40agner.ch
In-Reply-To: <20180418005415.GA31588@dcvr>

```
On 18.04.2018 02:54, Eric Wong wrote:
> Stefan Agner <stefan@agner.ch> wrote:
>> This addresses the issue reported here:
>> https://public-inbox.org/git/997160314bbafb3088a401f1c09ccb08@agner.ch/
> 
> Thanks for bringing this up.
> 
>> --- a/git-send-email.perl
>> +++ b/git-send-email.perl
>> @@ -1642,10 +1642,15 @@ foreach my $t (@files) {
>>  			elsif (/^Content-Transfer-Encoding: (.*)/i) {
>>  				$xfer_encoding = $1 if not defined $xfer_encoding;
>>  			}
>> +			elsif (/^In-Reply-To: (.*)/i) {
>> +				$in_reply_to = $1;
>> +			}
>> +			elsif (/^References: (.*)/i) {
>> +				$references = $1;
>> +			}
> 
> References: can span multiple lines with --thread=deep in format-patch
> (technically any header can be, but References: is common)

I think that is ok because we do
# First unfold multiline header fields

...

A quick test with 3 patches in --thread=deep mode looks good:
In-Reply-To:
<87d48c04aae0594ebea7567827d08979ad346380.1524034203.git.stefan@agner.ch>
References:
<06ea66574abfb2dd66adee9996e5fb66903b95a3.1524034203.git.stefan@agner.ch>
<87d48c04aae0594ebea7567827d08979ad346380.1524034203.git.stefan@agner.ch>

--
Stefan

```
