combine journal recpient addresses, allowing bcc users to see their messages

This commit is contained in:
SJ 2012-10-05 14:27:03 +02:00
parent d6b0c3def4
commit 79fafcb3fe
8 changed files with 88 additions and 5 deletions

View File

@ -13,7 +13,7 @@
#define VERSION "0.1.21"
#define BUILD 713
#define BUILD 716
#define HOSTID "mailarchiver"

View File

@ -152,6 +152,7 @@ struct _state {
struct list *boundaries;
struct list *rcpt;
struct list *rcpt_domain;
struct list *journal_recipient;
int n_attachments;
struct attachment attachments[MAX_ATTACHMENTS];
@ -159,9 +160,11 @@ struct _state {
char reference[SMALLBUFSIZE];
char b_from[SMALLBUFSIZE], b_from_domain[SMALLBUFSIZE], b_to[MAXBUFSIZE], b_to_domain[SMALLBUFSIZE], b_subject[MAXBUFSIZE], b_body[BIGBUFSIZE];
char b_journal_to[MAXBUFSIZE];
int bodylen;
int tolen;
int journaltolen;
};

View File

@ -56,7 +56,7 @@ int is_string_on_list(struct list *list, char *s){
p = list;
while(p != NULL){
if(strcasecmp(p->s, s) == 0) return 1;
if(strcmp(p->s, s) == 0) return 1;
p = p->r;
}

View File

@ -206,7 +206,59 @@ CLOSE:
}
int store_recipients(struct session_data *sdata, char *to, uint64 id, struct __config *cfg){
uint64 get_metaid_by_messageid(struct session_data *sdata, char *message_id, struct __config *cfg){
unsigned long len=0;
uint64 id=0;
char s[SMALLBUFSIZE];
MYSQL_STMT *stmt;
MYSQL_BIND bind[1];
snprintf(s, sizeof(s)-1, "SELECT id FROM %s WHERE message_id=?", SQL_METADATA_TABLE);
if(prepare_a_mysql_statement(sdata, &stmt, s) == ERR) return id;
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_STRING;
bind[0].buffer = message_id;
bind[0].is_null = 0;
len = strlen(message_id); bind[0].length = &len;
if(mysql_stmt_bind_param(stmt, bind)){
goto CLOSE;
}
if(mysql_stmt_execute(stmt)){
goto CLOSE;
}
memset(bind, 0, sizeof(bind));
bind[0].buffer_type = MYSQL_TYPE_LONGLONG;
bind[0].buffer = (char *)&id;
bind[0].is_null = 0;
bind[0].length = 0;
if(mysql_stmt_bind_result(stmt, bind)){
goto CLOSE;
}
if(mysql_stmt_store_result(stmt)){
goto CLOSE;
}
mysql_stmt_fetch(stmt);
CLOSE:
mysql_stmt_close(stmt);
return id;
}
int store_recipients(struct session_data *sdata, char *to, uint64 id, int log_errors, struct __config *cfg){
int ret=OK, n=0;
char *p, *q, s[SMALLBUFSIZE], puf[SMALLBUFSIZE];
@ -248,7 +300,7 @@ int store_recipients(struct session_data *sdata, char *to, uint64 id, struct __c
}
if(mysql_stmt_execute(stmt)){
if(mysql_stmt_execute(stmt) && log_errors == 1){
syslog(LOG_PRIORITY, "%s: %s.mysql_stmt_execute error: *%s*", sdata->ttmpfile, SQL_RECIPIENT_TABLE, mysql_error(&(sdata->mysql)));
ret = ERR;
}
@ -353,7 +405,7 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __d
else {
id = mysql_stmt_insert_id(stmt);
rc = store_recipients(sdata, state->b_to, id, cfg);
rc = store_recipients(sdata, state->b_to, id, 1, cfg);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: stored recipients, rc=%d", sdata->ttmpfile, rc);
@ -377,11 +429,19 @@ CLOSE:
int process_message(struct session_data *sdata, struct _state *state, struct __data *data, struct __config *cfg){
int i, rc;
uint64 id=0;
/* discard if existing message_id */
if(is_existing_message_id(sdata, state, data, cfg) == 1){
for(i=1; i<=state->n_attachments; i++) unlink(state->attachments[i].internalname);
if(strlen(state->b_journal_to) > 0){
id = get_metaid_by_messageid(sdata, state->message_id, cfg);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: trying to add journal rcpt (%s) to id=%llu for message-id: '%s'", sdata->ttmpfile, state->b_journal_to, id, state->message_id);
store_recipients(sdata, state->b_journal_to, id, 0, cfg);
}
return ERR_EXISTS;
}

View File

@ -452,6 +452,11 @@ int read_from_stdin(struct session_data *sdata){
}
void strtolower(char *s){
for(; *s; s++) *s = tolower(*s);
}
#ifndef _GNU_SOURCE
char *strcasestr(const char *s, const char *find){
char c, sc;

View File

@ -31,6 +31,7 @@ int drop_privileges(struct passwd *pwd);
int is_email_address_on_my_domains(char *email, struct __config *cfg);
void init_session_data(struct session_data *sdata);
int read_from_stdin(struct session_data *sdata);
void strtolower(char *s);
#ifndef _GNU_SOURCE
char *strcasestr(const char *s, const char *find);

View File

@ -112,6 +112,7 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi
free_list(state->boundaries);
free_list(state->rcpt);
free_list(state->rcpt_domain);
free_list(state->journal_recipient);
trimBuffer(state->b_subject);
fixupEncodedHeaderLine(state->b_subject);
@ -608,6 +609,15 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
}
}
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);
if(state->message_state == MSG_RECIPIENT && is_string_on_list(state->journal_recipient, puf) == 0){
append_list(&(state->journal_recipient), puf);
memcpy(&(state->b_journal_to[state->journaltolen]), puf, len);
memcpy(&(state->b_journal_to[state->journaltolen]), puf, len);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: journal rcpt: '%s'", sdata->ttmpfile, puf);
}
if(is_string_on_list(state->rcpt, puf) == 0){
append_list(&(state->rcpt), puf);
@ -634,6 +644,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
}
}
}
else if(state->message_state == MSG_BODY && len >= cfg->min_word_len && state->bodylen < BIGBUFSIZE-len-1){
memcpy(&(state->b_body[state->bodylen]), puf, len);

View File

@ -69,6 +69,7 @@ void init_state(struct _state *state){
state->boundaries = NULL;
state->rcpt = NULL;
state->rcpt_domain = NULL;
state->journal_recipient = NULL;
state->n_attachments = 0;
@ -91,9 +92,11 @@ void init_state(struct _state *state){
memset(state->b_to_domain, 0, SMALLBUFSIZE);
memset(state->b_subject, 0, MAXBUFSIZE);
memset(state->b_body, 0, BIGBUFSIZE);
memset(state->b_journal_to, 0, MAXBUFSIZE);
state->tolen = 0;
state->bodylen = 0;
state->journaltolen = 0;
}