mirror of
				https://bitbucket.org/jsuto/piler.git
				synced 2025-10-31 16:32:27 +01:00 
			
		
		
		
	added spam result detection support
This commit is contained in:
		| @@ -48,6 +48,22 @@ piler_header_field=X-piler: piler already archived this email | |||||||
| ; the direction of the given email | ; the direction of the given email | ||||||
| mydomains= | 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 | ; memcached stuff | ||||||
| ; | ; | ||||||
|   | |||||||
| @@ -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}, |    { "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}, |    { "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)}, |    { "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}, |    { "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)}, |    { "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}, |    { "username", "string", (void*) string_parser, offsetof(struct __config, username), "piler", MAXVAL-1}, | ||||||
|   | |||||||
| @@ -45,6 +45,8 @@ struct __config { | |||||||
|  |  | ||||||
|    char mydomains[MAXVAL]; |    char mydomains[MAXVAL]; | ||||||
|  |  | ||||||
|  |    char spam_header_line[MAXVAL]; | ||||||
|  |  | ||||||
|    // mysql stuff |    // mysql stuff | ||||||
|  |  | ||||||
|    char mysqlhost[MAXVAL]; |    char mysqlhost[MAXVAL]; | ||||||
|   | |||||||
| @@ -156,6 +156,7 @@ struct session_data { | |||||||
|    char attachments[SMALLBUFSIZE]; |    char attachments[SMALLBUFSIZE]; | ||||||
|    char internal_sender, internal_recipient, external_recipient; |    char internal_sender, internal_recipient, external_recipient; | ||||||
|    int direction; |    int direction; | ||||||
|  |    int spam_message; | ||||||
|    int fd, hdr_len, tot_len, num_of_rcpt_to, rav; |    int fd, hdr_len, tot_len, num_of_rcpt_to, rav; | ||||||
|    int need_scan; |    int need_scan; | ||||||
|    float __acquire, __parsed, __av, __store, __compress, __encrypt; |    float __acquire, __parsed, __av, __store, __compress, __encrypt; | ||||||
|   | |||||||
| @@ -293,7 +293,7 @@ int store_meta_data(struct session_data *sdata, struct _state *state, struct __c | |||||||
|    digest_string(s, &vcode[0]); |    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); |    if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: meta sql: *%s*", sdata->ttmpfile, s); | ||||||
|  |  | ||||||
|   | |||||||
| @@ -397,6 +397,8 @@ void init_session_data(struct session_data *sdata){ | |||||||
|  |  | ||||||
|    sdata->rav = AVIR_OK; |    sdata->rav = AVIR_OK; | ||||||
|  |  | ||||||
|  |    sdata->spam_message = 0; | ||||||
|  |  | ||||||
|    sdata->__acquire = sdata->__parsed = sdata->__av = sdata->__store = sdata->__compress = sdata->__encrypt = 0; |    sdata->__acquire = sdata->__parsed = sdata->__av = sdata->__store = sdata->__compress = sdata->__encrypt = 0; | ||||||
|  |  | ||||||
|  |  | ||||||
|   | |||||||
| @@ -106,6 +106,10 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, stru | |||||||
|       sdata->restored_copy = 1; |       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); |    //printf("buf: %s", buf); | ||||||
|  |  | ||||||
|    if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){ |    if(state->message_rfc822 == 0 && (buf[0] == '\r' || buf[0] == '\n') ){ | ||||||
|   | |||||||
| @@ -97,6 +97,8 @@ int main(int argc, char **argv){ | |||||||
|  |  | ||||||
|    printf("direction: %d\n", sdata.direction); |    printf("direction: %d\n", sdata.direction); | ||||||
|  |  | ||||||
|  |    printf("spam: %d\n", sdata.spam_message); | ||||||
|  |  | ||||||
|    printf("\n\n"); |    printf("\n\n"); | ||||||
|  |  | ||||||
|    mysql_close(&(sdata.mysql)); |    mysql_close(&(sdata.mysql)); | ||||||
|   | |||||||
| @@ -35,6 +35,7 @@ create table if not exists `metadata` ( | |||||||
|   `from` char(255) not null, |   `from` char(255) not null, | ||||||
|   `fromdomain` char(48) not null, |   `fromdomain` char(48) not null, | ||||||
|   `subject` text(512) default null, |   `subject` text(512) default null, | ||||||
|  |   `spam` tinyint(1) default 0, | ||||||
|   `arrived` int not null, |   `arrived` int not null, | ||||||
|   `sent` int not null, |   `sent` int not null, | ||||||
|   `deleted` tinyint(1) default 0, |   `deleted` tinyint(1) default 0, | ||||||
| @@ -221,3 +222,8 @@ create table if not exists `audit` ( | |||||||
|    primary key (`id`) |    primary key (`id`) | ||||||
| ) ENGINE=InnoDB; | ) 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`); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user