From ce1dbec019d7ab776d89884f09a55e83f5461732 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 16 Sep 2018 09:56:42 +0100 Subject: [PATCH] [Minor] Add more methods to lua selectors --- lualib/lua_selectors.lua | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lualib/lua_selectors.lua b/lualib/lua_selectors.lua index 00acc4cb24..3262da60e0 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'] = { -- 2.47.3