mirror of
https://bitbucket.org/jsuto/piler.git
synced 2025-06-13 11:37:02 +02:00
@ -20,7 +20,7 @@
|
||||
|
||||
int store_index_data(struct session_data *sdata, struct parser_state *state, struct data *data, uint64 id, struct config *cfg){
|
||||
int rc=ERR;
|
||||
char *subj;
|
||||
char *subj, *sender=state->b_from, *sender_domain=state->b_from_domain;
|
||||
struct sql sql;
|
||||
|
||||
if(data->folder == 0){
|
||||
@ -34,18 +34,24 @@ int store_index_data(struct session_data *sdata, struct parser_state *state, str
|
||||
if(prepare_sql_statement(sdata, &sql, SQL_PREPARED_STMT_INSERT_INTO_SPHINX_TABLE) == ERR) return rc;
|
||||
|
||||
|
||||
fix_email_address_for_sphinx(state->b_from);
|
||||
fix_email_address_for_sphinx(state->b_sender);
|
||||
fix_email_address_for_sphinx(state->b_to);
|
||||
fix_email_address_for_sphinx(state->b_from_domain);
|
||||
fix_email_address_for_sphinx(state->b_sender_domain);
|
||||
fix_email_address_for_sphinx(state->b_to_domain);
|
||||
|
||||
if(state->b_sender_domain){
|
||||
sender = state->b_sender;
|
||||
sender_domain = state->b_sender_domain;
|
||||
}
|
||||
|
||||
p_bind_init(&sql);
|
||||
|
||||
sql.sql[sql.pos] = (char *)&id; sql.type[sql.pos] = TYPE_LONGLONG; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_sender; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = sender; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_to; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_sender_domain; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = sender_domain; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_to_domain; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = subj; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_body; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
@ -180,15 +186,25 @@ int update_metadata_reference(struct session_data *sdata, struct parser_state *s
|
||||
|
||||
|
||||
int store_meta_data(struct session_data *sdata, struct parser_state *state, struct data *data, struct config *cfg){
|
||||
int rc=ERR, result;
|
||||
char *subj, *p, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
|
||||
int rc=ERR;
|
||||
char *subj, *sender, *sender_domain, s[MAXBUFSIZE], s2[SMALLBUFSIZE], vcode[2*DIGEST_LENGTH+1], ref[2*DIGEST_LENGTH+1];
|
||||
uint64 id=0;
|
||||
struct sql sql;
|
||||
|
||||
subj = state->b_subject;
|
||||
if(*subj == ' ') subj++;
|
||||
|
||||
snprintf(s, sizeof(s)-1, "%llu+%s%s%s%ld%ld%ld%d%d%d%d%s%s%s", id, subj, state->b_sender, state->message_id, sdata->now, sdata->sent, sdata->retained, sdata->tot_len, sdata->hdr_len, sdata->direction, state->n_attachments, sdata->ttmpfile, sdata->digest, sdata->bodydigest);
|
||||
if(state->b_sender_domain){
|
||||
sender = state->b_sender;
|
||||
sender_domain = state->b_sender_domain;
|
||||
get_first_email_address_from_string(state->b_sender, s2, sizeof(s2));
|
||||
} else {
|
||||
sender = state->b_from;
|
||||
sender_domain = state->b_from_domain;
|
||||
get_first_email_address_from_string(state->b_from, s2, sizeof(s2));
|
||||
}
|
||||
|
||||
snprintf(s, sizeof(s)-1, "%llu+%s%s%s%ld%ld%ld%d%d%d%d%s%s%s", id, subj, sender, state->message_id, sdata->now, sdata->sent, sdata->retained, sdata->tot_len, sdata->hdr_len, sdata->direction, state->n_attachments, sdata->ttmpfile, sdata->digest, sdata->bodydigest);
|
||||
|
||||
digest_string(s, &vcode[0]);
|
||||
|
||||
@ -201,19 +217,6 @@ int store_meta_data(struct session_data *sdata, struct parser_state *state, stru
|
||||
|
||||
if(prepare_sql_statement(sdata, &sql, SQL_PREPARED_STMT_INSERT_INTO_META_TABLE) == ERR) return ERR;
|
||||
|
||||
memset(s2, 0, sizeof(s2));
|
||||
|
||||
p = state->b_sender;
|
||||
do {
|
||||
memset(s2, 0, sizeof(s2));
|
||||
p = split(p, ' ', s2, sizeof(s2)-1, &result);
|
||||
|
||||
if(s2[0] == '\0') continue;
|
||||
|
||||
if(does_it_seem_like_an_email_address(s2) == 1){ break; }
|
||||
} while(p);
|
||||
|
||||
|
||||
if(strlen(state->b_to) < 5){
|
||||
snprintf(state->b_to, SMALLBUFSIZE-1, "undisclosed-recipients@no.domain");
|
||||
}
|
||||
@ -222,7 +225,7 @@ int store_meta_data(struct session_data *sdata, struct parser_state *state, stru
|
||||
p_bind_init(&sql);
|
||||
|
||||
sql.sql[sql.pos] = &s2[0]; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = state->b_sender_domain; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = sender_domain; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = subj; sql.type[sql.pos] = TYPE_STRING; sql.pos++;
|
||||
sql.sql[sql.pos] = (char *)&sdata->spam_message; sql.type[sql.pos] = TYPE_LONG; sql.pos++;
|
||||
sql.sql[sql.pos] = (char *)&sdata->now; sql.type[sql.pos] = TYPE_LONG; sql.pos++;
|
||||
|
14
src/parser.c
14
src/parser.c
@ -80,22 +80,18 @@ void post_parse(struct session_data *sdata, struct data *data, struct parser_sta
|
||||
clearhash(state->rcpt_domain);
|
||||
clearhash(state->journal_recipient);
|
||||
|
||||
// Fix From: line if it's too long
|
||||
// Fix From: and Sender: lines if they are too long
|
||||
if(strlen(state->b_from) > 255) state->b_from[255] = '\0';
|
||||
if(strlen(state->b_from_domain) > 255) state->b_from_domain[255] = '\0';
|
||||
|
||||
if(strlen(state->b_sender) > 255) state->b_sender[255] = '\0';
|
||||
if(strlen(state->b_sender_domain) > 255) state->b_sender_domain[255] = '\0';
|
||||
|
||||
// If Sender: header doesn't exist, then copy the From: header value to it
|
||||
// Otherwise append the From: address to the recipients list
|
||||
// TODO: If both Sender: and From: headers exist, and they are different, then
|
||||
// append the From: address to recipients list to give him access to this email
|
||||
// as well
|
||||
|
||||
|
||||
if(state->b_sender[0] == '\0'){
|
||||
strcpy(state->b_sender, state->b_from);
|
||||
strcpy(state->b_sender_domain, state->b_from_domain);
|
||||
} else {
|
||||
add_recipient(state->b_from, strlen(state->b_from), sdata, state, data, cfg);
|
||||
}
|
||||
|
||||
// Truncate the message_id if it's >255 characters
|
||||
if(strlen(state->message_id) > 255) state->message_id[255] = '\0';
|
||||
|
@ -38,5 +38,6 @@ void fix_plus_sign_in_email_address(char *puf, char **at_sign, unsigned int *len
|
||||
void tokenize(char *buf, struct parser_state *state, struct session_data *sdata, struct data *data, struct config *cfg);
|
||||
void flush_attachment_buffer(struct parser_state *state, char *abuffer, unsigned int abuffersize);
|
||||
void fill_attachment_name_buf(struct parser_state *state, char *buf);
|
||||
int get_first_email_address_from_string(char *str, char *buf, int buflen);
|
||||
|
||||
#endif /* _PARSER_H */
|
||||
|
@ -624,9 +624,9 @@ void translateLine(unsigned char *p, struct parser_state *state){
|
||||
|
||||
for(; *p; p++){
|
||||
|
||||
if( (state->message_state == MSG_RECEIVED || state->message_state == MSG_FROM || state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT) && *p == '@'){ continue; }
|
||||
if( (state->message_state == MSG_RECEIVED || state->message_state == MSG_FROM || state->message_state == MSG_SENDER || state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT) && *p == '@'){ continue; }
|
||||
|
||||
if(state->message_state == MSG_FROM || state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT){
|
||||
if(state->message_state == MSG_FROM || state->message_state == MSG_SENDER || state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT){
|
||||
|
||||
/* To fix some unusual addresses, eg.
|
||||
* "'user@domain'" -> user@domain
|
||||
@ -1077,3 +1077,20 @@ void fill_attachment_name_buf(struct parser_state *state, char *buf){
|
||||
state->anamepos++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int get_first_email_address_from_string(char *str, char *buf, int buflen){
|
||||
int result;
|
||||
|
||||
char *p = str;
|
||||
do {
|
||||
memset(buf, 0, buflen);
|
||||
p = split(p, ' ', buf, buflen-1, &result);
|
||||
|
||||
if(*buf == '\0') continue;
|
||||
|
||||
if(does_it_seem_like_an_email_address(buf) == 1){ return 1; }
|
||||
} while(p);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -82,9 +82,16 @@ void tokenize(char *buf, struct parser_state *state, struct session_data *sdata,
|
||||
if(q) fix_plus_sign_in_email_address(puf, &q, &len);
|
||||
|
||||
memcpy(&(state->b_sender[strlen(state->b_sender)]), puf, len);
|
||||
if(strlen(state->b_sender) < SMALLBUFSIZE-len-1){
|
||||
split_email_address(puf);
|
||||
memcpy(&(state->b_sender[strlen(state->b_sender)]), puf, len);
|
||||
|
||||
if(len >= MIN_EMAIL_ADDRESS_LEN && does_it_seem_like_an_email_address(puf) == 1 && state->b_sender_domain[0] == '\0'){
|
||||
if(q && strlen(q) > 5){
|
||||
memcpy(&(state->b_sender_domain), q+1, strlen(q+1)-1);
|
||||
}
|
||||
|
||||
if(strlen(state->b_sender) < SMALLBUFSIZE-len-1){
|
||||
split_email_address(puf);
|
||||
memcpy(&(state->b_sender[strlen(state->b_sender)]), puf, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if((state->message_state == MSG_TO || state->message_state == MSG_CC || state->message_state == MSG_RECIPIENT || state->message_state == MSG_ENVELOPE_TO) && state->is_1st_header == 1 && state->tolen < MAXBUFSIZE-len-1){
|
||||
|
Reference in New Issue
Block a user