aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/lua/multimap.lua
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-12 15:33:59 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-02-12 15:33:59 +0000
commitfc248c371b6b67d336a36947cd75a421e89be68a (patch)
tree3288f9f789200a49a5a87b256abdce9d958eecb8 /src/plugins/lua/multimap.lua
parent85b3f42f215e5736d90a803835f506673538bbd0 (diff)
downloadrspamd-fc248c371b6b67d336a36947cd75a421e89be68a.tar.gz
rspamd-fc248c371b6b67d336a36947cd75a421e89be68a.zip
Implement regexp filters for URL multimap
Diffstat (limited to 'src/plugins/lua/multimap.lua')
-rw-r--r--src/plugins/lua/multimap.lua54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua
index 760c5c1d0..44240f195 100644
--- a/src/plugins/lua/multimap.lua
+++ b/src/plugins/lua/multimap.lua
@@ -163,6 +163,60 @@ local function multimap_callback(task, pre_filter)
else
return nil
end
+ elseif string.find(filter, 'tld:regexp:') then
+ if not r['regexp'] then
+ local type,pat = string.match(filter, '(regexp:)(.+)')
+ if type and pat then
+ r['regexp'] = regexp.create(pat)
+ end
+ end
+
+ if not r['regexp'] then
+ rspamd_logger.errx(task, 'bad search filter: %s', filter)
+ else
+ local results = r['regexp']:search(url:get_tld())
+ if results then
+ return results[1]
+ else
+ return nil
+ end
+ end
+ elseif string.find(filter, 'full:regexp:') then
+ if not r['regexp'] then
+ local type,pat = string.match(filter, '(regexp:)(.+)')
+ if type and pat then
+ r['regexp'] = regexp.create(pat)
+ end
+ end
+
+ if not r['regexp'] then
+ rspamd_logger.errx(task, 'bad search filter: %s', filter)
+ else
+ local results = r['regexp']:search(url:get_text())
+ if results then
+ return results[1]
+ else
+ return nil
+ end
+ end
+ elseif string.find(filter, 'regexp:') then
+ if not r['regexp'] then
+ local type,pat = string.match(filter, '(regexp:)(.+)')
+ if type and pat then
+ r['regexp'] = regexp.create(pat)
+ end
+ end
+
+ if not r['regexp'] then
+ rspamd_logger.errx(task, 'bad search filter: %s', filter)
+ else
+ local results = r['regexp']:search(url:get_host())
+ if results then
+ return results[1]
+ else
+ return nil
+ end
+ end
end
return url:get_host()