|
|
@@ -109,7 +109,9 @@ local function cloudmark_config(opts) |
|
|
|
symbol_fail = 'CLOUDMARK_FAIL', |
|
|
|
symbol = 'CLOUDMARK_CHECK', |
|
|
|
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) |
|
|
@@ -200,6 +202,30 @@ local function table_to_multipart_body(tbl, boundary) |
|
|
|
return out |
|
|
|
end |
|
|
|
|
|
|
|
local function get_specific_symbol(scores_symbols, score) |
|
|
|
local selected |
|
|
|
local sel_thr = -1 |
|
|
|
|
|
|
|
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) |
|
|
|
assert(get_specific_symbol({ [100] = 'CLOUDMARK_SPAM' }, 100) == 'CLOUDMARK_SPAM') |
|
|
|
assert(get_specific_symbol({ [0] = 'CLOUDMARK_SPAM' }, 0) == 'CLOUDMARK_SPAM') |
|
|
|
|
|
|
|
local function parse_cloudmark_reply(task, rule, body) |
|
|
|
local parser = ucl.parser() |
|
|
|
local ret, err = parser:parse_string(body) |
|
|
@@ -238,6 +264,24 @@ local function parse_cloudmark_reply(task, rule, body) |
|
|
|
}) |
|
|
|
end |
|
|
|
|
|
|
|
if rule.add_score_header then |
|
|
|
lua_mime.modify_headers(task, { |
|
|
|
add = { |
|
|
|
['X-CMAE-Score'] = { |
|
|
|
order = 1, |
|
|
|
value = tostring(score) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
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) |