return ret
end
+
+function rspamd_str_split(s, sep)
+ local lpeg = require "lpeg"
+ sep = lpeg.P(sep)
+ local elem = lpeg.C((1 - sep)^0)
+ local p = lpeg.Ct(elem * (sep * elem)^0) -- make a table capture
+ return lpeg.match(p, s)
+end
\ No newline at end of file
return false
end
-local function split(str, delim, maxNb)
- -- Eliminate bad cases...
- if string.find(str, delim) == nil then
- return { str }
- end
- if maxNb == nil or maxNb < 1 then
- maxNb = 0 -- No limit
- end
- local result = {}
- local pat = "(.-)" .. delim .. "()"
- local nb = 0
- local lastPos
- for part, pos in string.gmatch(str, pat) do
- nb = nb + 1
- result[nb] = part
- lastPos = pos
- if nb == maxNb then break end
- end
- -- Handle the last field
- if nb ~= maxNb then
- result[nb + 1] = string.sub(str, lastPos)
- end
- return result
-end
-
local function check_fqdn(domain)
if check_regexp(domain, '(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{1,63}(?<!-)\\.)+[a-zA-Z0-9-]{2,63}\\.?$)') then
return true
if from then
--FROM host check
for _,fr in ipairs(from) do
- local fr_split = split(fr['addr'], '@', 0)
+ local fr_split = rspamd_str_split(fr['addr'], '@')
if table.maxn(fr_split) == 2 then
check_host(task, fr_split[2], 'FROMHOST', '', '')
if fr_split[1] == 'postmaster' then
if config['mid_enabled'] then
local message_id = task:get_message_id()
if message_id then
- local mid_split = split(message_id, '@', 0)
+ local mid_split = rspamd_str_split(message_id, '@')
if table.maxn(mid_split) == 2 and not string.find(mid_split[2], 'local') then
check_host(task, mid_split[2], 'MID')
end
local _ = require "fun"
--local dumper = require 'pl.pretty'.dump
---- Utility function for split string to table
-local function split(str, delim, maxNb)
- -- Eliminate bad cases...
- if string.find(str, delim) == nil then
- return { str }
- end
- if maxNb == nil or maxNb < 1 then
- maxNb = 0 -- No limit
- end
- local result = {}
- local pat = "(.-)" .. delim .. "()"
- local nb = 0
- local lastPos
- for part, pos in string.gmatch(str, pat) do
- nb = nb + 1
- result[nb] = part
- lastPos = pos
- if nb == maxNb then break end
- end
- -- Handle the last field
- if nb ~= maxNb then
- result[nb + 1] = string.sub(str, lastPos)
- end
- return result
-end
-
--- Parse atime and bucket of limit
local function parse_limits(data)
local function parse_limit_elt(str)
- local elts = split(str, ':', 3)
+ local elts = rspamd_str_split(str, ':')
if not elts or #elts < 2 then
return {0, 0, 0}
else
--- Parse a single limit description
local function parse_limit(str)
- local params = split(str, ':', 0)
+ local params = rspamd_str_split(str, ':')
local function set_limit(limit, burst, rate)
limit[1] = tonumber(burst)
rspamd_logger.infox(rspamd_config, 'enabled rate buckets: %s', enabled_limits)
if opts['whitelisted_rcpts'] and type(opts['whitelisted_rcpts']) == 'string' then
- whitelisted_rcpts = split(opts['whitelisted_rcpts'], ',')
+ whitelisted_rcpts = rspamd_str_split(opts['whitelisted_rcpts'], ',')
elseif type(opts['whitelisted_rcpts']) == 'table' then
whitelisted_rcpts = opts['whitelisted_rcpts']
end