diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-12 14:22:33 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-05-12 14:47:15 +0100 |
commit | e39900d3ee88253e7b5d4d933b9469280ee5b761 (patch) | |
tree | 367a18068bdd8c93ba90025f2beefa258f5a9bea /lualib | |
parent | d003c95fcb69a691bea466579e78a3738d57f4b6 (diff) | |
download | rspamd-e39900d3ee88253e7b5d4d933b9469280ee5b761.tar.gz rspamd-e39900d3ee88253e7b5d4d933b9469280ee5b761.zip |
[Minor] Allow to filter urls
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_util.lua | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index e72d7d319..ec0e8882c 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -476,14 +476,21 @@ end exports.override_defaults = override_defaults --[[[ --- @function lua_util.extract_specific_urls(task, limit) +-- @function lua_util.extract_specific_urls(task, limit, [need_emails[, filter[, prefix]) -- Apply heuristic in extracting of urls from task, this function -- tries its best to extract specific number of urls from a task based on -- their characteristics --]] -exports.extract_specific_urls = function(task, lim, need_emails) +exports.extract_specific_urls = function(task, lim, need_emails, filter, prefix) local fun = require "fun" - local cache_key = string.format('sp_urls_%d%s', lim, need_emails) + local cache_key + + if prefix then + cache_key = prefix + else + cache_key = string.format('sp_urls_%d%s', lim, need_emails) + end + local cached = task:cache_get(cache_key) @@ -493,9 +500,10 @@ exports.extract_specific_urls = function(task, lim, need_emails) local urls = task:get_urls(need_emails) - if not urls then return {} end + if filter then urls = fun.totable(fun.filter(filter, urls)) end + if #urls <= lim then task:cache_set(cache_key, urls) |