mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-07 23:51:59 +01:00
changed the internal lists to hash tables
This commit is contained in:
parent
4f2d743f9b
commit
b3cea9de7f
2
configure
vendored
2
configure
vendored
@ -4734,7 +4734,7 @@ echo; echo
|
|||||||
|
|
||||||
CFLAGS="$static -O2 -Wall -g"
|
CFLAGS="$static -O2 -Wall -g"
|
||||||
LIBS="$antispam_libs $sunos_libs "
|
LIBS="$antispam_libs $sunos_libs "
|
||||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs"
|
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs"
|
||||||
|
|
||||||
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile"
|
ac_config_files="$ac_config_files Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile"
|
||||||
|
|
||||||
|
@ -472,7 +472,7 @@ echo; echo
|
|||||||
|
|
||||||
CFLAGS="$static -O2 -Wall -g"
|
CFLAGS="$static -O2 -Wall -g"
|
||||||
LIBS="$antispam_libs $sunos_libs "
|
LIBS="$antispam_libs $sunos_libs "
|
||||||
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o list.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs"
|
OBJS="dirs.o base64.o misc.o counters.o cfg.o sig.o decoder.o hash.o parser.o parser_utils.o rules.o session.o message.o attachment.o digest.o store.o archive.o tai.o import.o imap.o pop3.o extract.o mydomains.o retr.o $objs"
|
||||||
|
|
||||||
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile])
|
AC_CONFIG_FILES([Makefile src/Makefile etc/Makefile util/Makefile init.d/Makefile test/Makefile contrib/imap/Makefile])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
#define VERSION "0.1.24-master-branch"
|
#define VERSION "0.1.24-master-branch"
|
||||||
|
|
||||||
#define BUILD 828
|
#define BUILD 832
|
||||||
|
|
||||||
#define HOSTID "mailarchiver"
|
#define HOSTID "mailarchiver"
|
||||||
|
|
||||||
|
23
src/defs.h
23
src/defs.h
@ -38,7 +38,7 @@
|
|||||||
#define MSG_REFERENCES 10
|
#define MSG_REFERENCES 10
|
||||||
#define MSG_RECIPIENT 11
|
#define MSG_RECIPIENT 11
|
||||||
|
|
||||||
#define MAXHASH 8171
|
#define MAXHASH 277
|
||||||
|
|
||||||
#define BASE64_RATIO 1.33333333
|
#define BASE64_RATIO 1.33333333
|
||||||
|
|
||||||
@ -88,9 +88,10 @@ struct ptr_array {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct list {
|
struct node {
|
||||||
char s[SMALLBUFSIZE];
|
void *str;
|
||||||
struct list *r;
|
unsigned int key;
|
||||||
|
struct node *r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -156,10 +157,10 @@ struct _state {
|
|||||||
char filename[TINYBUFSIZE];
|
char filename[TINYBUFSIZE];
|
||||||
char type[TINYBUFSIZE];
|
char type[TINYBUFSIZE];
|
||||||
|
|
||||||
struct list *boundaries;
|
struct node *boundaries[MAXHASH];
|
||||||
struct list *rcpt;
|
struct node *rcpt[MAXHASH];
|
||||||
struct list *rcpt_domain;
|
struct node *rcpt_domain[MAXHASH];
|
||||||
struct list *journal_recipient;
|
struct node *journal_recipient[MAXHASH];
|
||||||
|
|
||||||
int n_attachments;
|
int n_attachments;
|
||||||
struct attachment attachments[MAX_ATTACHMENTS];
|
struct attachment attachments[MAX_ATTACHMENTS];
|
||||||
@ -251,7 +252,7 @@ struct __data {
|
|||||||
int folder;
|
int folder;
|
||||||
char recursive_folder_names;
|
char recursive_folder_names;
|
||||||
char starttls[TINYBUFSIZE];
|
char starttls[TINYBUFSIZE];
|
||||||
struct list *mydomains;
|
struct node *mydomains[MAXHASH];
|
||||||
|
|
||||||
#ifdef NEED_MYSQL
|
#ifdef NEED_MYSQL
|
||||||
MYSQL_STMT *stmt_generic;
|
MYSQL_STMT *stmt_generic;
|
||||||
@ -276,8 +277,8 @@ struct __data {
|
|||||||
int pos;
|
int pos;
|
||||||
|
|
||||||
#ifdef HAVE_TRE
|
#ifdef HAVE_TRE
|
||||||
struct rule *archiving_rules;
|
struct node *archiving_rules[1];
|
||||||
struct rule *retention_rules;
|
struct node *retention_rules[1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_MEMCACHED
|
#ifdef HAVE_MEMCACHED
|
||||||
|
@ -33,8 +33,9 @@ void load_mydomains(struct session_data *sdata, struct __data *data, struct __co
|
|||||||
p_store_results(sdata, data->stmt_generic, data);
|
p_store_results(sdata, data->stmt_generic, data);
|
||||||
|
|
||||||
while(p_fetch_results(data->stmt_generic) == OK){
|
while(p_fetch_results(data->stmt_generic) == OK){
|
||||||
rc = append_list(&(data->mydomains), s);
|
rc = addnode(data->mydomains, s);
|
||||||
if(rc == -1) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
|
||||||
|
if(rc == 0) syslog(LOG_PRIORITY, "failed to append mydomain: '%s'", s);
|
||||||
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
else if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "added mydomain: '%s'", s);
|
||||||
|
|
||||||
memset(s, 0, sizeof(s));
|
memset(s, 0, sizeof(s));
|
||||||
@ -50,7 +51,6 @@ ENDE:
|
|||||||
int is_email_address_on_my_domains(char *email, struct __data *data){
|
int is_email_address_on_my_domains(char *email, struct __data *data){
|
||||||
int rc=0;
|
int rc=0;
|
||||||
char *q, *s;
|
char *q, *s;
|
||||||
struct list *p;
|
|
||||||
|
|
||||||
if(email == NULL) return rc;
|
if(email == NULL) return rc;
|
||||||
|
|
||||||
@ -61,17 +61,7 @@ int is_email_address_on_my_domains(char *email, struct __data *data){
|
|||||||
|
|
||||||
if(s) *s = '\0';
|
if(s) *s = '\0';
|
||||||
|
|
||||||
|
if(findnode(data->mydomains, q+1)) rc = 1;
|
||||||
p = data->mydomains;
|
|
||||||
|
|
||||||
while(p != NULL){
|
|
||||||
if(strcasecmp(p->s, q+1) == 0){
|
|
||||||
rc = 1;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
p = p->r;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(s) *s = ' ';
|
if(s) *s = ' ';
|
||||||
|
|
||||||
|
30
src/parser.c
30
src/parser.c
@ -50,8 +50,8 @@ struct _state parse_message(struct session_data *sdata, int take_into_pieces, st
|
|||||||
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: processing rcpt to address: *%s*", sdata->ttmpfile, puf);
|
if(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: processing rcpt to address: *%s*", sdata->ttmpfile, puf);
|
||||||
|
|
||||||
if(state.tolen < MAXBUFSIZE-len-1){
|
if(state.tolen < MAXBUFSIZE-len-1){
|
||||||
if(is_string_on_list(state.rcpt, puf) == 0){
|
if(findnode(state.rcpt, puf) == NULL){
|
||||||
append_list(&(state.rcpt), puf);
|
addnode(state.rcpt, puf);
|
||||||
memcpy(&(state.b_to[state.tolen]), puf, len);
|
memcpy(&(state.b_to[state.tolen]), puf, len);
|
||||||
state.tolen += len;
|
state.tolen += len;
|
||||||
|
|
||||||
@ -103,10 +103,10 @@ void post_parse(struct session_data *sdata, struct _state *state, struct __confi
|
|||||||
int i, len, rec=0;
|
int i, len, rec=0;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
free_list(state->boundaries);
|
clearhash(state->boundaries);
|
||||||
free_list(state->rcpt);
|
clearhash(state->rcpt);
|
||||||
free_list(state->rcpt_domain);
|
clearhash(state->rcpt_domain);
|
||||||
free_list(state->journal_recipient);
|
clearhash(state->journal_recipient);
|
||||||
|
|
||||||
trimBuffer(state->b_subject);
|
trimBuffer(state->b_subject);
|
||||||
fixupEncodedHeaderLine(state->b_subject);
|
fixupEncodedHeaderLine(state->b_subject);
|
||||||
@ -211,7 +211,7 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(take_into_pieces == 1){
|
if(take_into_pieces == 1){
|
||||||
if(state->message_state == MSG_BODY && state->fd != -1 && is_item_on_string(state->boundaries, buf) == 0){
|
if(state->message_state == MSG_BODY && state->fd != -1 && findnode(state->boundaries, buf) == NULL){
|
||||||
//n = write(state->fd, buf, len); // WRITE
|
//n = write(state->fd, buf, len); // WRITE
|
||||||
if(len + state->abufpos > abuffersize-1){
|
if(len + state->abufpos > abuffersize-1){
|
||||||
write(state->fd, abuffer, state->abufpos);
|
write(state->fd, abuffer, state->abufpos);
|
||||||
@ -473,7 +473,9 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
|
|
||||||
/* boundary check, and reset variables */
|
/* boundary check, and reset variables */
|
||||||
|
|
||||||
boundary_line = is_item_on_string(state->boundaries, buf);
|
if(findnode(state->boundaries, buf)) boundary_line = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(!strstr(buf, "boundary=") && !strstr(buf, "boundary =") && boundary_line == 1){
|
if(!strstr(buf, "boundary=") && !strstr(buf, "boundary =") && boundary_line == 1){
|
||||||
state->is_header = 1;
|
state->is_header = 1;
|
||||||
@ -616,16 +618,16 @@ 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){
|
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);
|
strtolower(puf);
|
||||||
|
|
||||||
if(state->message_state == MSG_RECIPIENT && is_string_on_list(state->journal_recipient, puf) == 0){
|
if(state->message_state == MSG_RECIPIENT && findnode(state->journal_recipient, puf) == NULL){
|
||||||
append_list(&(state->journal_recipient), puf);
|
addnode(state->journal_recipient, puf);
|
||||||
memcpy(&(state->b_journal_to[state->journaltolen]), puf, len);
|
memcpy(&(state->b_journal_to[state->journaltolen]), puf, len);
|
||||||
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(cfg->verbosity >= _LOG_DEBUG) syslog(LOG_PRIORITY, "%s: journal rcpt: '%s'", sdata->ttmpfile, puf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if(is_string_on_list(state->rcpt, puf) == 0){
|
if(findnode(state->rcpt, puf) == NULL){
|
||||||
append_list(&(state->rcpt), puf);
|
addnode(state->rcpt, puf);
|
||||||
memcpy(&(state->b_to[state->tolen]), puf, len);
|
memcpy(&(state->b_to[state->tolen]), puf, len);
|
||||||
state->tolen += len;
|
state->tolen += len;
|
||||||
|
|
||||||
@ -635,8 +637,8 @@ int parse_line(char *buf, struct _state *state, struct session_data *sdata, int
|
|||||||
|
|
||||||
q = strchr(puf, '@');
|
q = strchr(puf, '@');
|
||||||
if(q){
|
if(q){
|
||||||
if(is_string_on_list(state->rcpt_domain, q+1) == 0){
|
if(findnode(state->rcpt_domain, q+1) == NULL){
|
||||||
append_list(&(state->rcpt_domain), q+1);
|
addnode(state->rcpt_domain, q+1);
|
||||||
memcpy(&(state->b_to_domain[strlen(state->b_to_domain)]), q+1, strlen(q+1));
|
memcpy(&(state->b_to_domain[strlen(state->b_to_domain)]), q+1, strlen(q+1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ void init_state(struct _state *state){
|
|||||||
state->writebufpos = 0;
|
state->writebufpos = 0;
|
||||||
state->abufpos = 0;
|
state->abufpos = 0;
|
||||||
|
|
||||||
state->boundaries = NULL;
|
inithash(state->boundaries);
|
||||||
state->rcpt = NULL;
|
inithash(state->rcpt);
|
||||||
state->rcpt_domain = NULL;
|
inithash(state->rcpt_domain);
|
||||||
state->journal_recipient = NULL;
|
inithash(state->journal_recipient);
|
||||||
|
|
||||||
state->n_attachments = 0;
|
state->n_attachments = 0;
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ int extract_boundary(char *p, struct _state *state){
|
|||||||
q = strrchr(p, '\n');
|
q = strrchr(p, '\n');
|
||||||
if(q) *q = '\0';
|
if(q) *q = '\0';
|
||||||
|
|
||||||
append_list(&(state->boundaries), p);
|
addnode(state->boundaries, p);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
28
src/piler.c
28
src/piler.c
@ -228,10 +228,10 @@ void p_clean_exit(){
|
|||||||
|
|
||||||
kill_children(SIGTERM);
|
kill_children(SIGTERM);
|
||||||
|
|
||||||
free_rule(data.archiving_rules);
|
clearrules(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
free_list(data.mydomains);
|
clearhash(data.mydomains);
|
||||||
|
|
||||||
#ifdef HAVE_MULTITENANCY
|
#ifdef HAVE_MULTITENANCY
|
||||||
free_list(data.customers);
|
free_list(data.customers);
|
||||||
@ -307,10 +307,10 @@ void initialise_configuration(){
|
|||||||
setlocale(LC_CTYPE, cfg.locale);
|
setlocale(LC_CTYPE, cfg.locale);
|
||||||
|
|
||||||
|
|
||||||
free_rule(data.archiving_rules);
|
clearrules(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
free_list(data.mydomains);
|
clearhash(data.mydomains);
|
||||||
|
|
||||||
#ifdef HAVE_MULTITENANCY
|
#ifdef HAVE_MULTITENANCY
|
||||||
free_list(data.customers);
|
free_list(data.customers);
|
||||||
@ -318,9 +318,9 @@ void initialise_configuration(){
|
|||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.recursive_folder_names = 0;
|
data.recursive_folder_names = 0;
|
||||||
data.archiving_rules = NULL;
|
inithash(data.mydomains);
|
||||||
data.retention_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.mydomains = NULL;
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
#ifdef HAVE_MULTITENANCY
|
#ifdef HAVE_MULTITENANCY
|
||||||
data.customers = NULL;
|
data.customers = NULL;
|
||||||
@ -339,8 +339,8 @@ void initialise_configuration(){
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||||
load_rules(&sdata, &data, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||||
|
|
||||||
load_mydomains(&sdata, &data, &cfg);
|
load_mydomains(&sdata, &data, &cfg);
|
||||||
|
|
||||||
@ -393,9 +393,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.recursive_folder_names = 0;
|
data.recursive_folder_names = 0;
|
||||||
data.archiving_rules = NULL;
|
inithash(data.mydomains);
|
||||||
data.retention_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.mydomains = NULL;
|
initrules(data.retention_rules);
|
||||||
#ifdef HAVE_MULTITENANCY
|
#ifdef HAVE_MULTITENANCY
|
||||||
data.customers = NULL;
|
data.customers = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
#define _PILER_H
|
#define _PILER_H
|
||||||
|
|
||||||
#include <misc.h>
|
#include <misc.h>
|
||||||
#include <list.h>
|
|
||||||
#include <parser.h>
|
#include <parser.h>
|
||||||
#include <errmsg.h>
|
#include <errmsg.h>
|
||||||
#include <smtpcodes.h>
|
#include <smtpcodes.h>
|
||||||
#include <decoder.h>
|
#include <decoder.h>
|
||||||
#include <list.h>
|
#include <hash.h>
|
||||||
#include <rules.h>
|
#include <rules.h>
|
||||||
#include <defs.h>
|
#include <defs.h>
|
||||||
#include <tai.h>
|
#include <tai.h>
|
||||||
|
@ -397,9 +397,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.recursive_folder_names = 0;
|
data.recursive_folder_names = 0;
|
||||||
data.archiving_rules = NULL;
|
inithash(data.mydomains);
|
||||||
data.retention_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.mydomains = NULL;
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
|
|
||||||
@ -551,8 +551,8 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||||
load_rules(&sdata, &data, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||||
|
|
||||||
load_mydomains(&sdata, &data, &cfg);
|
load_mydomains(&sdata, &data, &cfg);
|
||||||
|
|
||||||
@ -569,10 +569,10 @@ int main(int argc, char **argv){
|
|||||||
if(pop3server && username && password) rc = import_from_pop3_server(pop3server, username, password, port, &sdata, &data, &cfg);
|
if(pop3server && username && password) rc = import_from_pop3_server(pop3server, username, password, port, &sdata, &data, &cfg);
|
||||||
|
|
||||||
|
|
||||||
free_rule(data.archiving_rules);
|
clearrules(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
free_list(data.mydomains);
|
clearhash(data.mydomains);
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
|
@ -216,9 +216,9 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.recursive_folder_names = 0;
|
data.recursive_folder_names = 0;
|
||||||
data.archiving_rules = NULL;
|
inithash(data.mydomains);
|
||||||
data.retention_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.mydomains = NULL;
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
if(folder){
|
if(folder){
|
||||||
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
data.folder = get_folder_id(&sdata, &data, folder, 0);
|
||||||
@ -247,7 +247,7 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
printf("put %llu messages to %s table for reindexing\n", n, SQL_SPHINX_TABLE);
|
printf("put %llu messages to %s table for reindexing\n", n, SQL_SPHINX_TABLE);
|
||||||
|
|
||||||
free_list(data.mydomains);
|
clearhash(data.mydomains);
|
||||||
|
|
||||||
close_database(&sdata);
|
close_database(&sdata);
|
||||||
|
|
||||||
|
176
src/rules.c
176
src/rules.c
@ -10,7 +10,7 @@
|
|||||||
#include "rules.h"
|
#include "rules.h"
|
||||||
|
|
||||||
|
|
||||||
void load_rules(struct session_data *sdata, struct __data *data, struct rule **rules, char *table){
|
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table){
|
||||||
char s[SMALLBUFSIZE];
|
char s[SMALLBUFSIZE];
|
||||||
char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE];
|
char domain[SMALLBUFSIZE], from[SMALLBUFSIZE], to[SMALLBUFSIZE], subject[SMALLBUFSIZE], _size[SMALLBUFSIZE], attachment_type[SMALLBUFSIZE], _attachment_size[SMALLBUFSIZE];
|
||||||
int size=0, attachment_size=0, spam=0, days=0;
|
int size=0, attachment_size=0, spam=0, days=0;
|
||||||
@ -54,7 +54,7 @@ void load_rules(struct session_data *sdata, struct __data *data, struct rule **r
|
|||||||
p_store_results(sdata, data->stmt_generic, data);
|
p_store_results(sdata, data->stmt_generic, data);
|
||||||
|
|
||||||
while(p_fetch_results(data->stmt_generic) == OK){
|
while(p_fetch_results(data->stmt_generic) == OK){
|
||||||
append_rule(rules, domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days);
|
append_rule(xhash, domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days);
|
||||||
|
|
||||||
memset(domain, 0, sizeof(domain));
|
memset(domain, 0, sizeof(domain));
|
||||||
memset(from, 0, sizeof(from));
|
memset(from, 0, sizeof(from));
|
||||||
@ -75,27 +75,40 @@ ENDE:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int append_rule(struct rule **rule, char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days){
|
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days){
|
||||||
struct rule *q, *t, *u=NULL;
|
struct node *q, *Q=NULL, *node;
|
||||||
|
struct rule *rule;
|
||||||
|
int rc=0;
|
||||||
|
|
||||||
q = *rule;
|
if((node = malloc(sizeof(struct node))) == NULL) return rc;
|
||||||
|
|
||||||
while(q){
|
memset(node, 0, sizeof(struct node));
|
||||||
u = q;
|
node->r = NULL;
|
||||||
|
|
||||||
|
rule = create_rule_item(domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days);
|
||||||
|
|
||||||
|
if(rule == NULL){
|
||||||
|
free(node);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
node->str = rule;
|
||||||
|
|
||||||
|
q = xhash[0];
|
||||||
|
|
||||||
|
while(q != NULL){
|
||||||
|
Q = q;
|
||||||
q = q->r;
|
q = q->r;
|
||||||
}
|
}
|
||||||
|
|
||||||
t = create_rule_item(domain, from, to, subject, _size, size, attachment_type, _attachment_size, attachment_size, spam, days);
|
if(Q == NULL) xhash[0] = node;
|
||||||
if(t){
|
else {
|
||||||
if(*rule == NULL)
|
Q->r = node;
|
||||||
*rule = t;
|
|
||||||
else if(u)
|
|
||||||
u->r = t;
|
|
||||||
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
rc = 1;
|
||||||
|
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -163,27 +176,35 @@ struct rule *create_rule_item(char *domain, char *from, char *to, char *subject,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *check_againt_ruleset(struct rule *rule, struct _state *state, int size, int spam){
|
char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam){
|
||||||
size_t nmatch=0;
|
size_t nmatch=0;
|
||||||
struct rule *p;
|
struct rule *p;
|
||||||
|
struct node *q;
|
||||||
|
|
||||||
p = rule;
|
q = xhash[0];
|
||||||
|
|
||||||
while(p != NULL){
|
while(q != NULL){
|
||||||
|
|
||||||
if(
|
if(q->str){
|
||||||
p->compiled == 1 &&
|
p = q->str;
|
||||||
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
|
|
||||||
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
|
if(p){
|
||||||
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
|
if(
|
||||||
check_size_rule(size, p->size, p->_size) == 1 &&
|
p->compiled == 1 &&
|
||||||
check_attachment_rule(state, p) == 1 &&
|
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
|
||||||
check_spam_rule(spam, p->spam) == 1
|
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
|
||||||
){
|
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
|
||||||
return p->rulestr;
|
check_size_rule(size, p->size, p->_size) == 1 &&
|
||||||
|
check_attachment_rule(state, p) == 1 &&
|
||||||
|
check_spam_rule(spam, p->spam) == 1
|
||||||
|
){
|
||||||
|
return p->rulestr;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
p = p->r;
|
q = q->r;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -193,33 +214,40 @@ char *check_againt_ruleset(struct rule *rule, struct _state *state, int size, in
|
|||||||
unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg){
|
unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg){
|
||||||
size_t nmatch=0;
|
size_t nmatch=0;
|
||||||
struct rule *p;
|
struct rule *p;
|
||||||
|
struct node *q;
|
||||||
|
|
||||||
p = data->retention_rules;
|
q = data->retention_rules[0];
|
||||||
|
|
||||||
while(p != NULL){
|
while(q != NULL){
|
||||||
|
|
||||||
if(p->domainlen > 2){
|
if(q->str){
|
||||||
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
p = q->str;
|
||||||
|
|
||||||
|
if(p->domainlen > 2){
|
||||||
|
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
||||||
|
state->retention = p->days;
|
||||||
|
return p->days * 86400;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (
|
||||||
|
p->compiled == 1 &&
|
||||||
|
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
|
||||||
|
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
|
||||||
|
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
|
||||||
|
check_size_rule(size, p->size, p->_size) == 1 &&
|
||||||
|
check_attachment_rule(state, p) == 1 &&
|
||||||
|
check_spam_rule(spam, p->spam) == 1
|
||||||
|
){
|
||||||
state->retention = p->days;
|
state->retention = p->days;
|
||||||
return p->days * 86400;
|
return p->days * 86400;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else if (
|
|
||||||
p->compiled == 1 &&
|
|
||||||
regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0 &&
|
|
||||||
regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0 &&
|
|
||||||
regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0 &&
|
|
||||||
check_size_rule(size, p->size, p->_size) == 1 &&
|
|
||||||
check_attachment_rule(state, p) == 1 &&
|
|
||||||
check_spam_rule(spam, p->spam) == 1
|
|
||||||
){
|
|
||||||
state->retention = p->days;
|
|
||||||
return p->days * 86400;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
p = p->r;
|
q = q->r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
state->retention = cfg->default_retention_days;
|
state->retention = cfg->default_retention_days;
|
||||||
|
|
||||||
return cfg->default_retention_days * 86400;
|
return cfg->default_retention_days * 86400;
|
||||||
@ -264,29 +292,39 @@ int check_attachment_rule(struct _state *state, struct rule *rule){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void free_rule(struct rule *rule){
|
void initrules(struct node *xhash[]){
|
||||||
struct rule *p, *q;
|
xhash[0] = NULL;
|
||||||
|
|
||||||
p = rule;
|
|
||||||
|
|
||||||
while(p != NULL){
|
|
||||||
q = p->r;
|
|
||||||
|
|
||||||
if(p){
|
|
||||||
regfree(&(p->from));
|
|
||||||
regfree(&(p->to));
|
|
||||||
regfree(&(p->attachment_type));
|
|
||||||
|
|
||||||
free(p->rulestr);
|
|
||||||
|
|
||||||
if(p->domain) free(p->domain);
|
|
||||||
|
|
||||||
free(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
p = q;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void clearrules(struct node *xhash[]){
|
||||||
|
struct node *p, *q;
|
||||||
|
struct rule *rule;
|
||||||
|
|
||||||
|
q = xhash[0];
|
||||||
|
|
||||||
|
while(q != NULL){
|
||||||
|
p = q;
|
||||||
|
q = q->r;
|
||||||
|
|
||||||
|
if(p){
|
||||||
|
if(p->str){
|
||||||
|
rule = (struct rule*)p->str;
|
||||||
|
|
||||||
|
regfree(&(rule->from));
|
||||||
|
regfree(&(rule->to));
|
||||||
|
regfree(&(rule->attachment_type));
|
||||||
|
|
||||||
|
free(rule->rulestr);
|
||||||
|
|
||||||
|
if(rule->domain) free(rule->domain);
|
||||||
|
|
||||||
|
free(rule);
|
||||||
|
}
|
||||||
|
free(p);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
xhash[0] = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
10
src/rules.h
10
src/rules.h
@ -7,15 +7,17 @@
|
|||||||
|
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
|
||||||
void load_rules(struct session_data *sdata, struct __data *data, struct rule **rules, char *table);
|
void load_rules(struct session_data *sdata, struct __data *data, struct node *xhash[], char *table);
|
||||||
int append_rule(struct rule **rule, char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days);
|
int append_rule(struct node *xhash[], char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days);
|
||||||
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days);
|
struct rule *create_rule_item(char *domain, char *from, char *to, char *subject, char *_size, int size, char *attachment_type, char *_attachment_size, int attachment_size, int spam, int days);
|
||||||
char *check_againt_ruleset(struct rule *rule, struct _state *state, int size, int spam);
|
char *check_againt_ruleset(struct node *xhash[], struct _state *state, int size, int spam);
|
||||||
unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg);
|
unsigned long query_retain_period(struct __data *data, struct _state *state, int size, int spam, struct __config *cfg);
|
||||||
int check_size_rule(int message_size, int size, char *_size);
|
int check_size_rule(int message_size, int size, char *_size);
|
||||||
int check_spam_rule(int is_spam, int spam);
|
int check_spam_rule(int is_spam, int spam);
|
||||||
int check_attachment_rule(struct _state *state, struct rule *rule);
|
int check_attachment_rule(struct _state *state, struct rule *rule);
|
||||||
void free_rule(struct rule *rule);
|
|
||||||
|
void initrules(struct node *xhash[]);
|
||||||
|
void clearrules(struct node *xhash[]);
|
||||||
|
|
||||||
#endif /* _RULES_H */
|
#endif /* _RULES_H */
|
||||||
|
|
||||||
|
19
src/test.c
19
src/test.c
@ -48,15 +48,18 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.recursive_folder_names = 0;
|
data.recursive_folder_names = 0;
|
||||||
data.archiving_rules = NULL;
|
|
||||||
data.retention_rules = NULL;
|
|
||||||
data.mydomains = NULL;
|
|
||||||
|
|
||||||
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
inithash(data.mydomains);
|
||||||
load_rules(&sdata, &data, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
|
||||||
|
initrules(data.archiving_rules);
|
||||||
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
load_mydomains(&sdata, &data, &cfg);
|
load_mydomains(&sdata, &data, &cfg);
|
||||||
|
|
||||||
|
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||||
|
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||||
|
|
||||||
|
|
||||||
init_session_data(&sdata, &cfg);
|
init_session_data(&sdata, &cfg);
|
||||||
|
|
||||||
sdata.sent = 0;
|
sdata.sent = 0;
|
||||||
@ -96,10 +99,10 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
printf("retention period: %ld\n", sdata.retained);
|
printf("retention period: %ld\n", sdata.retained);
|
||||||
|
|
||||||
free_rule(data.archiving_rules);
|
clearrules(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
free_list(data.mydomains);
|
clearhash(data.mydomains);
|
||||||
|
|
||||||
for(i=1; i<=state.n_attachments; i++){
|
for(i=1; i<=state.n_attachments; i++){
|
||||||
printf("i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s\n", i, state.attachments[i].filename, state.attachments[i].type, state.attachments[i].size, state.attachments[i].internalname, state.attachments[i].digest);
|
printf("i:%d, name=*%s*, type: *%s*, size: %d, int.name: %s, digest: %s\n", i, state.attachments[i].filename, state.attachments[i].type, state.attachments[i].size, state.attachments[i].internalname, state.attachments[i].digest);
|
||||||
|
@ -233,14 +233,16 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
setlocale(LC_CTYPE, cfg.locale);
|
setlocale(LC_CTYPE, cfg.locale);
|
||||||
|
|
||||||
data.archiving_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.retention_rules = NULL;
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
if(emlfile) rc = import_message2(emlfile, &sdata, &data, &cfg);
|
if(emlfile) rc = import_message2(emlfile, &sdata, &data, &cfg);
|
||||||
if(mailbox) rc = import_from_mailbox(mailbox, &sdata, &data, &cfg);
|
if(mailbox) rc = import_from_mailbox(mailbox, &sdata, &data, &cfg);
|
||||||
if(directory) rc = import_from_maildir(directory, &sdata, &data, &cfg);
|
if(directory) rc = import_from_maildir(directory, &sdata, &data, &cfg);
|
||||||
if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, &sdata, &data, &cfg);
|
if(imapserver && username && password) rc = import_from_imap_server(imapserver, username, password, &sdata, &data, &cfg);
|
||||||
|
|
||||||
|
clearrules(data.archiving_rules);
|
||||||
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
12
test/ptest.c
12
test/ptest.c
@ -306,8 +306,8 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
|
|
||||||
data.folder = 0;
|
data.folder = 0;
|
||||||
data.archiving_rules = NULL;
|
initrules(data.archiving_rules);
|
||||||
data.retention_rules = NULL;
|
initrules(data.retention_rules);
|
||||||
|
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
@ -422,8 +422,8 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
(void) openlog("pilerimport", LOG_PID, LOG_MAIL);
|
(void) openlog("pilerimport", LOG_PID, LOG_MAIL);
|
||||||
|
|
||||||
load_rules(&sdata, &data, &(data.archiving_rules), SQL_ARCHIVING_RULE_TABLE);
|
load_rules(&sdata, &data, data.archiving_rules, SQL_ARCHIVING_RULE_TABLE);
|
||||||
load_rules(&sdata, &data, &(data.retention_rules), SQL_RETENTION_RULE_TABLE);
|
load_rules(&sdata, &data, data.retention_rules, SQL_RETENTION_RULE_TABLE);
|
||||||
|
|
||||||
load_mydomains(&sdata, &data, &cfg);
|
load_mydomains(&sdata, &data, &cfg);
|
||||||
|
|
||||||
@ -440,8 +440,8 @@ int main(int argc, char **argv){
|
|||||||
|
|
||||||
if(quiet == 0) printf("\n");
|
if(quiet == 0) printf("\n");
|
||||||
|
|
||||||
free_rule(data.archiving_rules);
|
clearrules(data.archiving_rules);
|
||||||
free_rule(data.retention_rules);
|
clearrules(data.retention_rules);
|
||||||
|
|
||||||
mysql_close(&(sdata.mysql));
|
mysql_close(&(sdata.mysql));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user