aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_selectors.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-16 09:56:42 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-09-16 10:06:29 +0100
commitce1dbec019d7ab776d89884f09a55e83f5461732 (patch)
tree04b25f7143d0e9f9614ae14d2fd94d86404efa83 /lualib/lua_selectors.lua
parent3e12a51263a3c8dd690ed7d3b0f96a75c3d61b24 (diff)
downloadrspamd-ce1dbec019d7ab776d89884f09a55e83f5461732.tar.gz
rspamd-ce1dbec019d7ab776d89884f09a55e83f5461732.zip
[Minor] Add more methods to lua selectors
Diffstat (limited to 'lualib/lua_selectors.lua')
-rw-r--r--lualib/lua_selectors.lua41
1 files changed, 41 insertions, 0 deletions
diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua
index 00acc4cb2..3262da60e 100644
--- a/lualib/lua_selectors.lua
+++ b/lualib/lua_selectors.lua
@@ -32,6 +32,17 @@ local M = "lua_selectors"
local E = {}
local extractors = {
+ ['id'] = {
+ ['type'] = 'string',
+ ['get_value'] = function(_, args)
+ if args[1] then
+ return args[1]
+ end
+
+ return ''
+ end,
+ ['description'] = 'Return value from function\'s argument or an empty string',
+ },
-- Get source IP address
['ip'] = {
['type'] = 'ip',
@@ -402,6 +413,36 @@ local transform_function = {
end,
['description'] = 'Extracts substring',
},
+ -- Regexp matching
+ ['regexp'] = {
+ ['types'] = {
+ ['string'] = true
+ },
+ ['map_type'] = 'string',
+ ['process'] = function(inp, _, args)
+ local rspamd_regexp = require "rspamd_regexp"
+
+ local re = rspamd_regexp.create_cached(args[1])
+
+ if not re then
+ logger.errx('invalid regexp: %s', args[1])
+ return nil
+ end
+
+ local res = re:search(inp, false, true)
+
+ if res then
+ if #res == 1 then
+ return res[1],'string'
+ end
+
+ return res,'string_list'
+ end
+
+ return nil
+ end,
+ ['description'] = 'Regexp matching',
+ },
-- Drops input value and return values from function's arguments or an empty string
['id'] = {
['types'] = {