Git development
 help / color / mirror / Atom feed
From: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Harald Nordgren <haraldnordgren@gmail.com>,
	Harald Nordgren <haraldnordgren@gmail.com>
Subject: [PATCH] imap-send: make the header loop easier to read
Date: Tue, 24 Nov 2026 22:48:55 +0000	[thread overview]
Message-ID: <pull.2508.git.git.1795560535063.gitgitgadget@gmail.com> (raw)

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

             reply	other threads:[~2026-11-24 22:48 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 22:48 Harald Nordgren via GitGitGadget [this message]
2026-11-25  1:49 ` [PATCH] imap-send: make the header loop easier to read Junio C Hamano

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.2508.git.git.1795560535063.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=haraldnordgren@gmail.com \
    /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