From 17496d611054ecca73a852c4b7aa78a618967680 Mon Sep 17 00:00:00 2001 From: Andrew Lewis Date: Sat, 21 Jan 2017 10:45:07 +0200 Subject: [PATCH] [Feature] Plugin to force actions on selected symbols --- src/plugins/lua/force_actions.lua | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/plugins/lua/force_actions.lua diff --git a/src/plugins/lua/force_actions.lua b/src/plugins/lua/force_actions.lua new file mode 100644 index 000000000..011d9bda1 --- /dev/null +++ b/src/plugins/lua/force_actions.lua @@ -0,0 +1,55 @@ +--[[ +Copyright (c) 2017, Andrew Lewis +Copyright (c) 2017, Vsevolod Stakhov + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +]]-- + +-- A plugin that forces actions + +local E = {} +local N = 'force_actions' + +local function gen_cb(sym, act, message) + return function(task) + local s = task:get_symbol(sym) + if not s then return end + task:set_pre_result(act, message) + return true + end +end + +local function configure_module() + local opts = rspamd_config:get_all_opt(N) + if not opts then + return false + end + if type(opts.actions) ~= 'table' then + return false + end + for action, symbols in pairs(opts.actions) do + if type(symbols) == 'table' then + for _, symbol in ipairs(symbols) do + local message = (opts.messages or E)[symbol] + local id = rspamd_config:register_symbol({ + type = 'normal', + name = 'FORCE_ACTION_ON' .. symbol, + callback = gen_cb(symbol, action, message), + }) + rspamd_config:register_dependency(id, symbol) + end + end + end +end + +configure_module() -- 2.39.5