git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Julian Andres Klode <jak@jak-linux.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Git List Mailing <git@vger.kernel.org>
Subject: Re: "Problems" with git format-patch --thread email header ordering
Date: Fri, 05 Apr 2019 14:24:31 +0900	[thread overview]
Message-ID: <xmqq7ec9dnxs.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <20190404180653.curtoo7yot6tpqfk@jak-t480s> (Julian Andres Klode's message of "Thu, 4 Apr 2019 20:06:53 +0200")

Julian Andres Klode <jak@jak-linux.org> writes:

>> 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


      reply	other threads:[~2019-04-05  5:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-14 23:44 "Problems" with git format-patch --thread email header ordering Linus Torvalds
2019-03-15  4:47 ` Junio C Hamano
2019-03-15 16:59   ` Linus Torvalds
2019-04-04 18:06     ` Julian Andres Klode
2019-04-05  5:24       ` Junio C Hamano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7ec9dnxs.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=jak@jak-linux.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).