mirror of
https://bitbucket.org/jsuto/piler.git
synced 2024-11-08 08:32:00 +01:00
Refactored rules.c
Signed-off-by: Janos SUTO <sj@acts.hu>
This commit is contained in:
parent
a3226764c6
commit
53249db1eb
151
src/rules.c
151
src/rules.c
@ -194,11 +194,43 @@ struct rule *create_rule_item(struct rule_cond *rule_cond){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int size, int spam){
|
unsigned int count_match(struct rule *p, struct parser_state *state, int size, int spam){
|
||||||
|
unsigned int ismatch=0;
|
||||||
size_t nmatch=0;
|
size_t nmatch=0;
|
||||||
|
|
||||||
|
ismatch += check_spam_rule(spam, p->spam);
|
||||||
|
ismatch += check_size_rule(size, p->size, p->_size);
|
||||||
|
ismatch += check_attachment_rule(state, p);
|
||||||
|
|
||||||
|
if(p->compiled == 1){
|
||||||
|
if(p->emptyfrom == 1){
|
||||||
|
ismatch += RULE_UNDEF;
|
||||||
|
}
|
||||||
|
else if(regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||||
|
|
||||||
|
if(p->emptyto == 1){
|
||||||
|
ismatch += RULE_UNDEF;
|
||||||
|
}
|
||||||
|
else if(regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||||
|
|
||||||
|
if(p->emptysubject == 1){
|
||||||
|
ismatch += RULE_UNDEF;
|
||||||
|
}
|
||||||
|
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||||
|
|
||||||
|
if(p->emptybody == 1){
|
||||||
|
ismatch += RULE_UNDEF;
|
||||||
|
}
|
||||||
|
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ismatch;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int size, int spam){
|
||||||
struct rule *p;
|
struct rule *p;
|
||||||
struct node *q;
|
struct node *q;
|
||||||
int ismatch;
|
|
||||||
|
|
||||||
q = xhash[0];
|
q = xhash[0];
|
||||||
|
|
||||||
@ -207,40 +239,8 @@ char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int
|
|||||||
if(q->str){
|
if(q->str){
|
||||||
p = q->str;
|
p = q->str;
|
||||||
|
|
||||||
if(p){
|
if(p && count_match(p, state, size, spam) > 0){
|
||||||
ismatch = 0;
|
return p->rulestr;
|
||||||
|
|
||||||
ismatch += check_spam_rule(spam, p->spam);
|
|
||||||
ismatch += check_size_rule(size, p->size, p->_size);
|
|
||||||
ismatch += check_attachment_rule(state, p);
|
|
||||||
|
|
||||||
if(p->compiled == 1){
|
|
||||||
if(p->emptyfrom == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptyto == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptysubject == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptybody == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ismatch > 0){
|
|
||||||
return p->rulestr;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,10 +252,8 @@ char *check_againt_ruleset(struct node *xhash[], struct parser_state *state, int
|
|||||||
|
|
||||||
|
|
||||||
time_t query_retain_period(struct data *data, struct parser_state *state, int size, int spam, struct config *cfg){
|
time_t query_retain_period(struct data *data, struct parser_state *state, int size, int spam, struct config *cfg){
|
||||||
size_t nmatch=0;
|
|
||||||
struct rule *p;
|
struct rule *p;
|
||||||
struct node *q;
|
struct node *q;
|
||||||
int ismatch;
|
|
||||||
|
|
||||||
q = data->retention_rules[0];
|
q = data->retention_rules[0];
|
||||||
|
|
||||||
@ -264,47 +262,15 @@ time_t query_retain_period(struct data *data, struct parser_state *state, int si
|
|||||||
if(q->str){
|
if(q->str){
|
||||||
p = q->str;
|
p = q->str;
|
||||||
|
|
||||||
ismatch = 0;
|
|
||||||
|
|
||||||
if(p->domainlen > 2){
|
if(p->domainlen > 2){
|
||||||
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
||||||
state->retention = p->days;
|
state->retention = p->days;
|
||||||
return (time_t)(state->retention) * (time_t)86400;
|
return (time_t)(state->retention) * (time_t)86400;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if(count_match(p, state, size, spam) > 0){
|
||||||
|
state->retention = p->days;
|
||||||
ismatch += check_spam_rule(spam, p->spam);
|
return (time_t)(state->retention) * (time_t)86400;
|
||||||
ismatch += check_size_rule(size, p->size, p->_size);
|
|
||||||
ismatch += check_attachment_rule(state, p);
|
|
||||||
|
|
||||||
if(p->compiled == 1){
|
|
||||||
if(p->emptyfrom == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptyto == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptysubject == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptybody == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ismatch > 0){
|
|
||||||
state->retention = p->days;
|
|
||||||
return (time_t)(state->retention) * (time_t)86400;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -320,10 +286,8 @@ time_t query_retain_period(struct data *data, struct parser_state *state, int si
|
|||||||
|
|
||||||
|
|
||||||
int get_folder_id_by_rule(struct data *data, struct parser_state *state, int size, int spam, struct config *cfg){
|
int get_folder_id_by_rule(struct data *data, struct parser_state *state, int size, int spam, struct config *cfg){
|
||||||
size_t nmatch=0;
|
|
||||||
struct rule *p;
|
struct rule *p;
|
||||||
struct node *q;
|
struct node *q;
|
||||||
int ismatch;
|
|
||||||
|
|
||||||
if(cfg->enable_folders == 0) return 0;
|
if(cfg->enable_folders == 0) return 0;
|
||||||
|
|
||||||
@ -334,45 +298,13 @@ int get_folder_id_by_rule(struct data *data, struct parser_state *state, int siz
|
|||||||
if(q->str){
|
if(q->str){
|
||||||
p = q->str;
|
p = q->str;
|
||||||
|
|
||||||
ismatch = 0;
|
|
||||||
|
|
||||||
if(p->domainlen > 2){
|
if(p->domainlen > 2){
|
||||||
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
if(strcasestr(state->b_to_domain, p->domain) || strcasestr(state->b_from_domain, p->domain)){
|
||||||
return p->folder_id;
|
return p->folder_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if(count_match(p, state, size, spam) > 0){
|
||||||
|
return p->folder_id;
|
||||||
ismatch += check_spam_rule(spam, p->spam);
|
|
||||||
ismatch += check_size_rule(size, p->size, p->_size);
|
|
||||||
ismatch += check_attachment_rule(state, p);
|
|
||||||
|
|
||||||
if(p->compiled == 1){
|
|
||||||
if(p->emptyfrom == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->from), state->b_from, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptyto == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->to), state->b_to, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptysubject == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->subject), state->b_subject, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
if(p->emptybody == 1){
|
|
||||||
ismatch += RULE_UNDEF;
|
|
||||||
}
|
|
||||||
else if(regexec(&(p->body), state->b_body, nmatch, NULL, 0) == 0) ismatch += RULE_MATCH; else ismatch += RULE_NO_MATCH;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ismatch > 0){
|
|
||||||
return p->folder_id;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -476,4 +408,3 @@ void clearrules(struct node *xhash[]){
|
|||||||
|
|
||||||
xhash[0] = NULL;
|
xhash[0] = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user