Skip to content

Commit f88a545

Browse files
MrHackygitster
authored andcommitted
Make mailsplit and mailinfo strip whitespace from the start of the input
Signed-off-by: Simon Sasburg <Simon.Sasburg@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 3e4bb08 commit f88a545

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

builtin-mailinfo.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,7 @@ static void handle_info(void)
915915
static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
916916
const char *msg, const char *patch)
917917
{
918+
int peek;
918919
keep_subject = ks;
919920
metainfo_charset = encoding;
920921
fin = in;
@@ -935,6 +936,11 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
935936
p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
936937
s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
937938

939+
do {
940+
peek = fgetc(in);
941+
} while (isspace(peek));
942+
ungetc(peek, in);
943+
938944
/* process the email header */
939945
while (read_one_header_line(line, sizeof(line), fin))
940946
check_header(line, sizeof(line), p_hdr_data, 1);

builtin-mailsplit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
164164
{
165165
char name[PATH_MAX];
166166
int ret = -1;
167+
int peek;
167168

168169
FILE *f = !strcmp(file, "-") ? stdin : fopen(file, "r");
169170
int file_done = 0;
@@ -173,6 +174,11 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
173174
goto out;
174175
}
175176

177+
do {
178+
peek = fgetc(f);
179+
} while (isspace(peek));
180+
ungetc(peek, f);
181+
176182
if (fgets(buf, sizeof(buf), f) == NULL) {
177183
/* empty stdin is OK */
178184
if (f != stdin) {

t/t5100/sample.mbox

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
2+
3+
14
From nobody Mon Sep 17 00:00:00 2001
25
From: A U Thor <a.u.thor@example.com>
36
Date: Fri, 9 Jun 2006 00:44:16 -0700

0 commit comments

Comments
 (0)