added spam result detection support

This commit is contained in:
SJ 2012-01-26 14:35:51 +01:00
parent 57b0c1d650
commit a7df7986ae
9 changed files with 35 additions and 1 deletions

View File

@ -48,6 +48,22 @@ piler_header_field=X-piler: piler already archived this email
; the direction of the given email
mydomains=
; if piler detects this line in the mail header, then it will assume
; the message is a spam. You should include your own antispam solution's
; specific line.
;
; If you use SpamAssassin you may use
;
; spam_header_line=X-Spam-Status: Yes
;
; OR
;
; spam_header_line=X-Spam-Level: ********
;
; The default value is empty.
spam_header_line=
;
; memcached stuff
;

View File

@ -85,6 +85,7 @@ struct _parse_rule config_parse_rules[] =
{ "piler_header_field", "string", (void*) string_parser, offsetof(struct __config, piler_header_field), "", MAXVAL-1},
{ "queuedir", "string", (void*) string_parser, offsetof(struct __config, queuedir), QUEUE_DIR, MAXVAL-1},
{ "session_timeout", "integer", (void*) int_parser, offsetof(struct __config, session_timeout), "420", sizeof(int)},
{ "spam_header_line", "string", (void*) string_parser, offsetof(struct __config, spam_header_line), "", MAXVAL-1},
{ "sqlite3_pragma", "string", (void*) string_parser, offsetof(struct __config, sqlite3_pragma), "", MAXVAL-1},
{ "update_counters_to_memcached", "integer", (void*) int_parser, offsetof(struct __config, update_counters_to_memcached), "0", sizeof(int)},
{ "username", "string", (void*) string_parser, offsetof(struct __config, username), "piler", MAXVAL-1},

View File

@ -45,6 +45,8 @@ struct __config {
char mydomains[MAXVAL];
char spam_header_line[MAXVAL];
// mysql stuff
char mysqlhost[MAXVAL];

View File

@ -156,6 +156,7 @@ struct session_data {
char attachments[SMALLBUFSIZE];
char internal_sender, internal_recipient, external_recipient;
int direction;
int spam_message;
int fd, hdr_len, tot_len, num_of_rcpt_to, rav;
int need_scan;
float __acquire, __parsed, __av, __store, __compress, __encrypt;

View File

@ -293,7 +293,7 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __c
digest_string(s, &vcode[0]);
snprintf(s, MAXBUFSIZE-1, "INSERT INTO %s (`from`,`fromdomain`,`subject`,`arrived`,`sent`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,%ld,%ld,%d,%d,%d,%d,'%s',?,'%s','%s','%s')", SQL_METADATA_TABLE, sdata->now, sdata->sent, sdata->tot_len, sdata->hdr_len, sdata->direction, state->n_attachments, sdata->ttmpfile, sdata->digest, sdata->bodydigest, vcode);
snprintf(s, MAXBUFSIZE-1, "INSERT INTO %s (`from`,`fromdomain`,`subject`,`spam`,`arrived`,`sent`,`size`,`hlen`,`direction`,`attachments`,`piler_id`,`message_id`,`digest`,`bodydigest`,`vcode`) VALUES(?,?,?,%d,%ld,%ld,%d,%d,%d,%d,'%s',?,'%s','%s','%s')", SQL_METADATA_TABLE, sdata->spam_message, sdata->now, sdata->sent, sdata->tot_len, sdata->hdr_len, sdata->direction, state->n_attachments, sdata->ttmpfile, sdata->digest, sdata->bodydigest, vcode);
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: meta sql: *%s*", sdata->ttmpfile, s);

View File

@ -397,6 +397,8 @@ void init_session_data(struct session_data *sdata){
sdata->rav = AVIR_OK;
sdata->spam_message = 0;
sdata->__acquire = sdata->__parsed = sdata->__av = sdata->__store = sdata->__compress = sdata->__encrypt = 0;

View File

@ -106,6 +106,10 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, stru
sdata->restored_copy = 1;
}
if(state->is_1st_header == 1 && *(cfg->spam_header_line) != '\0' && strncmp(buf, cfg->spam_header_line, strlen(cfg->spam_header_line)) == 0){
sdata->spam_message = 1;
}
//printf("buf: %s", buf);
if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){

View File

@ -97,6 +97,8 @@ int main(int argc, char **argv){
printf("direction: %d\n", sdata.direction);
printf("spam: %d\n", sdata.spam_message);
printf("\n\n");
mysql_close(&(sdata.mysql));

View File

@ -35,6 +35,7 @@ create table if not exists `metadata` (
`from` char(255) not null,
`fromdomain` char(48) not null,
`subject` text(512) default null,
`spam` tinyint(1) default 0,
`arrived` int not null,
`sent` int not null,
`deleted` tinyint(1) default 0,
@ -221,3 +222,8 @@ create table if not exists `audit` (
primary key (`id`)
) ENGINE=InnoDB;
create index `audit_idx` on `audit`(`email`);
create index `audit_idx2` on `audit`(`action`);
create index `audit_idx3` on `audit`(`ipaddr`);
create index `audit_idx4` on `audit`(`ts`);