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

[PATCH v5 0/4] imap-send: fix with reordered message headers

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 1, 2026, 08:21 UTC
Message-ID
<pull.2456.v5.git.git.1793521297.gitgitgadget@gmail.com>
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
Previous: Junio C HamanoNext: Harald Nordgren via GitGitGadget
Message 35 of 39 in “Fix imap-send with reordered message headers”
  1. 0/2 Fix imap-send with reordered message headersHarald Nordgren via GitGitGadget, Oct 19, 2026
  2. 1/2 imap-send: avoid leaking the tunnel commandHarald Nordgren via GitGitGadget, Oct 19, 2026
  3. 2/2 imap-send: accept messages with Subject before DateHarald Nordgren via GitGitGadget, Oct 19, 2026
  4. Junio C HamanoOct 19, 2026
  5. Harald NordgrenOct 20, 2026
  6. 0/2 Fix imap-send with reordered message headersHarald Nordgren via GitGitGadget, Oct 21, 2026
  7. 1/2 imap-send: avoid leaking the tunnel commandHarald Nordgren via GitGitGadget, Oct 21, 2026
  8. Patrick SteinhardtOct 21, 2026
  9. Harald NordgrenOct 21, 2026
  10. 2/2 imap-send: accept messages with Subject before DateHarald Nordgren via GitGitGadget, Oct 21, 2026
  11. Patrick SteinhardtOct 21, 2026
  12. Harald NordgrenOct 21, 2026
  13. Patrick SteinhardtOct 21, 2026
  14. Harald NordgrenOct 21, 2026
  15. 0/4 Fix imap-send with reordered message headersHarald Nordgren via GitGitGadget, Oct 22, 2026
  16. 1/4 imap-send: wait for the tunnel command to finishHarald Nordgren via GitGitGadget, Oct 22, 2026
  17. Patrick SteinhardtOct 26, 2026
  18. Harald NordgrenOct 26, 2026
  19. 2/4 imap-send: accept messages with Subject before DateHarald Nordgren via GitGitGadget, Oct 22, 2026
  20. 3/4 imap-send: check git send-email copies like other messagesHarald Nordgren via GitGitGadget, Oct 22, 2026
  21. Patrick SteinhardtOct 26, 2026
  22. Harald NordgrenOct 26, 2026
  23. 4/4 imap-send: match header names case insensitivelyHarald Nordgren via GitGitGadget, Oct 22, 2026
  24. Patrick SteinhardtOct 26, 2026
  25. 0/4 Fix imap-send with reordered message headersHarald Nordgren via GitGitGadget, Oct 27, 2026
  26. 1/4 imap-send: wait for the tunnel command to finishHarald Nordgren via GitGitGadget, Oct 27, 2026
  27. 2/4 imap-send: accept messages with Subject before DateHarald Nordgren via GitGitGadget, Oct 27, 2026
  28. Junio C HamanoOct 30, 2026
  29. Harald NordgrenOct 31, 2026
  30. 3/4 imap-send: check git send-email copies like other messagesHarald Nordgren via GitGitGadget, Oct 27, 2026
  31. Patrick SteinhardtOct 27, 2026
  32. 4/4 imap-send: match header names case insensitivelyHarald Nordgren via GitGitGadget, Oct 27, 2026
  33. Patrick SteinhardtOct 27, 2026
  34. Junio C HamanoOct 29, 2026
  35. 0/4 imap-send: fix with reordered message headersHarald Nordgren via GitGitGadget, Nov 1, 2026
  36. 1/4 imap-send: wait for the tunnel command to finishHarald Nordgren via GitGitGadget, Nov 1, 2026
  37. 2/4 imap-send: accept messages with Subject before DateHarald Nordgren via GitGitGadget, Nov 1, 2026
  38. 3/4 imap-send: check git send-email copies like other messagesHarald Nordgren via GitGitGadget, Nov 1, 2026
  39. 4/4 imap-send: match header names case insensitivelyHarald Nordgren via GitGitGadget, Nov 1, 2026

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.