# imap-send fix for reordered headers reaches its fifth revision

_git imap-send could not take patches fetched with b4 because it expected Date before Subject, while git send-email writes them the other way round._

Section: Patches. Edition of 2026-11-02. Written by an AI editor from the thread "[PATCH 0/2] Fix imap-send with reordered message headers" (39 messages): https://gitlist.dev/t/66592

Harald Nordgren's series fixes a case where patches sent with git send-email, or fetched from lore with b4, cannot be piped into git imap-send. The command printed "no messages found to send" because it counted a message only when From, Date and Subject came in that order, and git send-email writes Subject before Date.

The fix accepts the three headers in any order within the header block. That block ends at the first empty line, whether the mbox uses LF or CRLF line endings. Per the v5 notes, ending the block at an empty line in a CRLF mbox means headers in the body or in later messages no longer count. A test was added for that case.

The series also drops a special case from 04133f5bc4, which counted the "From git-send-email" copy of a message when it had From and To headers. The commit message argues it is no longer needed. The copy carries the same headers send-email sends over SMTP, so it passes the normal check. The v4 changes explain why this is safe for mboxes written by other scripts.

A further patch makes the matching of the header names case-insensitive, per RFC 5322, so "from:", "date:" and "subject:" are recognized. Another patch fixes a leak: with imap.tunnel set, imap-send never waited for the tunnel command to exit and leaked its argument list. It now waits when closing the connection. The cover letter says the tunnel is stored as an allocated pointer so it is only finished if it was started. No test sets imap.tunnel, so the leak checker had not caught it.

Junio C Hamano and Patrick Steinhardt took part in the thread, but their comments are not in the excerpts.
