[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.imPublished-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