From 319c9e9732d9e3eefc226be506978242c3b01ad2 Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 11 Feb 2014 15:34:12 +0100 Subject: [PATCH] support longer attachment names --- src/config.h | 2 +- src/parser.c | 6 +++--- src/parser.h | 2 +- src/parser_utils.c | 15 +++++++++++---- test/parser.c | 3 +++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/config.h b/src/config.h index 8b219e6e..927f64da 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 860 +#define BUILD 861 #define HOSTID "mailarchiver" diff --git a/src/parser.c b/src/parser.c index 9e88ffaf..43cdffc8 100644 --- a/src/parser.c +++ b/src/parser.c @@ -109,7 +109,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi clearhash(state->journal_recipient); trimBuffer(state->b_subject); - fixupEncodedHeaderLine(state->b_subject); + fixupEncodedHeaderLine(state->b_subject, MAXBUFSIZE); if(sdata->internal_sender == 0) sdata->direction = DIRECTION_INCOMING; @@ -265,7 +265,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int if(take_into_pieces == 1){ state->fd = open(state->attachments[state->n_attachments].internalname, O_CREAT|O_RDWR, S_IRUSR|S_IWUSR); - fixupEncodedHeaderLine(state->attachments[state->n_attachments].filename); + fixupEncodedHeaderLine(state->attachments[state->n_attachments].filename, TINYBUFSIZE); p = get_attachment_extractor_by_filename(state->attachments[state->n_attachments].filename); @@ -428,7 +428,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int } if(state->is_1st_header == 1){ - fixupEncodedHeaderLine(buf); + fixupEncodedHeaderLine(buf, MAXBUFSIZE); } diff --git a/src/parser.h b/src/parser.h index 62a30ae3..436631e0 100644 --- a/src/parser.h +++ b/src/parser.h @@ -17,7 +17,7 @@ void init_state(struct _state *state); unsigned long parse_date_header(char *s, struct __config *cfg); int isHexNumber(char *p); int extract_boundary(char *p, struct _state *state); -void fixupEncodedHeaderLine(char *buf); +void fixupEncodedHeaderLine(char *buf, int buflen); void fixupSoftBreakInQuotedPritableLine(char *buf, struct _state *state); void fixupBase64EncodedLine(char *buf, struct _state *state); void markHTML(char *buf, struct _state *state); diff --git a/src/parser_utils.c b/src/parser_utils.c index 0d43eec0..cc9ac1b3 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -315,7 +315,7 @@ int extract_boundary(char *p, struct _state *state){ } -void fixupEncodedHeaderLine(char *buf){ +void fixupEncodedHeaderLine(char *buf, int buflen){ char *sb, *sq, *p, *q, *r, *s, *e, *start, *end; char v[SMALLBUFSIZE], puf[MAXBUFSIZE], encoding[SMALLBUFSIZE], tmpbuf[2*SMALLBUFSIZE]; iconv_t cd; @@ -323,6 +323,7 @@ void fixupEncodedHeaderLine(char *buf){ char *inbuf, *outbuf; int need_encoding; + if(buflen < 5) return; memset(puf, 0, sizeof(puf)); @@ -412,7 +413,7 @@ void fixupEncodedHeaderLine(char *buf){ } while(q); - snprintf(buf, MAXBUFSIZE-1, "%s", puf); + snprintf(buf, buflen-1, "%s", puf); } @@ -740,7 +741,7 @@ void fixURL(char *url){ int extractNameFromHeaderLine(char *s, char *name, char *resultbuf){ int rc=0; - char buf[TINYBUFSIZE], *p, *q; + char buf[SMALLBUFSIZE], puf[SMALLBUFSIZE], *p, *q; snprintf(buf, sizeof(buf)-1, "%s", s); @@ -760,7 +761,13 @@ int extractNameFromHeaderLine(char *s, char *name, char *resultbuf){ p++; } } - snprintf(resultbuf, TINYBUFSIZE-1, "%s", p); + + snprintf(puf, sizeof(puf)-1, "%s", p); + + fixupEncodedHeaderLine(puf, sizeof(puf)); + + snprintf(resultbuf, TINYBUFSIZE-1, "%s", puf); + rc = 1; } } diff --git a/test/parser.c b/test/parser.c index 6ca6ed37..0a073d14 100644 --- a/test/parser.c +++ b/test/parser.c @@ -164,6 +164,9 @@ int test_dates(){ snprintf(datestr, sizeof(datestr)-2, "Date: 03 Jun 06 05:59:00 +0100"); ts = parse_date_header(datestr, &cfg); printf("%s => %ld\n", datestr, ts); + snprintf(datestr, sizeof(datestr)-2, "Date: 03-Feb-2014 18:00:00"); + ts = parse_date_header(datestr, &cfg); printf("%s => %ld\n", datestr, ts); + return count; }