diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-27 16:04:29 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2024-03-27 16:04:29 +0000 |
commit | 3737999bbc0f7c5d1db1060abfa788c95c17e99b (patch) | |
tree | c90cbd5e135b312ec58396b204be06413bfe169f | |
parent | cd0be13b203cc4cacd935301f4b897f0eef7a3a0 (diff) | |
download | rspamd-3737999bbc0f7c5d1db1060abfa788c95c17e99b.tar.gz rspamd-3737999bbc0f7c5d1db1060abfa788c95c17e99b.zip |
[Feature] Cloudmark: Add scores_symbols setting
-rw-r--r-- | lualib/lua_scanners/cloudmark.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/lualib/lua_scanners/cloudmark.lua b/lualib/lua_scanners/cloudmark.lua index 13ebc157d..082596688 100644 --- a/lualib/lua_scanners/cloudmark.lua +++ b/lualib/lua_scanners/cloudmark.lua @@ -111,6 +111,7 @@ local function cloudmark_config(opts) symbol_spam = 'CLOUDMARK_SPAM', add_score_header = false, -- Add X-CMAE-Score header add_headers = false, -- allow addition of the headers from Cloudmark + scores_symbols = nil, -- a table with match { [score_threshold] = symbol, ... } } cloudmark_conf = lua_util.override_defaults(cloudmark_conf, opts) @@ -201,6 +202,28 @@ local function table_to_multipart_body(tbl, boundary) return out end +local function get_specific_symbol(scores_symbols, score) + local selected = nil + local sel_thr = 0 + + for threshold, sym in pairs(scores_symbols) do + if sel_thr < threshold and threshold <= score then + selected = sym + sel_thr = threshold + end + end + + return selected +end + +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM' }, 100) == 'CLOUDMARK_SPAM') +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM' }, 80) == nil) +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM', [80] = 'CLOUDMARK_SPAM2' }, 100) == 'CLOUDMARK_SPAM') +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM', [80] = 'CLOUDMARK_SPAM2' }, 80) == 'CLOUDMARK_SPAM2') +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM', [80] = 'CLOUDMARK_SPAM2' }, 70) == nil) +assert(get_specific_symbol({ [90] = 'CLOUDMARK_SPAM', [80] = 'CLOUDMARK_SPAM2' }, 90) == 'CLOUDMARK_SPAM') +assert(get_specific_symbol({ }, 80) == nil) + local function parse_cloudmark_reply(task, rule, body) local parser = ucl.parser() local ret, err = parser:parse_string(body) @@ -250,6 +273,13 @@ local function parse_cloudmark_reply(task, rule, body) }) end + if type(rule.scores_symbols) == 'table' then + local sym = get_specific_symbol(rule.scores_symbols, score) + if sym then + task:insert_result(sym, 1.0, tostring(score)) + end + end + end local function cloudmark_check(task, content, digest, rule, maybe_part) |