Fix #957 missing extra recipient address

Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
Janos SUTO 2019-01-13 13:40:01 +00:00
parent 990c52b2c0
commit 4c4e1b52b3
6 changed files with 56 additions and 46 deletions

View File

@ -28,11 +28,6 @@ int import_message(struct session_data *sdata, struct data *data, struct config
init_session_data(sdata, cfg);
if(data->import->extra_recipient){
snprintf(sdata->rcptto[0], SMALLBUFSIZE-1, "%s", data->import->extra_recipient);
sdata->num_of_rcpt_to = 1;
}
if(cfg->verbosity > 1) printf("processing: %s\n", data->import->filename);
if(strcmp(data->import->filename, "-") == 0){

View File

@ -55,6 +55,10 @@ struct parser_state parse_message(struct session_data *sdata, int take_into_piec
fclose(f);
if(data->import->extra_recipient){
add_recipient(data->import->extra_recipient, strlen(data->import->extra_recipient), sdata, &state, data, cfg);
}
return state;
}
@ -165,7 +169,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
char *p, *q, puf[SMALLBUFSIZE];
char tmpbuf[MAXBUFSIZE];
int writelen, boundary_line=0, result;
unsigned int len, domainlen;
unsigned int len;
if(cfg->debug == 1) printf("line: %s", buf);
@ -698,43 +702,7 @@ int parse_line(char *buf, struct parser_state *state, struct session_data *sdata
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: journal rcpt: '%s'", sdata->ttmpfile, puf);
}
if(findnode(state->rcpt, puf) == NULL){
/* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */
if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){
continue;
}
addnode(state->rcpt, puf);
memcpy(&(state->b_to[state->tolen]), puf, len);
state->tolen += len;
if(len >= MIN_EMAIL_ADDRESS_LEN && does_it_seem_like_an_email_address(puf) == 1){
if(is_email_address_on_my_domains(puf, data) == 1) sdata->internal_recipient = 1;
else sdata->external_recipient = 1;
if(q){
if(findnode(state->rcpt_domain, q+1) == NULL){
addnode(state->rcpt_domain, q+1);
domainlen = strlen(q+1);
if(state->todomainlen < SMALLBUFSIZE-domainlen-1){
memcpy(&(state->b_to_domain[state->todomainlen]), q+1, domainlen);
state->todomainlen += domainlen;
}
}
}
if(state->tolen < MAXBUFSIZE-len-1){
split_email_address(puf);
memcpy(&(state->b_to[state->tolen]), puf, len);
state->tolen += len;
}
}
}
add_recipient(puf, len, sdata, state, data, cfg);
}
else if(state->message_state == MSG_BODY && len >= (unsigned int)(cfg->min_word_len) && state->bodylen < BIGBUFSIZE-len-1){
// 99% of email addresses are longer than 8 characters

View File

@ -25,6 +25,7 @@ void translateLine(unsigned char *p, struct parser_state *state);
void fix_email_address_for_sphinx(char *s);
void split_email_address(char *s);
int does_it_seem_like_an_email_address(char *email);
void add_recipient(char *email, unsigned int len, struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg);
void reassembleToken(char *p);
void degenerateToken(unsigned char *p);
void fixURL(char *buf, int buflen);

View File

@ -693,6 +693,49 @@ int does_it_seem_like_an_email_address(char *email){
}
void add_recipient(char *email, unsigned int len, struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg){
char *q;
if(findnode(state->rcpt, email) == NULL){
q = strchr(email, '@');
/* skip any address matching ...@cfg->hostid, 2013.10.29, SJ */
if(q && strncmp(q+1, cfg->hostid, cfg->hostid_len) == 0){
return;
}
addnode(state->rcpt, email);
memcpy(&(state->b_to[state->tolen]), email, len);
state->tolen += len;
if(len >= MIN_EMAIL_ADDRESS_LEN && does_it_seem_like_an_email_address(email) == 1){
if(is_email_address_on_my_domains(email, data) == 1) sdata->internal_recipient = 1;
else sdata->external_recipient = 1;
if(q){
if(findnode(state->rcpt_domain, q+1) == NULL){
addnode(state->rcpt_domain, q+1);
unsigned int domainlen = strlen(q+1);
if(state->todomainlen < SMALLBUFSIZE-domainlen-1){
memcpy(&(state->b_to_domain[state->todomainlen]), q+1, domainlen);
state->todomainlen += domainlen;
}
}
}
if(state->tolen < MAXBUFSIZE-len-1){
split_email_address(email);
memcpy(&(state->b_to[state->tolen]), email, len);
state->tolen += len;
}
}
}
}
/*
* reassemble 'V i a g r a' to 'Viagra'
*/

View File

@ -64,7 +64,7 @@ void usage(){
int main(int argc, char **argv){
int i, c, n_mbox=0;
char *configfile=CONFIG_FILE, *mbox[MBOX_ARGS], *directory=NULL;
char *imapserver=NULL, *pop3server=NULL;
char puf[SMALLBUFSIZE], *imapserver=NULL, *pop3server=NULL;
struct session_data sdata;
struct config cfg;
struct data data;
@ -253,7 +253,8 @@ int main(int argc, char **argv){
break;
case 'a' :
data.import->extra_recipient = optarg;
snprintf(puf, sizeof(puf)-1, "%s ", optarg);
data.import->extra_recipient = puf;
break;
case 'D' :

View File

@ -37,6 +37,7 @@ int main(int argc, char **argv){
struct data data;
struct import import;
char *configfile=CONFIG_FILE, *rule, *emlfile=NULL;
char puf[SMALLBUFSIZE];
import.extra_recipient = NULL;
@ -74,7 +75,8 @@ int main(int argc, char **argv){
break;
case 'a':
import.extra_recipient = optarg;
snprintf(puf, sizeof(puf)-1, "%s ", optarg);
import.extra_recipient = puf;
break;
default :