Skip to content

Commit b6e8269

Browse files
committed
Merge branch 'jk/mbox-from-line' into maint
Some MUAs mangled a line in a message that begins with "From " to ">From " when writing to a mailbox file and feeding such an input to "git am" used to lose such a line. * jk/mbox-from-line: mailinfo: work around -Wstring-plus-int warning mailinfo: make ">From" in-body header check more robust
2 parents 80b616d + 85de86a commit b6e8269

File tree

6 files changed

+66
-1
lines changed

6 files changed

+66
-1
lines changed

builtin/mailinfo.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,22 @@ static inline int cmp_header(const struct strbuf *line, const char *hdr)
288288
line->buf[len] == ':' && isspace(line->buf[len + 1]);
289289
}
290290

291+
static int is_format_patch_separator(const char *line, int len)
292+
{
293+
static const char SAMPLE[] =
294+
"From e6807f3efca28b30decfecb1732a56c7db1137ee Mon Sep 17 00:00:00 2001\n";
295+
const char *cp;
296+
297+
if (len != strlen(SAMPLE))
298+
return 0;
299+
if (!skip_prefix(line, "From ", &cp))
300+
return 0;
301+
if (strspn(cp, "0123456789abcdef") != 40)
302+
return 0;
303+
cp += 40;
304+
return !memcmp(SAMPLE + (cp - line), cp, strlen(SAMPLE) - (cp - line));
305+
}
306+
291307
static int check_header(const struct strbuf *line,
292308
struct strbuf *hdr_data[], int overwrite)
293309
{
@@ -329,7 +345,7 @@ static int check_header(const struct strbuf *line,
329345

330346
/* for inbody stuff */
331347
if (starts_with(line->buf, ">From") && isspace(line->buf[5])) {
332-
ret = 1; /* Should this return 0? */
348+
ret = is_format_patch_separator(line->buf + 1, line->len - 1);
333349
goto check_header_out;
334350
}
335351
if (starts_with(line->buf, "[PATCH]") && isspace(line->buf[7])) {

t/t5100-mailinfo.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,22 @@ test_expect_success 'mailinfo on from header without name works' '
8989
9090
'
9191

92+
test_expect_success 'mailinfo finds headers after embedded From line' '
93+
mkdir embed-from &&
94+
git mailsplit -oembed-from "$TEST_DIRECTORY"/t5100/embed-from.in &&
95+
test_cmp "$TEST_DIRECTORY"/t5100/embed-from.in embed-from/0001 &&
96+
git mailinfo embed-from/msg embed-from/patch \
97+
<embed-from/0001 >embed-from/out &&
98+
test_cmp "$TEST_DIRECTORY"/t5100/embed-from.expect embed-from/out
99+
'
100+
101+
test_expect_success 'mailinfo on message with quoted >From' '
102+
mkdir quoted-from &&
103+
git mailsplit -oquoted-from "$TEST_DIRECTORY"/t5100/quoted-from.in &&
104+
test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.in quoted-from/0001 &&
105+
git mailinfo quoted-from/msg quoted-from/patch \
106+
<quoted-from/0001 >quoted-from/out &&
107+
test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.expect quoted-from/msg
108+
'
109+
92110
test_done

t/t5100/embed-from.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Author: Commit Author
2+
3+
Subject: patch subject
4+
Date: Sat, 13 Sep 2014 21:13:23 -0400
5+

t/t5100/embed-from.in

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
2+
From: Email Author <[email protected]>
3+
Date: Sun, 25 May 2008 00:38:18 -0700
4+
Subject: [PATCH] email subject
5+
6+
>From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
7+
From: Commit Author <[email protected]>
8+
Date: Sat, 13 Sep 2014 21:13:23 -0400
9+
Subject: patch subject
10+
11+
patch body
12+
---
13+
patch

t/t5100/quoted-from.expect

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
>From the depths of history, we are stuck with the
2+
flaky mbox format.
3+

t/t5100/quoted-from.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001
2+
From: Author Name <[email protected]>
3+
Date: Sun, 25 May 2008 00:38:18 -0700
4+
Subject: [PATCH] testing quoted >From
5+
6+
>From the depths of history, we are stuck with the
7+
flaky mbox format.
8+
9+
---
10+
patch

0 commit comments

Comments
 (0)