aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_cfg_transform.lua6
-rw-r--r--lualib/lua_clickhouse.lua10
-rw-r--r--lualib/lua_dkim_tools.lua39
-rw-r--r--lualib/lua_ffi/init.lua1
-rw-r--r--lualib/lua_selectors.lua21
5 files changed, 71 insertions, 6 deletions
diff --git a/lualib/lua_cfg_transform.lua b/lualib/lua_cfg_transform.lua
index 8a61dcd29..ae05eed59 100644
--- a/lualib/lua_cfg_transform.lua
+++ b/lualib/lua_cfg_transform.lua
@@ -242,6 +242,12 @@ return function(cfg)
ret = true
end
+ if cfg.symbols then
+ for k, v in metric_pairs(cfg.symbols) do
+ symbol_transform(cfg, k, v)
+ end
+ end
+
check_statistics_sanity()
if not cfg.actions then
diff --git a/lualib/lua_clickhouse.lua b/lualib/lua_clickhouse.lua
index dbb74e283..96ea59f02 100644
--- a/lualib/lua_clickhouse.lua
+++ b/lualib/lua_clickhouse.lua
@@ -227,7 +227,7 @@ exports.select = function (upstream, settings, params, query, ok_cb, fail_cb)
connect_prefix = 'https://'
end
local ip_addr = upstream:get_addr():to_string(true)
- local database = params.database or 'default'
+ local database = settings.database or 'default'
http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow',
connect_prefix, ip_addr, escape_spaces(database))
end
@@ -278,7 +278,7 @@ exports.select_sync = function (upstream, settings, params, query, ok_cb, fail_c
connect_prefix = 'https://'
end
local ip_addr = upstream:get_addr():to_string(true)
- local database = params.database or 'default'
+ local database = settings.database or 'default'
http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow',
connect_prefix, ip_addr, escape_spaces(database))
end
@@ -342,7 +342,7 @@ exports.insert = function (upstream, settings, params, query, rows,
connect_prefix = 'https://'
end
local ip_addr = upstream:get_addr():to_string(true)
- local database = params.database or 'default'
+ local database = settings.database or 'default'
http_params.url = string.format('%s%s/?database=%s&query=%s%%20FORMAT%%20TabSeparated',
connect_prefix,
ip_addr,
@@ -394,7 +394,7 @@ exports.generic = function (upstream, settings, params, query,
connect_prefix = 'https://'
end
local ip_addr = upstream:get_addr():to_string(true)
- local database = params.database or 'default'
+ local database = settings.database or 'default'
http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow',
connect_prefix, ip_addr, escape_spaces(database))
end
@@ -439,7 +439,7 @@ exports.generic_sync = function (upstream, settings, params, query)
connect_prefix = 'https://'
end
local ip_addr = upstream:get_addr():to_string(true)
- local database = params.database or 'default'
+ local database = settings.database or 'default'
http_params.url = string.format('%s%s/?database=%s&default_format=JSONEachRow',
connect_prefix, ip_addr, escape_spaces(database))
end
diff --git a/lualib/lua_dkim_tools.lua b/lualib/lua_dkim_tools.lua
index 4302d24ad..fc891ba71 100644
--- a/lualib/lua_dkim_tools.lua
+++ b/lualib/lua_dkim_tools.lua
@@ -120,7 +120,17 @@ local function prepare_dkim_signing(N, task, settings)
local is_local, is_sign_networks
if settings.use_http_headers then
- return parse_dkim_http_headers(N, task, settings)
+ local res,tbl = parse_dkim_http_headers(N, task, settings)
+
+ if not res then
+ if not settings.allow_headers_fallback then
+ return res,{}
+ else
+ lua_util.debugm(N, task, 'failed to read http headers, fallback to normal schema')
+ end
+ else
+ return res,tbl
+ end
end
local auser = task:get_user()
@@ -174,6 +184,8 @@ local function prepare_dkim_signing(N, task, settings)
return udom
elseif settings[dtype] == 'recipient' then
return tdom
+ else
+ return settings[dtype]:lower()
end
end
@@ -202,6 +214,31 @@ local function prepare_dkim_signing(N, task, settings)
dkim_domain = get_dkim_domain('use_domain_sign_inbound')
lua_util.debugm(N, task, 'inbound: use domain(%s) for signature: %s',
settings.use_domain_sign_inbound, dkim_domain)
+ elseif settings.use_domain_custom then
+ if type(settings.use_domain_custom) == 'string' then
+ -- Load custom function
+ local loadstring = loadstring or load
+ local ret, res_or_err = pcall(loadstring(settings.use_domain_custom))
+ if ret then
+ if type(res_or_err) == 'function' then
+ settings.use_domain_custom = res_or_err
+ dkim_domain = settings.use_domain_custom(task)
+ lua_util.debugm(N, task, 'use custom domain for signing: %s',
+ dkim_domain)
+ else
+ logger.errx(task, 'cannot load dkim domain custom script: invalid type: %s, expected function',
+ type(res_or_err))
+ settings.use_domain_custom = nil
+ end
+ else
+ logger.errx(task, 'cannot load dkim domain custom script: %s', res_or_err)
+ settings.use_domain_custom = nil
+ end
+ else
+ dkim_domain = settings.use_domain_custom(task)
+ lua_util.debugm(N, task, 'use custom domain for signing: %s',
+ dkim_domain)
+ end
else
dkim_domain = get_dkim_domain('use_domain')
lua_util.debugm(N, task, 'use domain(%s) for signature: %s',
diff --git a/lualib/lua_ffi/init.lua b/lualib/lua_ffi/init.lua
index d2cbd95aa..b0254bdd8 100644
--- a/lualib/lua_ffi/init.lua
+++ b/lualib/lua_ffi/init.lua
@@ -46,6 +46,7 @@ else
end
end
+pcall(ffi.load, "rspamd-server", true)
exports.common = require "lua_ffi/common"
exports.dkim = require "lua_ffi/dkim"
diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua
index 0a02edca9..b678ef179 100644
--- a/lualib/lua_selectors.lua
+++ b/lualib/lua_selectors.lua
@@ -199,6 +199,27 @@ the second optional argument is optional hash type (`blake2`, `sha256`, `sha1`,
end,
['description'] = 'Get all attachments files',
},
+ -- Get languages for text parts
+ ['languages'] = {
+ ['get_value'] = function(task)
+ local text_parts = task:get_text_parts() or E
+ local languages = {}
+
+ for _,p in ipairs(text_parts) do
+ local lang = p:get_language()
+ if lang then
+ table.insert(languages, lang)
+ end
+ end
+
+ if #languages > 0 then
+ return languages,'string_list'
+ end
+
+ return nil
+ end,
+ ['description'] = 'Get languages for text parts',
+ },
-- Get helo value
['helo'] = {
['get_value'] = function(task)