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

[PATCH] imap-send: make the header loop easier to read

From
Harald Nordgren via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 24, 2026, 22:48 UTC
Message-ID
<pull.2508.git.git.1795560535063.gitgitgadget@gmail.com>
From: Harald Nordgren <haraldnordgren@gmail.com>

The loop that looks for the From, Date and Subject headers of a message stops at the first empty line, which can end in LF or CRLF. The check for LF also moves to the next line, and the check for CRLF depends on that, which is easy to miss.

Check for both kinds of empty line in the same way, before moving to the next line. The behavior does not change.

Suggested-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
---
    imap-send: make the header loop easier to read
    
    Make the loop that finds the end of the message headers easier to read,
    as suggested in review of the series that is now in master:
    
    https://lore.kernel.org/git/avq0R5zx0PgSN-Oa@pks.im
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2508%2FHaraldNordgren%2Fimap-send-header-loop-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2508/HaraldNordgren/imap-send-header-loop-v1
Pull-Request: https://github.com/git/git/pull/2508
 imap-send.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/imap-send.c b/imap-send.c
index 1b5850a80e..c2d6b7c55a 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1462,7 +1462,9 @@ static bool has_required_headers(const char *line)
 	bool from = false, date = false, subject = false;
 
 	while ((line = strchr(line, '\n')) &&
-	       *++line != '\n' && !starts_with(line, "\r\n")) {
+	       !starts_with(line, "\n\n") &&
+	       !starts_with(line, "\n\r\n")) {
+		line++;
 		if (istarts_with(line, "From: "))
 			from = true;
 		else if (istarts_with(line, "Date: "))

base-commit: 77904e546de3bd940621092ecec47a88d0cede5d
-- 
gitgitgadget
Next: Junio C Hamano
Message 1 of 2 in “imap-send: make the header loop easier to read”
  1. imap-send: make the header loop easier to readHarald Nordgren via GitGitGadget, Nov 24, 2026
  2. Junio C HamanoNov 25, 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.