git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: "Problems" with git format-patch --thread email header ordering

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 5, 2019, 05:24 UTC
Message-ID
<xmqq7ec9dnxs.fsf@gitster-ct.c.googlers.com>
In-Reply-To
<20190404180653.curtoo7yot6tpqfk@jak-t480s>
Julian Andres Klode <jak@jak-linux.org> writes:
Show 21 quoted lines
>> What Thomas Found out was that the exact same email with
>> 
>>     Message-Id/From/Date/Subject/To
>> 
>> (in that order) does not work, but
>> 
>>     Date/From/Subject/To/Message-Id
>> 
>> does work. Weird and "wonderful". But there might be a lot of other
>> orderings that work or don't.
>> 
>> Having looked through some other emails, I know that
>> 
>>     From/To/Subject/Date/Message-Id
>>     Subject/To/References/From/Message-ID/Date
>> 
>> also works.  Which makes me suspect that it's the Message-ID line that matters.
>
> I also know that gmail rewrites the Message-ID / creates one if it is
> missing or "odd" (such as ends in a .). It those probably makes sense
> in that twisted world view to require that to be fairly late...

Here is a patch that is not polished enough to be commited yet but should be testable (as I suspect that existing tests need to be adjusted).

-- >8 --
Subject: [PATCH] format-patch: move message-id and related headers to the end

It has been reported that GMail MSA has an undocumented limitation that makes it reject or accept depending on some ordering of headers in the incoming message. The current suspicion is that they want to see the Message-Id: header near the end, so let's try doing so and see what happens..

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 log-tree.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)
diff --git a/log-tree.c b/log-tree.c
index 1e56df62a7..111b947264 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -363,24 +363,27 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 	const char *extra_headers = opt->extra_headers;
 	const char *name = oid_to_hex(opt->zero_commit ?
 				      &null_oid : &commit->object.oid);
+	struct strbuf message_ids = STRBUF_INIT;
 
 	*need_8bit_cte_p = 0; /* unknown */
 
 	fprintf(opt->diffopt.file, "From %s Mon Sep 17 00:00:00 2001\n", name);
 	graph_show_oneline(opt->graph);
-	if (opt->message_id) {
-		fprintf(opt->diffopt.file, "Message-Id: <%s>\n", opt->message_id);
-		graph_show_oneline(opt->graph);
-	}
+
+	if (opt->message_id)
+		strbuf_addf(&message_ids, "Message-Id: <%s>\n", opt->message_id);
+
 	if (opt->ref_message_ids && opt->ref_message_ids->nr > 0) {
 		int i, n;
 		n = opt->ref_message_ids->nr;
-		fprintf(opt->diffopt.file, "In-Reply-To: <%s>\n", opt->ref_message_ids->items[n-1].string);
+		strbuf_addf(&message_ids, "In-Reply-To: <%s>\n",
+			    opt->ref_message_ids->items[n-1].string);
 		for (i = 0; i < n; i++)
-			fprintf(opt->diffopt.file, "%s<%s>\n", (i > 0 ? "\t" : "References: "),
-			       opt->ref_message_ids->items[i].string);
-		graph_show_oneline(opt->graph);
+			strbuf_addf(&message_ids, "%s<%s>\n",
+				    (i > 0 ? "\t" : "References: "),
+				    opt->ref_message_ids->items[i].string);
 	}
+
 	if (opt->mime_boundary && maybe_multipart) {
 		static struct strbuf subject_buffer = STRBUF_INIT;
 		static struct strbuf buffer = STRBUF_INIT;
@@ -425,6 +428,17 @@ void log_write_email_headers(struct rev_info *opt, struct commit *commit,
 		opt->diffopt.stat_sep = buffer.buf;
 		strbuf_release(&filename);
 	}
+
+	if (message_ids.len) {
+		static struct strbuf buf = STRBUF_INIT;
+
+		strbuf_reset(&buf);
+		strbuf_addbuf(&buf, &message_ids);
+		if (extra_headers)
+			strbuf_addstr(&buf, extra_headers);
+		extra_headers = buf.buf;
+	}
+
 	*extra_headers_p = extra_headers;
 }
 
-- 
2.21.0-197-g893dd55891
Previous: Julian Andres Klode
Message 5 of 5 in “"Problems" with git format-patch --thread email header ordering”
  1. Linus TorvaldsMar 14, 2019
  2. Junio C HamanoMar 15, 2019
  3. Linus TorvaldsMar 15, 2019
  4. Julian Andres KlodeApr 4, 2019
  5. Junio C HamanoApr 5, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.