mailinfo: ignore blanks after in-body headers.
[jc: this is based on Eric's patch but also fixes up the parsed subject headers]. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Jun 17, 2006 at 16:58 UTC
ae448e3854d8b6e7e37aa88fa3917f5dd97f3210
1 file changed
+14
-8
mailinfo.c
+14
-8
@@ -243,11 +243,20 @@ static int eatspace(char *line)
243
#define SEEN_BOGUS_UNIX_FROM 010
244
#define SEEN_PREFIX 020
245
246
-/* First lines of body can have From:, Date:, and Subject: */
246
+/* First lines of body can have From:, Date:, and Subject: or empty */
247
static void handle_inbody_header(int *seen, char *line)
248
{
249
if (*seen & SEEN_PREFIX)
250
return;
251
+ if (isspace(*line)) {
252
+ char *cp;
253
+ for (cp = line + 1; *cp; cp++) {
254
+ if (!isspace(*cp))
255
+ break;
256
+ }
257
+ if (!*cp)
258
+ return;
259
+ }
260
if (!memcmp(">From", line, 5) && isspace(line[5])) {
261
if (!(*seen & SEEN_BOGUS_UNIX_FROM)) {
262
*seen |= SEEN_BOGUS_UNIX_FROM;
@@ -316,6 +325,7 @@ static char *cleanup_subject(char *subject)
325
}
326
break;
327
}
328
+ eatspace(subject);
329
return subject;
330
}
331
}
@@ -422,9 +432,7 @@ static int read_one_header_line(char *line, int sz, FILE *in)
432
if (fgets(line + ofs, sz - ofs, in) == NULL)
433
break;
434
len = eatspace(line + ofs);
425
- if (len == 0)
426
- break;
427
- if (!is_rfc2822_header(line)) {
435
+ if ((len == 0) || !is_rfc2822_header(line)) {
436
/* Re-add the newline */
437
line[ofs + len] = '\n';
438
line[ofs + len + 1] = '\0';
@@ -764,10 +772,8 @@ static void handle_body(void)
772
{
773
int seen = 0;
774
767
- if (line[0] || fgets(line, sizeof(line), stdin) != NULL) {
768
- handle_commit_msg(&seen);
769
- handle_patch();
770
- }
775
+ handle_commit_msg(&seen);
776
+ handle_patch();
777
fclose(patchfile);
778
if (!patch_lines) {
779
fprintf(stderr, "No patch found\n");