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

[PATCH 5/6] More accurately detect header lines in read_one_header_line

From
Eric W. Biederman <ebiederm@xmission.com>
Date
May 23, 2006, 19:53 UTC
Message-ID
<m1mzd8iklr.fsf_-_@ebiederm.dsl.xmission.com>
In-Reply-To
<m1r72kiksz.fsf_-_@ebiederm.dsl.xmission.com>

Only count lines of the form '^.*: ' and '^From ' as email header lines.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 mailinfo.c |   25 +++++++++++++++++--------
 1 files changed, 17 insertions(+), 8 deletions(-)
b955444f0bfb4ee9a5cd31686dd7eeec0750e235
diff --git a/mailinfo.c b/mailinfo.c
index 99989c2..c642ff4 100644
--- a/mailinfo.c
+++ b/mailinfo.c
@@ -385,20 +385,29 @@ static int read_one_header_line(char *li
 {
 	int ofs = 0;
 	while (ofs < sz) {
+		const char *colon;
 		int peek, len;
 		if (fgets(line + ofs, sz - ofs, in) == NULL)
-			return ofs;
+			break;
 		len = eatspace(line + ofs);
 		if (len == 0)
-			return ofs;
-		peek = fgetc(in); ungetc(peek, in);
-		if (peek == ' ' || peek == '\t') {
-			/* Yuck, 2822 header "folding" */
-			ofs += len;
-			continue;
+			break;
+		colon = strchr(line, ':');
+		if (!colon || !isspace(colon[1])) {
+			/* Readd the newline */
+			line[ofs + len] = '\n';
+			line[ofs + len + 1] = '\0';
+			break;
 		}
-		return ofs + len;
+		ofs += len;
+		/* Yuck, 2822 header "folding" */
+		peek = fgetc(in); ungetc(peek, in);
+		if (peek != ' ' && peek != '\t')
+			break;
 	}
+	/* Count mbox From headers as headers */
+	if (!ofs && !memcmp(line, "From ", 5))
+		ofs = 1;
 	return ofs;
 }
 
-- 
1.3.2.g5041c-dirty
Previous: Eric W. BiedermanNext: Eric W. Biederman
Message 6 of 10 in “Detect non email patches in git-mailinfo”
  1. 0/6 Detect non email patches in git-mailinfoEric W. Biederman, May 23, 2006
  2. 1/6 Make read_one_header_line return a flag not a length.Eric W. Biederman, May 23, 2006
  3. 2/6 Move B and Q decoding into check header.Eric W. Biederman, May 23, 2006
  4. 3/6 Refactor commit messge handling.Eric W. Biederman, May 23, 2006
  5. 4/6 In handle_body only read a line if we don't already have one.Eric W. Biederman, May 23, 2006
  6. 5/6 More accurately detect header lines in read_one_header_lineEric W. Biederman, May 23, 2006
  7. 6/6 Allow in body headers beyond the in body header prefix.Eric W. Biederman, May 23, 2006
  8. Junio C HamanoMay 26, 2006
  9. Junio C HamanoMay 23, 2006
  10. Eric W. BiedermanMay 26, 2006

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.