aboutsummaryrefslogtreecommitdiffstats
path: root/src/libmime/scan_result.c
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2020-09-22 12:32:38 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2020-09-22 12:32:38 +0100
commitc5e6bbff4a6efe44806d1c22beb9654d1d19776b (patch)
treeb27a73c93e5255bfcd36993b665c5a38df2b26c1 /src/libmime/scan_result.c
parent39fb3e04c4599a0e1071400fb94ecb7036a60643 (diff)
downloadrspamd-c5e6bbff4a6efe44806d1c22beb9654d1d19776b.tar.gz
rspamd-c5e6bbff4a6efe44806d1c22beb9654d1d19776b.zip
[Minor] Add method to remove symbol from a scan result
Diffstat (limited to 'src/libmime/scan_result.c')
-rw-r--r--src/libmime/scan_result.c56
1 files changed, 55 insertions, 1 deletions
diff --git a/src/libmime/scan_result.c b/src/libmime/scan_result.c
index d987cbff2..7b92510ca 100644
--- a/src/libmime/scan_result.c
+++ b/src/libmime/scan_result.c
@@ -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,