Git development
 help / color / mirror / Atom feed
From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
	Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH v5 0/4] imap-send: fix with reordered message headers
Date: Sun, 01 Nov 2026 08:21:33 +0000	[thread overview]
Message-ID: <pull.2456.v5.git.git.1793521297.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2456.git.git.1792437558.gitgitgadget@gmail.com>

git imap-send rejected patches sent with git send-email, such as ones
fetched from lore with b4, because it expected Date before Subject.

Changes in v5:

 * End the header block at an empty line in a CRLF mbox as well, so headers
   in the body or in later messages no longer count. Add a test.

Changes in v4:

 * Store the tunnel as an allocated pointer, so it is only finished when it
   was started, and drop the local tunnel variable
 * Add a test for lowercase from:, date: and subject: headers
 * Explain in the commit message why dropping the From git-send-email
   special case is fine for mboxes written by other scripts

Changes in v3:

 * Split concerns into different commits, commit message explains what they
   do.
 * Handle tunnel leak in the proper place.

Changes in v2:

 * Case insensitive header match according to RFC 822/2822/5322.

Harald Nordgren (4):
  imap-send: wait for the tunnel command to finish
  imap-send: accept messages with Subject before Date
  imap-send: check git send-email copies like other messages
  imap-send: match header names case insensitively

 imap-send.c           | 61 ++++++++++++++++++++-------------------
 t/t9001-send-email.sh | 66 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 98 insertions(+), 29 deletions(-)


base-commit: 50fe5cc63f9cd6e89b87a2c9ccf96a444f4cfdb7
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2456%2FHaraldNordgren%2Ffix%2Fimap-send-header-order-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2456/HaraldNordgren/fix/imap-send-header-order-v5
Pull-Request: https://github.com/git/git/pull/2456

