aboutsummaryrefslogtreecommitdiffstats
path: root/lualib
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 14:30:51 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-11-05 14:30:51 +0000
commit578497bab343ec7372c9fd6a7e4ee3e0e4aca59f (patch)
tree0ae3ac40ae7e09d9e1cbaf8162021c6e6db2b8ee /lualib
parent997b81a6f13a49ccf39c8c7adee1c41e25ff382c (diff)
downloadrspamd-578497bab343ec7372c9fd6a7e4ee3e0e4aca59f.tar.gz
rspamd-578497bab343ec7372c9fd6a7e4ee3e0e4aca59f.zip
[Project] Add logic to check content type
Diffstat (limited to 'lualib')
-rw-r--r--lualib/lua_fuzzy.lua33
1 files changed, 32 insertions, 1 deletions
diff --git a/lualib/lua_fuzzy.lua b/lualib/lua_fuzzy.lua
index 2ce18bb62..30ec278c8 100644
--- a/lualib/lua_fuzzy.lua
+++ b/lualib/lua_fuzzy.lua
@@ -22,6 +22,8 @@ limitations under the License.
local N = "lua_fuzzy"
local lua_util = require "lua_util"
+local rspamd_regexp = require "rspamd_regexp"
+local fun = require "fun"
local rspamd_logger = require "rspamd_logger"
local ts = require("tableshape").types
@@ -102,6 +104,19 @@ exports.process_rule = function(rule)
end
end
+ if processed_rule.mime_types then
+ processed_rule.mime_types = fun.totable(fun.map(function(gl)
+ return rspamd_regexp.import_glob(gl, 'i')
+ end, processed_rule.mime_types))
+ end
+
+ if processed_rule.extensions then
+ processed_rule.mime_types = fun.totable(fun.map(function(gl)
+ return rspamd_regexp.import_glob(gl, 'i')
+ end, processed_rule.extensions))
+ end
+
+
table.insert(rules, processed_rule)
return #rules
end
@@ -184,7 +199,23 @@ local function check_image_part(task, part, rule, image)
end
local function mime_types_check(task, part, rule)
- return true,true -- TODO: add checks
+ local t,st = part:get_type()
+
+ if not t then return false, false end
+
+ local ct = string.format('%s/%s', t, st)
+
+ if rule.mime_types then
+ if fun.any(function(gl_re)
+ if gl_re:match(ct) then return true else return false end
+ end, rule.mime_types) then
+ return true, true
+ end
+
+ return false, false
+ end
+
+ return false,false
end
exports.check_mime_part = function(task, part, rule_id)