]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Add method to remove symbol from a scan result
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 22 Sep 2020 11:32:38 +0000 (12:32 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 22 Sep 2020 11:32:38 +0000 (12:32 +0100)
src/libmime/scan_result.c
src/libmime/scan_result.h

index d987cbff2b91d3913bcf4977bb4fc4e8cba37e6e..7b92510ca22a70553430f1bef4536af420a67352 100644 (file)
@@ -354,7 +354,8 @@ insert_metric_result (struct rspamd_task *task,
 
                                                diff = NAN;
                                                break;
-                                       } else if (gr_score) {
+                                       }
+                                       else if (gr_score) {
                                                *gr_score += cur_diff;
 
                                                if (cur_diff < diff) {
@@ -890,6 +891,59 @@ rspamd_task_find_symbol_result (struct rspamd_task *task, const char *sym,
        return res;
 }
 
+struct rspamd_symbol_result* rspamd_task_remove_symbol_result (
+               struct rspamd_task *task,
+               const gchar *symbol,
+               struct rspamd_scan_result *result)
+{
+       struct rspamd_symbol_result *res = NULL;
+       khiter_t k;
+
+       if (result == NULL) {
+               /* Use default result */
+               result = task->result;
+       }
+
+       k = kh_get (rspamd_symbols_hash, result->symbols, symbol);
+
+       if (k != kh_end (result->symbols)) {
+               res = &kh_value (result->symbols, k);
+
+               if (!isnan (res->score)) {
+                       /* Remove score from the result */
+                       result->score -= res->score;
+
+                       /* Also check the group limit */
+                       if (result->sym_groups && res->sym) {
+                               struct rspamd_symbol_group *gr;
+                               gint i;
+
+                               PTR_ARRAY_FOREACH (res->sym->groups, i, gr) {
+                                       gdouble *gr_score;
+
+                                       k = kh_get (rspamd_symbols_group_hash,
+                                                       result->sym_groups, gr);
+
+                                       if (k != kh_end (result->sym_groups)) {
+                                               gr_score = &kh_value (result->sym_groups, k);
+
+                                               if (gr_score) {
+                                                       *gr_score -= res->score;
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+               kh_del (rspamd_symbols_hash, result->symbols, k);
+       }
+       else {
+               return NULL;
+       }
+
+       return res;
+}
+
 void
 rspamd_task_symbol_result_foreach (struct rspamd_task *task,
                                                                   struct rspamd_scan_result *result, GHFunc func,
index 2f20e2c626603a57c3a3b78368c7d884af600e3f..4d55a8e62e21d0b7ff330954bd65cf2eef3a36f0 100644 (file)
@@ -149,7 +149,17 @@ struct rspamd_symbol_result *rspamd_task_insert_result_full (struct rspamd_task
 #define rspamd_task_insert_result(task, symbol, flag, opts) \
     rspamd_task_insert_result_full (task, symbol, flag, opts, RSPAMD_SYMBOL_INSERT_DEFAULT, NULL)
 
-
+/**
+ * Removes a symbol from a specific symbol result
+ * @param task
+ * @param symbol
+ * @param result
+ * @return
+ */
+struct rspamd_symbol_result* rspamd_task_remove_symbol_result (
+               struct rspamd_task *task,
+               const gchar *symbol,
+               struct rspamd_scan_result *result);
 /**
  * Adds new option to symbol
  * @param task