diff options
author | rm-minus-rf <rm.minus.rf@protonmail.com> | 2020-04-18 00:17:29 +0200 |
---|---|---|
committer | rm-minus-rf <rm.minus.rf@protonmail.com> | 2020-04-18 00:17:29 +0200 |
commit | 00b2ecaa3b1ec5629a1c37781af80b7afa23913b (patch) | |
tree | 4a1a2ceed45afd012871fd633507c3b676eb8166 | |
parent | e1e23ddef268163cec9e1d1fafbfda0b36917e77 (diff) | |
download | rspamd-00b2ecaa3b1ec5629a1c37781af80b7afa23913b.tar.gz rspamd-00b2ecaa3b1ec5629a1c37781af80b7afa23913b.zip |
[Minor] selectors: cleaner symbol extractor
'symbol' extractor returns a table
'to_ascii' transform can handle tables
-rw-r--r-- | lualib/lua_selectors/extractors.lua | 17 | ||||
-rw-r--r-- | lualib/lua_selectors/transforms.lua | 15 | ||||
-rw-r--r-- | src/plugins/lua/force_actions.lua | 1 |
3 files changed, 15 insertions, 18 deletions
diff --git a/lualib/lua_selectors/extractors.lua b/lualib/lua_selectors/extractors.lua index 635972226..695371e79 100644 --- a/lualib/lua_selectors/extractors.lua +++ b/lualib/lua_selectors/extractors.lua @@ -419,21 +419,12 @@ The first argument must be header name.]], ['symbol'] = { ['get_value'] = function(task, args) local symbol = task:get_symbol(args[1]) - if args[2] and symbol then - if args[2] == 'options' then - -- concat options tables to avoid table representation strings produced by implicit conversion - return fun.map(function(r) return table.concat(r[args[2]], ', ') end, symbol), 'string_list' - elseif args[2] == 'score' then - -- only userdata_list seems to work for scores - return fun.map(function(r) return r[args[2]] end, symbol), 'userdata_list' - else - return fun.map(function(r) return r[args[2]] end, symbol), 'string_list' - end + if symbol then + return symbol[1],'table' end - return symbol,'table_list' end, - ['description'] = [[Get specific symbol. The first argument must be the symbol name. If no second argument is specified, returns a list of symbol tables. Otherwise the second argument specifies the attribute which is returned as list (`options`, `score` or `group`)]], - ['args_schema'] = {ts.string, ts.one_of{'options','score','group'}:is_optional()} + ['description'] = [[Get specific symbol. The first argument must be the symbol name. Returns the symbol table. See task:get_symbol()]], + ['args_schema'] = {ts.string} }, } diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua index be896126d..b1088aa75 100644 --- a/lualib/lua_selectors/transforms.lua +++ b/lualib/lua_selectors/transforms.lua @@ -413,16 +413,23 @@ Empty string comes the first argument or 'true', non-empty string comes nil]], ['args_schema'] = {(ts.number + ts.string / tonumber), (ts.number + ts.string / tonumber):is_optional()} }, - -- Returns the string with all non ascii chars replaced + -- Returns the string(s) with all non ascii chars replaced ['to_ascii'] = { ['types'] = { ['string'] = true, + ['list'] = true, }, ['map_type'] = 'string', - ['process'] = function(inp, _) - return string.gsub(inp, '[\128-\255]', '?'), 'string' + ['process'] = function(inp, _, args) + if type(inp) == 'table' then + return fun.map( function(s) return string.gsub(tostring(s), '[\128-\255]', args[1] or '?') end , inp), 'string_list' + else + return string.gsub(tostring(inp), '[\128-\255]', '?'), 'string' + end + end, - ['description'] = 'Returns the string with all non-ascii bytes replaced with `?`', + ['description'] = 'Returns the string with all non-ascii bytes replaced with the character given as second argument or `?`', + ['args_schema'] = {ts.string:is_optional()} }, } diff --git a/src/plugins/lua/force_actions.lua b/src/plugins/lua/force_actions.lua index e86892f6a..eda87ead0 100644 --- a/src/plugins/lua/force_actions.lua +++ b/src/plugins/lua/force_actions.lua @@ -111,7 +111,6 @@ local function gen_cb(expr, act, pool, message, subject, raction, honor, limit, -- process selector expressions in the message message = string.gsub(message, '(${(.-)})', process_message_selectors) task:set_pre_result(act, message, N, nil, nil, flags) - else task:set_pre_result(act, nil, N, nil, nil, flags) end |