aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@rspamd.com>2024-07-10 18:53:30 +0600
committerGitHub <noreply@github.com>2024-07-10 18:53:30 +0600
commite62dd9dea2fb32981154a2b1106505d3335659de (patch)
tree9bbe84630a972d89319713ddea6c0ecf55e20128 /src
parent7f19699410f7d85ee9468b7ab6afab2fd1a4cedd (diff)
parent574cd4f7a3a8dbaaf3f05e9a93ea07effcbea69a (diff)
downloadrspamd-e62dd9dea2fb32981154a2b1106505d3335659de.tar.gz
rspamd-e62dd9dea2fb32981154a2b1106505d3335659de.zip
Merge branch 'master' into vstakhov-ratelimits-disable-dyn
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_task.c22
-rw-r--r--src/plugins/lua/gpt.lua29
-rw-r--r--src/plugins/lua/metric_exporter.lua2
3 files changed, 38 insertions, 15 deletions
diff --git a/src/lua/lua_task.c b/src/lua/lua_task.c
index dc41d4ab7..61aac63f2 100644
--- a/src/lua/lua_task.c
+++ b/src/lua/lua_task.c
@@ -2642,7 +2642,7 @@ struct rspamd_url_query_to_inject_cbd {
static gboolean
inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
- gsize end_offset, gpointer ud)
+ gsize end_offset, gpointer ud)
{
struct rspamd_url_query_to_inject_cbd *cbd =
(struct rspamd_url_query_to_inject_cbd *) ud;
@@ -2661,7 +2661,7 @@ inject_url_query_callback(struct rspamd_url *url, gsize start_offset,
static void
inject_url_query(struct rspamd_task *task, struct rspamd_url *url,
- GPtrArray *part_urls)
+ GPtrArray *part_urls)
{
if (url->querylen > 0) {
struct rspamd_url_query_to_inject_cbd cbd;
@@ -2692,11 +2692,11 @@ lua_task_inject_url(lua_State *L)
if (lua_isuserdata(L, 3)) {
/* We also have a mime part there */
mpart = *((struct rspamd_mime_part **)
- rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
+ rspamd_lua_check_udata_maybe(L, 3, rspamd_mimepart_classname));
}
if (task && task->message && url && url->url) {
if (rspamd_url_set_add_or_increase(MESSAGE_FIELD(task, urls), url->url, false)) {
- if(mpart && mpart->urls) {
+ if (mpart && mpart->urls) {
inject_url_query(task, url->url, mpart->urls);
}
}
@@ -4682,7 +4682,7 @@ lua_push_symbol_result(lua_State *L,
struct rspamd_symbol_option *opt;
struct rspamd_symbols_group *sym_group;
unsigned int i;
- int j = 1, table_fields_cnt = 4;
+ int j = 1, table_fields_cnt = 5;
if (!metric_res) {
metric_res = task->result;
@@ -4710,10 +4710,22 @@ lua_push_symbol_result(lua_State *L,
lua_pushstring(L, symbol);
lua_settable(L, -3);
}
+
lua_pushstring(L, "score");
lua_pushnumber(L, s->score);
lua_settable(L, -3);
+ /* Dynamic weight of the symbol */
+ if (s->sym->score != 0) {
+ lua_pushstring(L, "weight");
+ lua_pushnumber(L, s->score / s->sym->score);
+ }
+ else {
+ lua_pushstring(L, "weight");
+ lua_pushnumber(L, 0.0);
+ }
+ lua_settable(L, -3);
+
if (s->sym && s->sym->gr) {
lua_pushstring(L, "group");
lua_pushstring(L, s->sym->gr->name);
diff --git a/src/plugins/lua/gpt.lua b/src/plugins/lua/gpt.lua
index ddd2f0186..6adbce3bf 100644
--- a/src/plugins/lua/gpt.lua
+++ b/src/plugins/lua/gpt.lua
@@ -59,13 +59,13 @@ local fun = require "fun"
-- Exclude checks if one of those is found
local default_symbols_to_except = {
- 'BAYES_SPAM', -- We already know that it is a spam, so we can safely skip it, but no same logic for HAM!
- 'WHITELIST_SPF',
- 'WHITELIST_DKIM',
- 'WHITELIST_DMARC',
- 'FUZZY_DENIED',
- 'REPLY',
- 'BOUNCE',
+ BAYES_SPAM = 0.9, -- We already know that it is a spam, so we can safely skip it, but no same logic for HAM!
+ WHITELIST_SPF = -1,
+ WHITELIST_DKIM = -1,
+ WHITELIST_DMARC = -1,
+ FUZZY_DENIED = -1,
+ REPLY = -1,
+ BOUNCE = -1,
}
local settings = {
@@ -105,9 +105,20 @@ local function default_condition(task)
end
end
-- We also exclude some symbols
- for _, s in ipairs(settings.symbols_to_except) do
+ for s, required_weight in pairs(settings.symbols_to_except) do
if task:has_symbol(s) then
- return false, 'skip as "' .. s .. '" is found'
+ if required_weight > 0 then
+ -- Also check score
+ local sym = task:get_symbol(s)
+ -- Must exist as we checked it before with `has_symbol`
+ if math.abs(sym.weight) >= required_weight then
+ return false, 'skip as "' .. s .. '" is found (weight: ' .. sym.weight .. ')'
+ end
+ lua_util.debugm(N, task, 'symbol %s has weight %s, but required %s', s,
+ sym.weight, required_weight)
+ else
+ return false, 'skip as "' .. s .. '" is found'
+ end
end
end
diff --git a/src/plugins/lua/metric_exporter.lua b/src/plugins/lua/metric_exporter.lua
index 75885516c..3de87c157 100644
--- a/src/plugins/lua/metric_exporter.lua
+++ b/src/plugins/lua/metric_exporter.lua
@@ -117,7 +117,7 @@ local function graphite_push(kwargs)
elseif #split == 2 then
mvalue = kwargs['stats'][split[1]][split[2]]
end
- table.insert(metrics_str, string.format('%s %s %s', mname, mvalue, stamp))
+ table.insert(metrics_str, string.format('%s %s %s', mname, mvalue or 'null', stamp))
end
metrics_str = table.concat(metrics_str, '\n')