Browse Source

[Minor] Multimap: Improve crappy style

tags/1.9.0
Vsevolod Stakhov 5 years ago
parent
commit
9546d4cd5e
1 changed files with 33 additions and 31 deletions
  1. 33
    31
      src/plugins/lua/multimap.lua

+ 33
- 31
src/plugins/lua/multimap.lua View File

@@ -696,48 +696,50 @@ local function multimap_callback(task, rule)
end
end

if rule['expression'] then
if rule.expression then
local res,trace = rule['expression']:process_traced(task)

if not res or res == 0 then
lua_util.debugm(N, task, 'condition is false for %s', rule['symbol'])
lua_util.debugm(N, task, 'condition is false for %s',
rule.symbol)
return
else
lua_util.debugm(N, task, 'condition is true for %s: %s', rule['symbol'],
trace)
lua_util.debugm(N, task, 'condition is true for %s: %s',
rule.symbol,
trace)
end
end

local rt = rule['type']
local process_rule_funcs = {
dnsbl = function()
ip = function()
local ip = task:get_from_ip()
if ip:is_valid() then
if rt == 'ip' then
match_rule(rule, ip)
else
local to_resolve = ip_to_rbl(ip, rule['map'])
end
end,
dnsbl = function()
local ip = task:get_from_ip()
if ip:is_valid() then
local to_resolve = ip_to_rbl(ip, rule['map'])

local is_ok, results = rspamd_dns.request({
type = "a",
task = task,
name = to_resolve,
})
local is_ok, results = rspamd_dns.request({
type = "a",
task = task,
name = to_resolve,
})

lua_util.debugm(N, rspamd_config,
'resolve() finished: results=%1, is_ok=%2, to_resolve=%3',
results, is_ok, to_resolve)

if not is_ok and
(results ~= 'requested record is not found' and results ~= 'no records with this name') then
rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results)
elseif is_ok then
task:insert_result(rule['symbol'], 1, rule['map'])
if pre_filter then
task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol'], N)
end
lua_util.debugm(N, rspamd_config,
'resolve() finished: results=%1, is_ok=%2, to_resolve=%3',
results, is_ok, to_resolve)

if not is_ok and
(results ~= 'requested record is not found' and results ~= 'no records with this name') then
rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, results)
elseif is_ok then
task:insert_result(rule['symbol'], 1, rule['map'])
if pre_filter then
task:set_pre_result(rule['action'], 'Matched map: ' .. rule['symbol'], N)
end

end
end
end,
@@ -865,10 +867,10 @@ local function multimap_callback(task, rule)
end,
}

process_rule_funcs.ip = process_rule_funcs.dnsbl
local f = process_rule_funcs[rt]
if f then
f()
local rt = rule.type
local process_func = process_rule_funcs[rt]
if process_func then
process_func()
else
rspamd_logger.errx(task, 'Unrecognised rule type: %s', rt)
end

Loading…
Cancel
Save