]> source.dussan.org Git - rspamd.git/commitdiff
[Project] Adjust some final bits 4912/head
authorVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 8 Apr 2024 18:21:20 +0000 (19:21 +0100)
committerVsevolod Stakhov <vsevolod@rspamd.com>
Mon, 8 Apr 2024 18:21:20 +0000 (19:21 +0100)
src/libmime/scan_result.c
src/libserver/task.c

index 5324d6082d7a792fccec02e5643c66661f19ff3d..09c3208cff6beb946abd502ae4f2307ad5a4bb7d 100644 (file)
@@ -1088,20 +1088,21 @@ void rspamd_task_result_adjust_grow_factor(struct rspamd_task *task,
        double final_grow_factor = grow_factor;
        double max_limit = G_MINDOUBLE;
 
-       for (unsigned int i = 0; i < result->nactions; i++) {
-               struct rspamd_action_config *cur = &result->actions_config[i];
-
-               if (cur->cur_limit > 0 && max_limit < cur->cur_limit) {
-                       max_limit = cur->cur_limit;
-               }
-       }
-
        if (grow_factor > 1.0) {
 
+               for (unsigned int i = 0; i < result->nactions; i++) {
+                       struct rspamd_action_config *cur = &result->actions_config[i];
+
+                       if (cur->cur_limit > 0 && max_limit < cur->cur_limit) {
+                               max_limit = cur->cur_limit;
+                       }
+               }
 
+               /* Adjust factor by selecting all symbols and checking those with positive scores */
                kh_foreach(result->symbols, kk, res, {
                        if (res->score > 0) {
                                double mult = 1.0 - grow_factor;
+                               /* We adjust the factor by the ratio of the score to the max limit */
                                if (max_limit > 0 && !isnan(res->score)) {
                                        mult *= res->score / max_limit;
                                        final_grow_factor *= 1.0 + mult;
@@ -1109,12 +1110,15 @@ void rspamd_task_result_adjust_grow_factor(struct rspamd_task *task,
                        }
                });
 
-               if (final_grow_factor > grow_factor) {
+               /* At this stage we know that we have some grow factor to apply */
+               if (final_grow_factor > 1.0) {
                        msg_info_task("calculated final grow factor for task: %.3f (%.2f the original one)",
                                                  final_grow_factor, grow_factor);
                        kh_foreach(result->symbols, kk, res, {
                                if (res->score > 0) {
+                                       result->score -= res->score;
                                        res->score *= final_grow_factor;
+                                       result->score += res->score;
                                }
                        });
                }
index f81f34e47c88b2b5dfe367f07716974437ed4aad..270bb80ea42177a6834b8b880113ec225ab1c23e 100644 (file)
@@ -758,6 +758,10 @@ rspamd_task_process(struct rspamd_task *task, unsigned int stages)
                all_done = rspamd_symcache_process_symbols(task, task->cfg->cache,
                                                                                                   st);
 
+               if (all_done) {
+                       rspamd_task_result_adjust_grow_factor(task, task->result, task->cfg->grow_factor);
+               }
+
                if (all_done && (task->flags & RSPAMD_TASK_FLAG_LEARN_AUTO) &&
                        !RSPAMD_TASK_IS_EMPTY(task) &&
                        !(task->flags & (RSPAMD_TASK_FLAG_LEARN_SPAM | RSPAMD_TASK_FLAG_LEARN_HAM))) {