From 27c212d3e34088522477cf4dc9cdd8fb75accd6f Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 4 Nov 2018 10:01:41 +0000 Subject: [Feature] Add support of cookies in replies module --- src/plugins/lua/replies.lua | 94 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 88 insertions(+), 6 deletions(-) diff --git a/src/plugins/lua/replies.lua b/src/plugins/lua/replies.lua index fe15211ef..7e9816fb8 100644 --- a/src/plugins/lua/replies.lua +++ b/src/plugins/lua/replies.lua @@ -37,6 +37,9 @@ local settings = { score = -4, -- Default score use_auth = true, use_local = true, + cookie = nil, + cookie_key = nil, + cookie_is_pattern = false } local N = "replies" @@ -128,16 +131,99 @@ local function replies_set(task) end end +local function replies_check_cookie(task) + local function cookie_matched(extra) + + if extra then + task:insert_result(settings['symbol'], 1.0, string.format('cookie:%s', extra)) + else + task:insert_result(settings['symbol'], 1.0, 'cookie') + end + if settings['action'] ~= nil then + local ip_addr = task:get_ip() + if (settings.use_auth and + task:get_user()) or + (settings.use_local and ip_addr and ip_addr:is_local()) then + rspamd_logger.infox(task, "not forcing action for local network or authorized user"); + else + task:set_pre_result(settings['action'], settings['message'], N) + end + end + end + + -- If in-reply-to header not present return + local irt = task:get_header('in-reply-to') + if irt == nil then + return + end + + local cr = require "rspamd_cryptobox" + -- Extract user part if needed + local extracted_cookie = irt:match('^%