Skip to content

Commit

Permalink
Merge branch 'ss/mailsplit'
Browse files Browse the repository at this point in the history
* ss/mailsplit:
  Make mailsplit and mailinfo strip whitespace from the start of the input
  • Loading branch information
Junio C Hamano committed Nov 4, 2007
2 parents e091653 + f88a545 commit c8a140f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions builtin-mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,7 @@ static void handle_info(void)
static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
const char *msg, const char *patch)
{
int peek;
keep_subject = ks;
metainfo_charset = encoding;
fin = in;
Expand All @@ -935,6 +936,11 @@ static int mailinfo(FILE *in, FILE *out, int ks, const char *encoding,
p_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));
s_hdr_data = xcalloc(MAX_HDR_PARSED, sizeof(char *));

do {
peek = fgetc(in);
} while (isspace(peek));
ungetc(peek, in);

/* process the email header */
while (read_one_header_line(line, sizeof(line), fin))
check_header(line, sizeof(line), p_hdr_data, 1);
Expand Down
6 changes: 6 additions & 0 deletions builtin-mailsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ static int split_mbox(const char *file, const char *dir, int allow_bare,
{
char name[PATH_MAX];
int ret = -1;
int peek;

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

do {
peek = fgetc(f);
} while (isspace(peek));
ungetc(peek, f);

if (fgets(buf, sizeof(buf), f) == NULL) {
/* empty stdin is OK */
if (f != stdin) {
Expand Down
3 changes: 3 additions & 0 deletions t/t5100/sample.mbox
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@



From nobody Mon Sep 17 00:00:00 2001
From: A U Thor <a.u.thor@example.com>
Date: Fri, 9 Jun 2006 00:44:16 -0700
Expand Down

0 comments on commit c8a140f

Please sign in to comment.