aboutsummaryrefslogtreecommitdiffstats
path: root/lualib/lua_selectors/transforms.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-19 14:37:10 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2019-08-19 14:37:10 +0100
commit0c8dcea94a3999d7a008afa37eb740ec431defc3 (patch)
tree8fdb2829a4e94ef295d3c07b2b0c48f366028046 /lualib/lua_selectors/transforms.lua
parentc3d9d449aadb4cd6853218b10de458c3227372bb (diff)
downloadrspamd-0c8dcea94a3999d7a008afa37eb740ec431defc3.tar.gz
rspamd-0c8dcea94a3999d7a008afa37eb740ec431defc3.zip
[Minor] Selectors: Add except_map function
Diffstat (limited to 'lualib/lua_selectors/transforms.lua')
-rw-r--r--lualib/lua_selectors/transforms.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/lualib/lua_selectors/transforms.lua b/lualib/lua_selectors/transforms.lua
index 99b4201ef..ffc9acd00 100644
--- a/lualib/lua_selectors/transforms.lua
+++ b/lualib/lua_selectors/transforms.lua
@@ -253,6 +253,31 @@ the second argument is optional hash type (`blake2`, `sha256`, `sha1`, `sha512`,
['description'] = 'Returns a value if it exists in some map (or acts like a `filter` function)',
['args_schema'] = {ts.string}
},
+ -- Returns a value if it exists in some map (or acts like a `filter` function)
+ ['except_map'] = {
+ ['types'] = {
+ ['string'] = true
+ },
+ ['map_type'] = 'string',
+ ['process'] = function(inp, t, args)
+ local map = maps[args[1]]
+
+ if not map then
+ logger.errx('invalid map name: %s', args[1])
+ return nil
+ end
+
+ local res = map:get_key(inp)
+
+ if not res then
+ return inp,t
+ end
+
+ return nil
+ end,
+ ['description'] = 'Returns a value if it does not exists in some map (or acts like a `except` function)',
+ ['args_schema'] = {ts.string}
+ },
-- Returns a value from some map corresponding to some key (or acts like a `map` function)
['apply_map'] = {
['types'] = {