summaryrefslogtreecommitdiff
path: root/builtin/mailsplit.c
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-06-05 04:46:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2016-06-06 18:14:43 (GMT)
commitc88098d7f19c6322fbd911bb89e2efd246bf75c4 (patch)
tree99fce8afe1374149c63f69c6185d7cdbdd958952 /builtin/mailsplit.c
parent9f23e040615857e3909db51a5420f338c9831b5a (diff)
downloadgit-c88098d7f19c6322fbd911bb89e2efd246bf75c4.zip
git-c88098d7f19c6322fbd911bb89e2efd246bf75c4.tar.gz
git-c88098d7f19c6322fbd911bb89e2efd246bf75c4.tar.bz2
mailsplit: support unescaping mboxrd messages
This will allow us to parse the output of --pretty=mboxrd and the output of other mboxrd generators. Signed-off-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/mailsplit.c')
-rw-r--r--builtin/mailsplit.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/builtin/mailsplit.c b/builtin/mailsplit.c
index 4859ede..3068168 100644
--- a/builtin/mailsplit.c
+++ b/builtin/mailsplit.c
@@ -45,6 +45,19 @@ static int is_from_line(const char *line, int len)
static struct strbuf buf = STRBUF_INIT;
static int keep_cr;
+static int mboxrd;
+
+static int is_gtfrom(const struct strbuf *buf)
+{
+ size_t min = strlen(">From ");
+ size_t ngt;
+
+ if (buf->len < min)
+ return 0;
+
+ ngt = strspn(buf->buf, ">");
+ return ngt && starts_with(buf->buf + ngt, "From ");
+}
/* Called with the first line (potentially partial)
* already in buf[] -- normally that should begin with
@@ -77,6 +90,9 @@ static int split_one(FILE *mbox, const char *name, int allow_bare)
strbuf_addch(&buf, '\n');
}
+ if (mboxrd && is_gtfrom(&buf))
+ strbuf_remove(&buf, 0, 1);
+
if (fwrite(buf.buf, 1, buf.len, output) != buf.len)
die_errno("cannot write output");
@@ -271,6 +287,8 @@ int cmd_mailsplit(int argc, const char **argv, const char *prefix)
keep_cr = 1;
} else if ( arg[1] == 'o' && arg[2] ) {
dir = arg+2;
+ } else if (!strcmp(arg, "--mboxrd")) {
+ mboxrd = 1;
} else if ( arg[1] == '-' && !arg[2] ) {
argp++; /* -- marks end of options */
break;