@matheusbsbs / matheus-bagliano / commits / f30b20282b
Fork 0

More accurately detect header lines in read_one_header_line

Only count lines of the form '^.*: ' and '^From ' as email header lines. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Eric W. Biederman committed May 23, 2006 at 13:53 UTC f30b20282babcd77bcadef70b4e36e24cd1f6d59
1 file changed +17 -8
mailinfo.c
+17 -8
@@ -385,20 +385,29 @@ static int read_one_header_line(char *line, int sz, FILE *in)
385 {
386 int ofs = 0;
387 while (ofs < sz) {
388 + const char *colon;
389 int peek, len;
390 if (fgets(line + ofs, sz - ofs, in) == NULL)
390 - return ofs;
391 + break;
392 len = eatspace(line + ofs);
393 if (len == 0)
393 - return ofs;
394 - peek = fgetc(in); ungetc(peek, in);
395 - if (peek == ' ' || peek == '\t') {
396 - /* Yuck, 2822 header "folding" */
397 - ofs += len;
398 - continue;
394 + break;
395 + colon = strchr(line, ':');
396 + if (!colon || !isspace(colon[1])) {
397 + /* Re-add the newline */
398 + line[ofs + len] = '\n';
399 + line[ofs + len + 1] = '\0';
400 + break;
401 }
400 - return ofs + len;
402 + ofs += len;
403 + /* Yuck, 2822 header "folding" */
404 + peek = fgetc(in); ungetc(peek, in);
405 + if (peek != ' ' && peek != '\t')
406 + break;
407 }
408 + /* Count mbox From headers as headers */
409 + if (!ofs && !memcmp(line, "From ", 5))
410 + ofs = 1;
411 return ofs;
412 }
413