diff --git a/src/config.h b/src/config.h index 8b74cbde..b120d92a 100644 --- a/src/config.h +++ b/src/config.h @@ -14,7 +14,7 @@ #define VERSION "0.1.25-master-branch" -#define BUILD 865 +#define BUILD 866 #define HOSTID "mailarchiver" diff --git a/src/defs.h b/src/defs.h index fcac850a..74030009 100644 --- a/src/defs.h +++ b/src/defs.h @@ -158,6 +158,9 @@ struct _state { char filename[TINYBUFSIZE]; char type[TINYBUFSIZE]; + char attachment_name_buf[SMALLBUFSIZE]; + int anamepos; + struct node *boundaries[MAXHASH]; struct node *rcpt[MAXHASH]; struct node *rcpt_domain[MAXHASH]; @@ -257,6 +260,7 @@ struct import { int processed_messages; int import_job_id; int remove_after_import; + int keep_eml; time_t started, updated, finished; }; diff --git a/src/parser.c b/src/parser.c index 6881c456..2fd3522f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -200,6 +200,11 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int if(state->is_header == 1) state->is_header = 0; state->is_1st_header = 0; + + if(state->anamepos > 0){ + extractNameFromHeaderLine(state->attachment_name_buf, "name", state->filename); + } + } if(sdata->ms_journal == 1 && strncasecmp(buf, "Received:", strlen("Received:")) == 0){ @@ -333,10 +338,27 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int if(strncasecmp(buf, "From:", strlen("From:")) == 0) state->message_state = MSG_FROM; - else if(strncasecmp(buf, "Content-Type:", strlen("Content-Type:")) == 0) state->message_state = MSG_CONTENT_TYPE; - else if(strncasecmp(buf, "Content-Transfer-Encoding:", strlen("Content-Transfer-Encoding:")) == 0) state->message_state = MSG_CONTENT_TRANSFER_ENCODING; - else if(strncasecmp(buf, "Content-Disposition:", strlen("Content-Disposition:")) == 0) state->message_state = MSG_CONTENT_DISPOSITION; + else if(strncasecmp(buf, "Content-Type:", strlen("Content-Type:")) == 0){ + state->message_state = MSG_CONTENT_TYPE; + if(state->anamepos > 0){ + extractNameFromHeaderLine(state->attachment_name_buf, "name", state->filename); + memset(state->attachment_name_buf, 0, SMALLBUFSIZE); + state->anamepos = 0; + } + + } + else if(strncasecmp(buf, "Content-Transfer-Encoding:", strlen("Content-Transfer-Encoding:")) == 0) state->message_state = MSG_CONTENT_TRANSFER_ENCODING; + else if(strncasecmp(buf, "Content-Disposition:", strlen("Content-Disposition:")) == 0){ + state->message_state = MSG_CONTENT_DISPOSITION; + + if(state->anamepos > 0){ + extractNameFromHeaderLine(state->attachment_name_buf, "name", state->filename); + memset(state->attachment_name_buf, 0, SMALLBUFSIZE); + state->anamepos = 0; + } + + } else if(strncasecmp(buf, "To:", 3) == 0) state->message_state = MSG_TO; else if(strncasecmp(buf, "Cc:", 3) == 0) state->message_state = MSG_CC; else if(strncasecmp(buf, "Bcc:", 4) == 0) state->message_state = MSG_CC; @@ -482,7 +504,18 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int if((state->message_state == MSG_CONTENT_TYPE || state->message_state == MSG_CONTENT_DISPOSITION) && strlen(state->filename) < 5){ - extractNameFromHeaderLine(buf, "name", state->filename); + + p = &buf[0]; + for(; *p; p++){ + if(*p != ' ' && *p != '\t') break; + } + + len = strlen(p); + + if(len + state->anamepos < SMALLBUFSIZE-2){ + memcpy(&(state->attachment_name_buf[state->anamepos]), p, len); + state->anamepos += len; + } } @@ -543,6 +576,9 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int memset(state->filename, 0, TINYBUFSIZE); memset(state->type, 0, TINYBUFSIZE); + memset(state->attachment_name_buf, 0, SMALLBUFSIZE); + state->anamepos = 0; + state->message_state = MSG_UNDEF; return 0; diff --git a/src/parser_utils.c b/src/parser_utils.c index cc9ac1b3..8720bd5f 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -54,6 +54,9 @@ void init_state(struct _state *state){ memset(state->filename, 0, TINYBUFSIZE); memset(state->type, 0, TINYBUFSIZE); + memset(state->attachment_name_buf, 0, SMALLBUFSIZE); + state->anamepos = 0; + state->has_to_dump = 0; state->fd = -1; state->b64fd = -1;