-- Check messages for 'bulkiness' using DCC
+local N = 'dcc'
local symbol_bulk = "DCC_BULK"
-local opts = rspamd_config:get_all_opt('dcc')
+local opts = rspamd_config:get_all_opt(N)
local logger = require "rspamd_logger"
local tcp = require "rspamd_tcp"
local fun = require "fun"
end
-- Parse the response
local _,_,result,disposition,header = tostring(data):find("(.-)\n(.-)\n(.-)\n")
- logger.debugx(task, 'DCC result=%1 disposition=%2 header="%3"',
+ logger.debugm(N, task, 'DCC result=%1 disposition=%2 header="%3"',
result, disposition, header)
if header then
task:get_content()
}
- logger.debugx(task, 'sending to dcc: client=%1 helo="%2" envfrom="%3" envrcpt="%4"',
+ logger.debugm(N, task, 'sending to dcc: client=%1 helo="%2" envfrom="%3" envrcpt="%4"',
client, helo, envfrom, envrcpt)
tcp.request({
callback = check_dcc
})
rspamd_config:set_metric_symbol({
- group = 'dcc',
+ group = N,
score = 2.0,
description = 'Detected as bulk mail by DCC',
one_shot = true,
local rspamd_http
local rspamd_logger = require "rspamd_logger"
+local N = 'metadata_exporter'
local settings = {
format = function(task)
mime_type = 'text/plain',
}
-local opts = rspamd_config:get_all_opt('metadata_exporter')
+local opts = rspamd_config:get_all_opt(N)
if not opts then return end
local redis_params
local channel = opts['channel']
rspamd_logger.errx('No backends configured')
end
if channel then
- redis_params = rspamd_parse_redis_server('metadata_exporter')
+ redis_params = rspamd_parse_redis_server(N)
if not redis_params then
rspamd_logger.errx(rspamd_config, 'No redis servers are specified')
return
end
if settings.select then
if not settings.select(task) then return end
- rspamd_logger.debugx(task, 'Message selected for processing')
+ rspamd_logger.debugm(N, task, 'Message selected for processing')
end
local data = settings.format(task)
if not data then
- rspamd_logger.debugx(task, 'Format returned non-truthy value: %1', data)
+ rspamd_logger.debugm(N, task, 'Format returned non-truthy value: %1', data)
return
end
if channel then
limitations under the License.
]] --
+local N = 'metric_exporter'
local logger = require "rspamd_logger"
local mempool = require "rspamd_mempool"
local util = require "rspamd_util"
}
local function configure_metric_exporter()
- local opts = rspamd_config:get_all_opt('metric_exporter')
+ local opts = rspamd_config:get_all_opt(N)
if not backends[opts['backend']] then
logger.errx(rspamd_config, 'Backend is invalid or unspecified')
return false
pool:set_variable(VAR_NAME, stamp)
end
if not stamp then
- logger.debug('No state found - pushing stats immediately')
+ logger.debugm(N, rspamd_config, 'No state found - pushing stats immediately')
push_metrics()
schedule_regular_push()
return
local time = util.get_time()
local delta = stamp - time + settings['interval']
if delta <= 0 then
- logger.debug('Last push is too old - pushing stats immediately')
+ logger.debugm(N, rspamd_config, 'Last push is too old - pushing stats immediately')
push_metrics(time)
schedule_regular_push()
return
end
- logger.debugx('Scheduling next push in %s seconds', delta)
+ logger.debugm(N, rspamd_config, 'Scheduling next push in %s seconds', delta)
schedule_intermediate_push(delta)
end)
local rspamd_expression = require "rspamd_expression"
local redis_params
local fun = require "fun"
+local N = 'multimap'
local urls = {}
local res,trace = rule['expression']:process_traced(task)
if not res or res == 0 then
- rspamd_logger.debugx(task, 'condition is false for %s', rule['symbol'])
+ rspamd_logger.debugm(N, task, 'condition is false for %s', rule['symbol'])
return
else
- rspamd_logger.debugx(task, 'condition is true for %s: %s', rule['symbol'],
+ rspamd_logger.debugm(N, task, 'condition is true for %s: %s', rule['symbol'],
trace)
end
end
local function process_atom(atom, task)
local f_ret = task:has_symbol(atom)
- rspamd_logger.debugx('check for symbol %s: %s', atom, f_ret)
+ rspamd_logger.debugm(N, rspamd_config, 'check for symbol %s: %s', atom, f_ret)
if f_ret then
return 1
newrule['expression'] = expression
fun.each(function(v)
- rspamd_logger.debugx(rspamd_config, 'add dependency %s -> %s',
+ rspamd_logger.debugm(N, rspamd_config, 'add dependency %s -> %s',
newrule['symbol'], v)
rspamd_config:register_dependency(newrule['symbol'], v)
end, atoms)
end
-- Registration
-local opts = rspamd_config:get_all_opt('multimap')
+local opts = rspamd_config:get_all_opt(N)
if opts and type(opts) == 'table' then
- redis_params = rspamd_parse_redis_server('multimap')
+ redis_params = rspamd_parse_redis_server(N)
for k,m in pairs(opts) do
if type(m) == 'table' and m['type'] then
local rule = add_multimap_rule(k, m)
if rule['score'] then
-- Register metric symbol
local description = 'multimap symbol'
- local group = 'multimap'
+ local group = N
if rule['description'] then
description = rule['description']
end
-- Phishing detection interface for selecting phished urls and inserting corresponding symbol
--
--
+local N = 'phishing'
local symbol = 'PHISHED_URL'
local openphish_symbol = 'PHISHED_OPENPHISH'
local phishtank_symbol = 'PHISHED_PHISHTANK'
local phishtank_data = {}
local rspamd_logger = require "rspamd_logger"
local util = require "rspamd_util"
-local opts = rspamd_config:get_all_opt('phishing')
+local opts = rspamd_config:get_all_opt(N)
if not (opts and type(opts) == 'table') then
rspamd_logger.infox(rspamd_config, 'Module is unconfigured')
return
-- Use distance to penalize the total weight
weight = util.tanh(3 * (1 - dist + 0.1))
end
- rspamd_logger.debugx(task, "distance: %1 -> %2: %3", tld, ptld, dist)
+ rspamd_logger.debugm(N, task, "distance: %1 -> %2: %3", tld, ptld, dist)
local function found_in_map(map)
if #map > 0 then
-- Documentation can be found here:
-- https://rspamd.com/doc/modules/rbl.html
+local N = 'rbl'
local rbls = {}
local local_exclusions = nil
rspamd_logger.errx(task, 'error looking up %s: %s', to_resolve, err)
end
if not results then
- rspamd_logger.debugx(task, 'DNS RESPONSE: label=%1 results=%2 error=%3 rbl=%4', to_resolve, false, err, rule['rbls'][1]['symbol'])
+ rspamd_logger.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 rbl=%4', to_resolve, false, err, rule['rbls'][1]['symbol'])
return
else
- rspamd_logger.debugx(task, 'DNS RESPONSE: label=%1 results=%2 error=%3 rbl=%4', to_resolve, true, err, rule['rbls'][1]['symbol'])
+ rspamd_logger.debugm(N, task, 'DNS RESPONSE: label=%1 results=%2 error=%3 rbl=%4', to_resolve, true, err, rule['rbls'][1]['symbol'])
end
for _,rbl in ipairs(rule.rbls) do
for _,result in pairs(results) do
local ipstr = result:to_string()
local foundrc
- rspamd_logger.debugx(task, '%s DNS result %s', to_resolve, ipstr)
+ rspamd_logger.debugm(N, task, '%s DNS result %s', to_resolve, ipstr)
for s,i in pairs(rbl['returncodes']) do
if type(i) == 'string' then
if string.find(ipstr, '^' .. i .. '$') then
local params = {} -- indexed by rbl name
local function gen_rbl_rule(to_resolve, rbl)
- rspamd_logger.debugx(task, 'DNS REQUEST: label=%1 rbl=%2', to_resolve, rbl['symbol'])
+ rspamd_logger.debugm(N, task, 'DNS REQUEST: label=%1 rbl=%2', to_resolve, rbl['symbol'])
if not params[to_resolve] then
local nrule = {
to_resolve = to_resolve,
-- Registration
if type(rspamd_config.get_api_version) ~= 'nil' then
if rspamd_config:get_api_version() >= 1 then
- rspamd_config:register_module_option('rbl', 'rbls', 'map')
- rspamd_config:register_module_option('rbl', 'default_ipv4', 'string')
- rspamd_config:register_module_option('rbl', 'default_ipv6', 'string')
- rspamd_config:register_module_option('rbl', 'default_received', 'string')
- rspamd_config:register_module_option('rbl', 'default_from', 'string')
- rspamd_config:register_module_option('rbl', 'default_rdns', 'string')
- rspamd_config:register_module_option('rbl', 'default_helo', 'string')
- rspamd_config:register_module_option('rbl', 'default_dkim', 'string')
- rspamd_config:register_module_option('rbl', 'default_dkim_domainonly', 'string')
- rspamd_config:register_module_option('rbl', 'default_unknown', 'string')
- rspamd_config:register_module_option('rbl', 'default_exclude_users', 'string')
- rspamd_config:register_module_option('rbl', 'default_exclude_private_ips', 'string')
- rspamd_config:register_module_option('rbl', 'local_exclude_ip_map', 'string')
- rspamd_config:register_module_option('rbl', 'default_exclude_local', 'string')
- rspamd_config:register_module_option('rbl', 'default_emails', 'string')
- rspamd_config:register_module_option('rbl', 'default_is_whitelist', 'string')
- rspamd_config:register_module_option('rbl', 'default_ignore_whitelists', 'string')
+ rspamd_config:register_module_option(N, 'rbls', 'map')
+ rspamd_config:register_module_option(N, 'default_ipv4', 'string')
+ rspamd_config:register_module_option(N, 'default_ipv6', 'string')
+ rspamd_config:register_module_option(N, 'default_received', 'string')
+ rspamd_config:register_module_option(N, 'default_from', 'string')
+ rspamd_config:register_module_option(N, 'default_rdns', 'string')
+ rspamd_config:register_module_option(N, 'default_helo', 'string')
+ rspamd_config:register_module_option(N, 'default_dkim', 'string')
+ rspamd_config:register_module_option(N, 'default_dkim_domainonly', 'string')
+ rspamd_config:register_module_option(N, 'default_unknown', 'string')
+ rspamd_config:register_module_option(N, 'default_exclude_users', 'string')
+ rspamd_config:register_module_option(N, 'default_exclude_private_ips', 'string')
+ rspamd_config:register_module_option(N, 'local_exclude_ip_map', 'string')
+ rspamd_config:register_module_option(N, 'default_exclude_local', 'string')
+ rspamd_config:register_module_option(N, 'default_emails', 'string')
+ rspamd_config:register_module_option(N, 'default_is_whitelist', 'string')
+ rspamd_config:register_module_option(N, 'default_ignore_whitelists', 'string')
end
end
-- Configuration
-local opts = rspamd_config:get_all_opt('rbl')
+local opts = rspamd_config:get_all_opt(N)
if not (opts and type(opts) == 'table') then
rspamd_logger.infox(rspamd_config, 'Module is unconfigured')
return
end
if(opts['local_exclude_ip_map'] ~= nil) then
- local_exclusions = rspamd_map_add('rbl', 'local_exclude_ip_map', 'radix',
+ local_exclusions = rspamd_map_add(N, 'local_exclude_ip_map', 'radix',
'RBL exclusions map')
end
-- This plugin is intended to read and parse spamassassin rules with regexp
-- rules. SA plugins or statistics are not supported
+local N = 'spamassassin'
local rspamd_logger = require "rspamd_logger"
local rspamd_regexp = require "rspamd_regexp"
local rspamd_expression = require "rspamd_expression"
local function freemail_search(input)
local res = 0
local function trie_callback(number, pos)
- rspamd_logger.debugx('Matched pattern %1 at pos %2', freemail_domains[number], pos)
+ rspamd_logger.debugm(N, rspamd_config, 'Matched pattern %1 at pos %2', freemail_domains[number], pos)
res = res + 1
end
local elts = split(line, '[^:]+')
arg = elts[2]
- rspamd_logger.debugx(rspamd_config, 'trying to parse SA function %1 with args %2',
+ rspamd_logger.debugm(N, rspamd_config, 'trying to parse SA function %1 with args %2',
elts[1], elts[2])
local substitutions = {
{'^exists:',
local function parse_score(words)
if #words == 3 then
-- score rule <x>
- rspamd_logger.debugx(rspamd_config, 'found score for %1: %2', words[2], words[3])
+ rspamd_logger.debugm(N, rspamd_config, 'found score for %1: %2', words[2], words[3])
return tonumber(words[3])
elseif #words == 6 then
-- score rule <x1> <x2> <x3> <x4>
-- we assume here that bayes and network are enabled and select <x4>
- rspamd_logger.debugx(rspamd_config, 'found score for %1: %2', words[2], words[6])
+ rspamd_logger.debugm(N, rspamd_config, 'found score for %1: %2', words[2], words[6])
return tonumber(words[6])
else
rspamd_logger.errx(rspamd_config, 'invalid score for %1', words[2])
local res = atom_cb(task)
if not res then
- rspamd_logger.debugx(task, 'atom: %1, NULL result', atom)
+ rspamd_logger.debugm(N, task, 'atom: %1, NULL result', atom)
elseif res > 0 then
- rspamd_logger.debugx(task, 'atom: %1, result: %2', atom, res)
+ rspamd_logger.debugm(N, task, 'atom: %1, result: %2', atom, res)
end
return res
else
end
end
- rspamd_logger.debugx(task, 'external atom: %1, result: %2', atom, res)
+ rspamd_logger.debugm(N, task, 'external atom: %1, result: %2', atom, res)
return res
else
- rspamd_logger.debugx(task, 'Cannot find atom ' .. atom)
+ rspamd_logger.debugm(N, task, 'Cannot find atom ' .. atom)
end
end
return 0
--rule['re'] = nil
else
local old_max_hits = rule['re']:get_max_hits()
- rspamd_logger.debugx(rspamd_config, 'replace %1 -> %2', r, nexpr)
+ rspamd_logger.debugm(N, rspamd_config, 'replace %1 -> %2', r, nexpr)
rspamd_config:replace_regexp({
old_re = rule['re'],
new_re = nre
for _,a in ipairs(expr_atoms) do
if not atoms[a] then
local rspamd_symbol = replace_symbol(a)
- rspamd_logger.debugx('atom %1 is a direct foreign dependency, ' ..
+ rspamd_logger.debugm(N, rspamd_config, 'atom %1 is a direct foreign dependency, ' ..
'register dependency for %2 on %3',
a, k, rspamd_symbol)
rspamd_config:register_dependency(k, rspamd_symbol)
for _,a in ipairs(expr_atoms) do
if type(external_deps[a]) == 'table' then
for _,dep in ipairs(external_deps[a]) do
- rspamd_logger.debugx('atom %1 holds a foreign dependency, ' ..
+ rspamd_logger.debugm(N, rspamd_config, 'atom %1 holds a foreign dependency, ' ..
'register dependency for %2 on %3',
a, k, dep);
rspamd_config:register_dependency(k, dep)
-- Trie is rspamd module designed to define and operate with suffix trie
+local N = 'trie'
local rspamd_logger = require "rspamd_logger"
local rspamd_trie = require "rspamd_trie"
local fun = require "fun"
local pattern = patterns[idx]
if param['multi'] or not matched[pattern] then
- rspamd_logger.debugx(task, "<%1> matched pattern %2 at pos %3",
+ rspamd_logger.debugm(N, task, "<%1> matched pattern %2 at pos %3",
task:get_message_id(), pattern, pos)
task:insert_result(param['symbol'], 1.0, type)
if not param['multi'] then