Range-diff vs v4:

 1:  8941ae12bb = 1:  cb27ac3a27 imap-send: wait for the tunnel command to finish
 2:  ad3158b336 ! 2:  fa90c64a5c imap-send: accept messages with Subject before Date
     @@ Commit message
          and git send-email writes Subject before Date.
      
          Accept the three headers in any order within the header block of each
     -    message.
     +    message, which ends at the first empty line whether the mbox uses LF or
     +    CRLF line endings.
      
          Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
      
     @@ imap-send.c: static void wrap_in_html(struct strbuf *msg)
      +{
      +	bool from = false, date = false, subject = false;
      +
     -+	while ((line = strchr(line, '\n')) && *++line != '\n') {
     ++	while ((line = strchr(line, '\n')) &&
     ++	       *++line != '\n' && !starts_with(line, "\r\n")) {
      +		if (starts_with(line, "From: "))
      +			from = true;
      +		else if (starts_with(line, "Date: "))
     @@ t/t9001-send-email.sh: test_expect_success $PREREQ '--compose handles to headers
      +	test_grep "^Sending 1 message to INBOX folder" err &&
      +	test_grep "(1/1) done" err
      +'
     ++
     ++test_expect_success $PREREQ 'imap-send ignores headers in the body of a CRLF mbox' '
     ++	test_config imap.tunnel ./fake-imap-server &&
     ++	q_to_cr >crlf.mbox <<-\EOF &&
     ++	From mboxrd@z Thu Jan  1 00:00:00 1970Q
     ++	From: Example <from@example.com>Q
     ++	Subject: Fwd: originalQ
     ++	Q
     ++	---------- Forwarded message ---------Q
     ++	From: Someone <someone@example.com>Q
     ++	Date: Thu, 1 Jan 1970 00:00:00 +0000Q
     ++	Subject: originalQ
     ++	EOF
     ++	test_must_fail git imap-send --folder=INBOX <crlf.mbox 2>err &&
     ++	test_grep "no messages found to send" err
     ++'
      +
       test_done
 3:  919e38c31d ! 3:  8646185486 imap-send: check git send-email copies like other messages
     @@ imap-send.c: static int count_messages(struct strbuf *all_msgs)
       			break;
      
       ## t/t9001-send-email.sh ##
     -@@ t/t9001-send-email.sh: test_expect_success $PREREQ 'imap-send accepts a sent patch from the list archiv
     - 	test_grep "(1/1) done" err
     +@@ t/t9001-send-email.sh: test_expect_success $PREREQ 'imap-send ignores headers in the body of a CRLF mbo
     + 	test_grep "no messages found to send" err
       '
       
      +test_expect_success $PREREQ '--imap-sent-folder stores a copy of the sent patch' '
 4:  5b4a08bbda ! 4:  e7d1d7cd72 imap-send: match header names case insensitively
     @@ Commit message
      
       ## imap-send.c ##
      @@ imap-send.c: static bool has_required_headers(const char *line)
     - 	bool from = false, date = false, subject = false;
       
     - 	while ((line = strchr(line, '\n')) && *++line != '\n') {
     + 	while ((line = strchr(line, '\n')) &&
     + 	       *++line != '\n' && !starts_with(line, "\r\n")) {
      -		if (starts_with(line, "From: "))
      +		if (istarts_with(line, "From: "))
       			from = true;

-- 
gitgitgadget

  parent reply	other threads:[~2026-11-01  8:21 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 19:19 [PATCH 0/2] Fix imap-send with reordered message headers Harald Nordgren via GitGitGadget
2026-10-19 19:19 ` [PATCH 1/2] imap-send: avoid leaking the tunnel command Harald Nordgren via GitGitGadget
2026-10-19 19:19 ` [PATCH 2/2] imap-send: accept messages with Subject before Date Harald Nordgren via GitGitGadget
2026-10-19 22:00   ` Junio C Hamano
2026-10-20  7:28     ` Harald Nordgren
2026-10-21  7:07 ` [PATCH v2 0/2] Fix imap-send with reordered message headers Harald Nordgren via GitGitGadget
2026-10-21  7:07   ` [PATCH v2 1/2] imap-send: avoid leaking the tunnel command Harald Nordgren via GitGitGadget
2026-10-21  8:24     ` Patrick Steinhardt
2026-10-21  8:53       ` Harald Nordgren
2026-10-21  7:07   ` [PATCH v2 2/2] imap-send: accept messages with Subject before Date Harald Nordgren via GitGitGadget
2026-10-21  8:25     ` Patrick Steinhardt
2026-10-21  8:45       ` Harald Nordgren
2026-10-21  9:36         ` Patrick Steinhardt
2026-10-21  9:59           ` Harald Nordgren
2026-10-22  6:56 ` [PATCH v3 0/4] Fix imap-send with reordered message headers Harald Nordgren via GitGitGadget
2026-10-22  6:56   ` [PATCH v3 1/4] imap-send: wait for the tunnel command to finish Harald Nordgren via GitGitGadget
2026-10-26  9:42     ` Patrick Steinhardt
2026-10-26  9:59       ` Harald Nordgren
2026-10-22  6:56   ` [PATCH v3 2/4] imap-send: accept messages with Subject before Date Harald Nordgren via GitGitGadget
2026-10-22  6:56   ` [PATCH v3 3/4] imap-send: check git send-email copies like other messages Harald Nordgren via GitGitGadget
2026-10-26  9:42     ` Patrick Steinhardt
2026-10-26 10:02       ` Harald Nordgren
2026-10-22  6:56   ` [PATCH v3 4/4] imap-send: match header names case insensitively Harald Nordgren via GitGitGadget
2026-10-26  9:42     ` Patrick Steinhardt
2026-10-27  8:31 ` [PATCH v4 0/4] Fix imap-send with reordered message headers Harald Nordgren via GitGitGadget
2026-10-27  8:31   ` [PATCH v4 1/4] imap-send: wait for the tunnel command to finish Harald Nordgren via GitGitGadget
2026-10-27  8:31   ` [PATCH v4 2/4] imap-send: accept messages with Subject before Date Harald Nordgren via GitGitGadget
2026-10-30 22:51     ` Junio C Hamano
2026-10-31  7:58       ` Harald Nordgren
2026-10-27  8:31   ` [PATCH v4 3/4] imap-send: check git send-email copies like other messages Harald Nordgren via GitGitGadget
2026-10-27 10:59     ` Patrick Steinhardt
2026-10-27  8:31   ` [PATCH v4 4/4] imap-send: match header names case insensitively Harald Nordgren via GitGitGadget
2026-10-27 10:59   ` [PATCH v4 0/4] Fix imap-send with reordered message headers Patrick Steinhardt
2026-10-29 14:29     ` Junio C Hamano
2026-11-01  8:21 ` Harald Nordgren via GitGitGadget [this message]
2026-11-01  8:21   ` [PATCH v5 1/4] imap-send: wait for the tunnel command to finish Harald Nordgren via GitGitGadget
2026-11-01  8:21   ` [PATCH v5 2/4] imap-send: accept messages with Subject before Date Harald Nordgren via GitGitGadget
2026-11-01  8:21   ` [PATCH v5 3/4] imap-send: check git send-email copies like other messages Harald Nordgren via GitGitGadget
2026-11-01  8:21   ` [PATCH v5 4/4] imap-send: match header names case insensitively Harald Nordgren via GitGitGadget

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

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

  git send-email \
    --in-reply-to=pull.2456.v5.git.git.1793521297.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=haraldnordgren@gmail.com \
    --cc=ps@pks.im \
    /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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox