fixed a multiline attachment name issue

This commit is contained in:
SJ 2014-03-14 12:17:50 +01:00
parent 3c6932d17b
commit 325d821a40
4 changed files with 48 additions and 5 deletions

View File

@ -14,7 +14,7 @@
#define VERSION "0.1.25-master-branch"
#define BUILD 865
#define BUILD 866
#define HOSTID "mailarchiver"

View File

@ -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;
};

View File

@ -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;

View File

@ -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;