local rspamd_mempool = require "rspamd_mempool"
local rspamd_trie = require "rspamd_trie"
local util = require "rspamd_util"
-local _ = require "fun"
+require "fun" ()
--local dumper = require 'pl.pretty'.dump
ordinary = false
end
- _.each(function(func)
+ each(function(func)
if func == 'addr' then
cur_param['function'] = function(str)
local addr_parsed = util.parse_addr(str)
rspamd_logger.warnx(rspamd_config, 'Function %1 is not supported in %2',
func, cur_rule['symbol'])
end
- end, _.tail(args))
+ end, tail(args))
local function split_hdr_param(param, headers)
for i,h in ipairs(headers) do
end
local function words_to_re(words, start)
- return table.concat(_.totable(_.drop_n(start, words)), " ");
+ return table.concat(totable(drop_n(start, words)), " ");
end
local function process_tflags(rule, flags)
- _.each(function(flag)
+ each(function(flag)
if flag == 'publish' then
rule['publish'] = true
elseif flag == 'multiple' then
elseif flag == 'nice' then
rule['nice'] = true
end
- end, _.drop_n(1, flags))
+ end, drop_n(1, flags))
if rule['re'] then
if rule['maxhits'] then
if string.match(l, '^ifplugin') then
local ls = split(l)
- if not _.any(function(pl)
+ if not any(function(pl)
if pl == ls[2] then return true end
return false
end, known_plugins) then
end
elseif string.match(l, '^if !plugin%(') then
local pname = string.match(l, '^if !plugin%(([A-Za-z:]+)%)')
- if _.any(function(pl)
+ if any(function(pl)
if pl == pname then return true end
return false
end, known_plugins) then
local slash = string.find(l, '/')
-- Skip comments
- words = _.totable(_.take_while(
+ words = totable(take_while(
function(w) return string.sub(w, 1, 1) ~= '#' end,
- _.filter(function(w)
+ filter(function(w)
return w ~= "" end,
- _.iter(split(l)))))
+ iter(split(l)))))
if words[1] == "header" or words[1] == 'mimeheader' then
-- header SYMBOL Header ~= /regexp/
elseif words[1] == "score" then
scores[words[2]] = parse_score(words)
elseif words[1] == 'freemail_domains' then
- _.each(function(dom)
+ each(function(dom)
table.insert(freemail_domains, '@' .. dom)
- end, _.drop_n(1, words))
+ end, drop_n(1, words))
elseif words[1] == 'blacklist_from' then
sa_lists['from_blacklist'][words[2]] = 1
sa_lists['elts'] = sa_lists['elts'] + 1
elseif words[1] == 'replace_post' then
process_replace(words, replace['post'])
elseif words[1] == 'replace_rules' then
- _.each(function(r) table.insert(replace['rules'], r) end,
- _.drop_n(1, words))
+ each(function(r) table.insert(replace['rules'], r) end,
+ drop_n(1, words))
end
end)()
end
-- Now check all valid rules and add the according rspamd rules
local function calculate_score(sym, rule)
- if _.all(function(c) return c == '_' end, _.take_n(2, _.iter(sym))) then
+ if all(function(c) return c == '_' end, take_n(2, iter(sym))) then
return 0.0
end
local function check_specific_tag(prefix, s, tbl)
local replacement = nil
local ret = s
- _.each(function(n, t)
+ each(function(n, t)
local ns,matches = string.gsub(s, string.format("<%s%s>", prefix, n), "")
if matches > 0 then
replacement = t
local function replace_all_tags(s)
local str, matches
str = s
- _.each(function(n, t)
+ each(function(n, t)
str,matches = string.gsub(str, string.format("<%s>", n),
string.format("%s%s%s", pre, t, post))
end, replace['tags'])
end
local function parse_atom(str)
- local atom = table.concat(_.totable(_.take_while(function(c)
+ local atom = table.concat(totable(take_while(function(c)
if string.find(', \t()><+!|&\n', c) then
return false
end
return true
- end, _.iter(str))), '')
+ end, iter(str))), '')
return atom
end
local ntags = {}
local function rec_replace_tags(tag, tagv)
if ntags[tag] then return ntags[tag] end
- _.each(function(n, t)
+ each(function(n, t)
if n ~= tag then
local s, matches = string.gsub(tagv, string.format("<%s>", n), t)
if matches > 0 then
return ntags[tag]
end
- _.each(function(n, t)
+ each(function(n, t)
rec_replace_tags(n, t)
end, replace['tags'])
- _.each(function(n, t)
+ each(function(n, t)
replace['tags'][n] = t
end, ntags)
- _.each(function(r)
+ each(function(r)
local rule = rules[r]
if rule['re_expr'] and rule['re'] then
end
end, replace['rules'])
- _.each(function(key, score)
+ each(function(key, score)
if rules[key] then
rules[key]['score'] = score
end
end, scores)
-- Header rules
- _.each(function(k, r)
+ each(function(k, r)
local f = function(task)
local raw = false
end
-- Slow path
- _.each(function(h)
+ each(function(h)
local headers = {}
local hname = h['header']
--rspamd_config:register_symbol(k, calculate_score(k), f)
atoms[k] = f
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'header' and r['header']
end,
rules))
-- Custom function rules
- _.each(function(k, r)
+ each(function(k, r)
local f = function(task)
local res = r['function'](task)
if res and res > 0 then
--rspamd_config:register_symbol(k, calculate_score(k), f)
atoms[k] = f
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'function' and r['function']
end,
rules))
-- Parts rules
- _.each(function(k, r)
+ each(function(k, r)
local f = function(task)
if not r['re'] then
rspamd_logger.errx(task, 're is missing for rule %s', k)
--rspamd_config:register_symbol(k, calculate_score(k), f)
atoms[k] = f
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'part'
end, rules))
-- SA body rules
- _.each(function(k, r)
+ each(function(k, r)
local f = function(task)
if not r['re'] then
rspamd_logger.errx(task, 're is missing for rule %s', k)
--rspamd_config:register_symbol(k, calculate_score(k), f)
atoms[k] = f
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'sabody' or r['type'] == 'message' or r['type'] == 'sarawbody'
end, rules))
-- URL rules
- _.each(function(k, r)
+ each(function(k, r)
local f = function(task)
if not r['re'] then
rspamd_logger.errx(task, 're is missing for rule %s', k)
--rspamd_config:register_symbol(k, calculate_score(k), f)
atoms[k] = f
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'uri'
end,
rules))
-- Meta rules
- _.each(function(k, r)
+ each(function(k, r)
local expression = nil
-- Meta function callback
local meta_cb = function(task)
end
end
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'meta'
end,
rules))
-- Check meta rules for foreign symbols and register dependencies
- _.each(function(k, r)
+ each(function(k, r)
if r['expression'] then
local expr_atoms = r['expression']:atoms()
end
end
end,
- _.filter(function(k, r)
+ filter(function(k, r)
return r['type'] == 'meta'
end,
rules))
-- Set missing symbols
- _.each(function(key, score)
+ each(function(key, score)
if not scores_added[key] then
rspamd_config:set_metric_symbol({
name = key, score = score,