diff options
author | rm-minus-rf <rm.minus.rf@protonmail.com> | 2020-04-17 07:43:56 +0200 |
---|---|---|
committer | rm-minus-rf <rm.minus.rf@protonmail.com> | 2020-04-17 07:43:56 +0200 |
commit | 834279171c3ec8c8a355a9e438f07a06f5b16325 (patch) | |
tree | 789362c07329ded6f584d9f214c368551d1e10d8 /lualib/lua_selectors | |
parent | 0d13c724df534012de7e41c5d5b743a7d9314431 (diff) | |
download | rspamd-834279171c3ec8c8a355a9e438f07a06f5b16325.tar.gz rspamd-834279171c3ec8c8a355a9e438f07a06f5b16325.zip |
[Feature] add queueid, uid, messageid and specific symbols to selectors
[Minor] use only selectors to fill vars in force_actions message
Diffstat (limited to 'lualib/lua_selectors')
-rw-r--r-- | lualib/lua_selectors/extractors.lua | 50 | ||||
-rw-r--r-- | lualib/lua_selectors/transforms.lua | 14 |
2 files changed, 62 insertions, 2 deletions
diff --git a/lualib/lua_selectors/extractors.lua b/lualib/lua_selectors/extractors.lua index 625af435c..635972226 100644 --- a/lualib/lua_selectors/extractors.lua +++ b/lualib/lua_selectors/extractors.lua @@ -388,6 +388,54 @@ The first argument must be header name.]], ]], ['args_schema'] = { ts.one_of { 'stem', 'raw', 'norm', 'full' }:is_optional()}, }, + -- Get queue ID + ['queueid'] = { + ['get_value'] = function(task) + local queueid = task:get_queue_id() + if queueid then return queueid,'string' end + return nil + end, + ['description'] = [[Get queue ID]], + }, + -- Get ID of the task being processed + ['uid'] = { + ['get_value'] = function(task) + local uid = task:get_uid() + if uid then return uid,'string' end + return nil + end, + ['description'] = [[Get ID of the task being processed]], + }, + -- Get message ID of the task being processed + ['messageid'] = { + ['get_value'] = function(task) + local mid = task:get_message_id() + if mid then return mid,'string' end + return nil + end, + ['description'] = [[Get message ID]], + }, + -- Get specific symbol + ['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 + 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()} + }, + } -return extractors
\ No newline at end of file +return extractors diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua index b0c912deb..be896126d 100644 --- a/lualib/lua_selectors/transforms.lua +++ b/lualib/lua_selectors/transforms.lua @@ -413,8 +413,20 @@ 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 + ['to_ascii'] = { + ['types'] = { + ['string'] = true, + }, + ['map_type'] = 'string', + ['process'] = function(inp, _) + return string.gsub(inp, '[\128-\255]', '?'), 'string' + end, + ['description'] = 'Returns the string with all non-ascii bytes replaced with `?`', + }, + } transform_function.match = transform_function.regexp -return transform_function
\ No newline at end of file +return transform_function |