diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-07-30 17:14:07 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-07-30 17:14:07 +0100 |
commit | cddc50cd4e66a874bdfd07c9d27c234e2cd779ad (patch) | |
tree | 96ff4f0dba76d48f84f7f28f83b11bf15f7d2564 /src/libmime | |
parent | 0b547ff8e801979b2f1ea42b1b686476f10341cf (diff) | |
download | rspamd-cddc50cd4e66a874bdfd07c9d27c234e2cd779ad.tar.gz rspamd-cddc50cd4e66a874bdfd07c9d27c234e2cd779ad.zip |
[Feature] Allow to set negative group score limit via `min_score`
Diffstat (limited to 'src/libmime')
-rw-r--r-- | src/libmime/scan_result.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c index f15290b95..bc7e5ccfd 100644 --- a/src/libmime/scan_result.c +++ b/src/libmime/scan_result.c @@ -201,16 +201,29 @@ rspamd_check_group_score(struct rspamd_task *task, double *group_score, double w) { - if (gr != NULL && group_score && gr->max_score > 0.0 && w > 0.0) { - if (*group_score >= gr->max_score && w > 0) { + double group_limit = NAN; + + if (gr != NULL && group_score) { + if ((*group_score + w) >= 0 && !isnan(gr->max_score) && gr->max_score > 0) { + group_limit = gr->max_score; + } + else if ((*group_score + w) < 0 && !isnan(gr->min_score) && gr->min_score < 0) { + group_limit = -gr->min_score; + } + } + + if (gr != NULL && group_limit && !isnan(group_limit)) { + if (fabs(*group_score) >= group_limit && signbit(*group_score) == signbit(w)) { + /* Cannot add more to the group */ msg_info_task("maximum group score %.2f for group %s has been reached," " ignoring symbol %s with weight %.2f", - gr->max_score, + group_limit, gr->name, symbol, w); return NAN; } - else if (*group_score + w > gr->max_score) { - w = gr->max_score - *group_score; + else if (fabs(*group_score + w) > group_limit) { + /* Reduce weight */ + w = signbit(w) ? -group_limit - *group_score : group_limit - *group_score; } } |