diff --git a/src/config.h b/src/config.h index 6d78458a..79de044b 100644 --- a/src/config.h +++ b/src/config.h @@ -13,7 +13,7 @@ #define VERSION "0.1.21" -#define BUILD 710 +#define BUILD 711 #define HOSTID "mailarchiver" diff --git a/src/misc.c b/src/misc.c index 24dc62be..53327629 100644 --- a/src/misc.c +++ b/src/misc.c @@ -181,15 +181,23 @@ char *split_str(char *row, char *what, char *s, int size){ * trim trailing CR-LF */ -void trimBuffer(char *s){ +int trimBuffer(char *s){ + int n=0; char *p; p = strrchr(s, '\n'); - if(p) *p = '\0'; + if(p){ + *p = '\0'; + n++; + } p = strrchr(s, '\r'); - if(p) *p = '\0'; + if(p){ + *p = '\0'; + n++; + } + return n; } diff --git a/src/misc.h b/src/misc.h index c0bdbfcb..7c4cdef1 100644 --- a/src/misc.h +++ b/src/misc.h @@ -18,7 +18,7 @@ int countCharacterInBuffer(char *p, char c); void replaceCharacterInBuffer(char *p, char from, char to); char *split(char *row, int ch, char *s, int size); char *split_str(char *row, char *what, char *s, int size); -void trimBuffer(char *s); +int trimBuffer(char *s); int extractEmail(char *rawmail, char *email); void create_id(char *id); int get_random_bytes(unsigned char *buf, int len); diff --git a/src/parser.c b/src/parser.c index 82cd862b..fe3ca2ff 100644 --- a/src/parser.c +++ b/src/parser.c @@ -157,7 +157,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi int parse_line(char *buf, struct _state *state, struct session_data *sdata, int take_into_pieces, char *writebuffer, int writebuffersize, char *abuffer, int abuffersize, struct __config *cfg){ char *p, *q, puf[SMALLBUFSIZE]; unsigned char b64buffer[MAXBUFSIZE]; - int x, n, n64, len, writelen, b64_len, boundary_line=0; + int t, x, n, n64, len, writelen, b64_len, boundary_line=0; if(cfg->debug == 1) printf("line: %s", buf); @@ -312,7 +312,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int } - trimBuffer(buf); + t = trimBuffer(buf); /* skip the first line, if it's a "From date" format */ if(state->line_num == 1 && strncmp(buf, "From ", 5) == 0) return 0; @@ -375,7 +375,12 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int sdata->journal_envelope_length -= len; state->writebufpos = 0; memset(writebuffer, 0, writebuffersize); memcpy(writebuffer+state->writebufpos, buf, strlen(buf)); state->writebufpos += strlen(buf); - memcpy(writebuffer+state->writebufpos, "\n", 1); state->writebufpos++; + if(t == 2){ + memcpy(writebuffer+state->writebufpos, "\r\n", 2); state->writebufpos += 2; + } else { + memcpy(writebuffer+state->writebufpos, "\n", 1); state->writebufpos++; + } + }