diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-12-13 21:36:31 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rspamd.com> | 2022-12-13 21:36:31 +0000 |
commit | b29fa2e81b4e04dab29b05d0750d527bb9998aa1 (patch) | |
tree | b5a1d2fcbdc909aedef20b35ef8a7a089ed4e158 /lualib/lua_selectors | |
parent | fe24cb2ef55b3b5eecb1ef7a93e0dae7d2e8d2ed (diff) | |
download | rspamd-b29fa2e81b4e04dab29b05d0750d527bb9998aa1.tar.gz rspamd-b29fa2e81b4e04dab29b05d0750d527bb9998aa1.zip |
[Feature] Selectors: Add specific_urls_filter_map extractor
Diffstat (limited to 'lualib/lua_selectors')
-rw-r--r-- | lualib/lua_selectors/extractors.lua | 34 | ||||
-rw-r--r-- | lualib/lua_selectors/init.lua | 3 |
2 files changed, 37 insertions, 0 deletions
diff --git a/lualib/lua_selectors/extractors.lua b/lualib/lua_selectors/extractors.lua index a4b33f52f..fa5fd314f 100644 --- a/lualib/lua_selectors/extractors.lua +++ b/lualib/lua_selectors/extractors.lua @@ -20,7 +20,9 @@ local lua_util = require "lua_util" local rspamd_url = require "rspamd_url" local common = require "lua_selectors/common" local ts = require("tableshape").types +local maps = require "lua_selectors/maps" local E = {} +local M = (require "lua_selectors").M local url_flags_ts = ts.array_of(ts.one_of(lua_util.keys(rspamd_url.flags))):is_optional() @@ -313,6 +315,38 @@ e.g. `get_tld`]], ignore_redirected = (ts.boolean + ts.string / lua_util.toboolean):is_optional(), }} }, + ['specific_urls_filter_map'] = { + ['get_value'] = function(task, args) + local map = maps[args[1]] + if not map then + lua_util.debugm(M, "invalid/unknown map: %s", args[1]) + end + local params = args[2] or {} + params.task = task + params.no_cache = true + if params.exclude_flags then + params.filter = gen_exclude_flags_filter(params.exclude_flags) + end + local urls = lua_util.extract_specific_urls(params) + if not urls[1] then + return nil + end + return fun.filter(function(u) return map:get_key(tostring(u)) end, urls),'userdata_list' + end, + ['description'] = [[Get most specific urls, filtered by some map. Arguments are equal to the Lua API function]], + ['args_schema'] = {ts.array_of{ts.string, ts.shape{ + limit = ts.number + ts.string / tonumber, + esld_limit = (ts.number + ts.string / tonumber):is_optional(), + exclude_flags = url_flags_ts, + flags = url_flags_ts, + flags_mode = ts.one_of{'explicit'}:is_optional(), + prefix = ts.string:is_optional(), + need_content = (ts.boolean + ts.string / lua_util.toboolean):is_optional(), + need_emails = (ts.boolean + ts.string / lua_util.toboolean):is_optional(), + need_images = (ts.boolean + ts.string / lua_util.toboolean):is_optional(), + ignore_redirected = (ts.boolean + ts.string / lua_util.toboolean):is_optional(), + }}} + }, -- URLs filtered by flags ['urls_filtered'] = { ['get_value'] = function(task, args) diff --git a/lualib/lua_selectors/init.lua b/lualib/lua_selectors/init.lua index f05b21249..7c8d526d2 100644 --- a/lualib/lua_selectors/init.lua +++ b/lualib/lua_selectors/init.lua @@ -623,4 +623,7 @@ exports.add_map = function(name, map) end end +-- Publish log target +exports.M = M + return exports |