From a1cc7d879c128fe0ff23614dc4e4bc774b69a754 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 24 Nov 2016 12:14:39 +0000 Subject: [PATCH] [Fix] Add handling of regexp maps --- src/lua/global_functions.lua | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/lua/global_functions.lua b/src/lua/global_functions.lua index 64f4f6b72..d3b84b4ea 100644 --- a/src/lua/global_functions.lua +++ b/src/lua/global_functions.lua @@ -436,17 +436,45 @@ function rspamd_map_add(mname, optname, mtype, description) setmetatable(ret, ret_mt) return ret end + elseif mtype == 'regexp' then + local data = {} + local rspamd_regexp = require "rspamd_regexp" + for _,elt in ipairs(opt) do + if type(elt) == 'string' then + local re = rspamd_regexp:create_cached(elt) + + if re then + table.insert(data, re) + else + local logger = require "rspamd_logger" + logger.errx(rspamd_config, "cannot create regexp from '%s'", elt) + end + end + end + + ret.__data = data + ret.get_key = function(t, k) + for _,re in ipairs(t.__data) do + if re:match(k) then return true end + end + + return nil + end else local data = {} for _,elt in ipairs(opt) do if type(elt) == 'string' then - data[elt] = '1' + data[elt] = true end end ret.__data = data ret.get_key = function(t, k) - return t.__data[k] + if k ~= '__data' then + return t.__data[k] + end + + return nil end end else -- 2.39.5