diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-16 14:27:02 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-11-16 14:27:02 +0000 |
commit | 3c4fbc745b1f34ad505749f5110722d7a13f0cee (patch) | |
tree | ba70744dd033ab0ddfb044b3df98b35af809f606 /lualib/lua_stat.lua | |
parent | 2d027e3d15a65d4815571c45b04a7e42c99df0d9 (diff) | |
download | rspamd-3c4fbc745b1f34ad505749f5110722d7a13f0cee.tar.gz rspamd-3c4fbc745b1f34ad505749f5110722d7a13f0cee.zip |
[Project] Move stat tokens generation to Lua
Diffstat (limited to 'lualib/lua_stat.lua')
-rw-r--r-- | lualib/lua_stat.lua | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/lualib/lua_stat.lua b/lualib/lua_stat.lua index 9b72a1f22..0ced4b428 100644 --- a/lualib/lua_stat.lua +++ b/lualib/lua_stat.lua @@ -23,6 +23,7 @@ local logger = require "rspamd_logger" local sqlite3 = require "rspamd_sqlite3" local util = require "rspamd_util" local lua_redis = require "lua_redis" +local lua_util = require "lua_util" local exports = {} local N = "stat_tools" -- luacheck: ignore (maybe unused) @@ -516,4 +517,40 @@ end exports.redis_classifier_from_sqlite = redis_classifier_from_sqlite +-- Reads statistics config and return preprocessed table +local function process_stat_config(cfg) + local opts_section = cfg:get_all_opt('options') + + -- Check if we have a dedicated section for statistics + if opts_section.statistics then + opts_section = opts_section.statistics + end + + -- Default + local res_config = { + classify_headers = { + "User-Agent", + "X-Mailer", + "Content-Type", + "X-MimeOLE", + }, + classify_images = true, + classify_mime_info = true, + classify_headers = true, + } + + res_config = lua_util.override_defaults(res_config, opts_section) + + return res_config +end + + +exports.gen_stat_tokens = function(cfg) + local stat_config = process_stat_config(cfg) + + return function(task) + return get_stat_tokens(task, stat_config) + end +end + return exports |