diff --git a/src/parser.c b/src/parser.c index 703fe3bf..178ee56f 100644 --- a/src/parser.c +++ b/src/parser.c @@ -705,10 +705,12 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata if(state->message_state == MSG_FROM && state->is_1st_header == 1 && strlen(state->b_from) < SMALLBUFSIZE-len-1){ strtolower(puf); + q = strchr(puf, '@'); + if(q) fix_plus_sign_in_email_address(puf, &q, &len); + memcpy(&(state->b_from[strlen(state->b_from)]), puf, len); if(does_it_seem_like_an_email_address(puf) == 1 && state->b_from_domain[0] == '\0' && len > 5){ - q = strchr(puf, '@'); if(q && strlen(q) > 5){ memcpy(&(state->b_from_domain), q+1, strlen(q+1)-1); if(strstr(sdata->mailfrom, "<>")){ @@ -728,6 +730,10 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata else if((state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT) && state->is_1st_header == 1 && state->tolen < MAXBUFSIZE-len-1){ strtolower(puf); + /* fix aaa+bbb@ccc.fu address to aaa@ccc.fu, 2017.02.04, SJ */ + q = strchr(puf, '@'); + if(q) fix_plus_sign_in_email_address(puf, &q, &len); + if(state->message_state == MSG_RECIPIENT && findnode(state->journal_recipient, puf) == NULL){ addnode(state->journal_recipient, puf); memcpy(&(state->b_journal_to[state->journaltolen]), puf, len); @@ -738,7 +744,6 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata if(findnode(state->rcpt, puf) == NULL){ /* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */ - q = strchr(puf, '@'); if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){ continue; } diff --git a/src/parser.h b/src/parser.h index fd361ee8..c6a9bbed 100644 --- a/src/parser.h +++ b/src/parser.h @@ -34,5 +34,6 @@ char *determine_attachment_type(char *filename, char *type); char *get_attachment_extractor_by_filename(char *filename); void parse_reference(struct parser_state *state, char *s); int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen); +void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len); #endif /* _PARSER_H */ diff --git a/src/parser_utils.c b/src/parser_utils.c index acc8c62a..f06cb64a 100644 --- a/src/parser_utils.c +++ b/src/parser_utils.c @@ -604,7 +604,7 @@ void translateLine(unsigned char *p, struct parser_state *state){ if(*p == '\'' && prev == '"') { *p = ' '; } if(*p == '\'' && *(p+1) == '"'){ *p = ' '; } - if(*p == '_' || *p == '\'' || *p == '&'){ continue; } + if(*p == '_' || *p == '\'' || *p == '&' || *p == '+'){ continue; } prev = *p; } @@ -958,3 +958,16 @@ int base64_decode_attachment_buffer(char *p, unsigned char *b, int blen){ } +void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len){ + int n; + char *r; + + r = strchr(puf, '+'); + if(r){ + n = strlen(*at_sign); + memmove(r, *at_sign, n); + *(r+n) = '\0'; + *len = strlen(puf); + *at_sign = r; + } +}