diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-21 14:14:43 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-21 14:14:43 +0000 |
commit | 954a6ec8cd67b6b0b5d70d005c2506678810c8cc (patch) | |
tree | 0e2e27eecc825e0909db47d58d63ea79b8f218ed | |
parent | 9943eb69b0192ad589d4144c290d6857d922bd20 (diff) | |
download | rspamd-954a6ec8cd67b6b0b5d70d005c2506678810c8cc.tar.gz rspamd-954a6ec8cd67b6b0b5d70d005c2506678810c8cc.zip |
[Minor] Slightly improve antivirus parts selection logic
-rw-r--r-- | src/plugins/lua/antivirus.lua | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/src/plugins/lua/antivirus.lua b/src/plugins/lua/antivirus.lua index a00d2cd73..f5fd6312c 100644 --- a/src/plugins/lua/antivirus.lua +++ b/src/plugins/lua/antivirus.lua @@ -20,6 +20,7 @@ local rspamd_regexp = require "rspamd_regexp" local tcp = require "rspamd_tcp" local upstream_list = require "rspamd_upstream_list" local lua_util = require "lua_util" +local fun = require "fun" local redis_params local N = "antivirus" @@ -890,21 +891,20 @@ local function add_antivirus_rule(sym, opts) if rule.scan_mime_parts then local parts = task:get_parts() or {} - for _,p in ipairs(parts) do - if ( - (p:is_image() and rule.scan_image_mime) - or (p:is_text() and rule.scan_text_mime) - or (p:is_multipart() and rule.scan_text_mime) - or (not p:is_image() and not p:is_text() and not p:is_multipart()) - ) then + local filter_func = function(p) + return (rule.scan_image_mime and p:is_image()) + or (rule.scan_text_mime and p:is_text()) + or (p:get_filename()) + end - local content = p:get_content() + fun.each(function(p) + local content = p:get_content() - if content and #content > 0 then - cfg.check(task, content, p:get_digest(), rule) - end + if content and #content > 0 then + cfg.check(task, content, p:get_digest(), rule) end - end + end, fun.filter(filter_func, parts)) + else cfg.check(task, task:get_content(), task:get_digest(), rule) end |