Procházet zdrojové kódy

[Feature] Allow to set task flags via settings

tags/1.7.6
Vsevolod Stakhov před 6 roky
rodič
revize
9fa16c0ead
1 změnil soubory, kde provedl 25 přidání a 25 odebrání
  1. 25
    25
      src/plugins/lua/settings.lua

+ 25
- 25
src/plugins/lua/settings.lua Zobrazit soubor

local ucl = require "ucl" local ucl = require "ucl"
local fun = require "fun" local fun = require "fun"


local function apply_settings(task, to_apply)
task:set_settings(to_apply)
task:cache_set('settings', to_apply)
lua_squeeze.handle_settings(task, to_apply)

if to_apply['add_headers'] or to_apply['remove_headers'] then
local rep = {
add_headers = to_apply['add_headers'] or {},
remove_headers = to_apply['remove_headers'] or {},
}
task:set_rmilter_reply(rep)
end

if to_apply.flags and type(to_apply.flags) == 'table' then
for _,fl in ipairs(to_apply.flags) do
task:set_flag(fl)
end
end
end

-- Checks for overridden settings within query params and returns 'true' if -- Checks for overridden settings within query params and returns 'true' if
-- settings are overridden -- settings are overridden
local function check_query_settings(task) local function check_query_settings(task)
local res,err = parser:parse_string(tostring(query_set)) local res,err = parser:parse_string(tostring(query_set))
if res then if res then
local settings_obj = parser:get_object() local settings_obj = parser:get_object()
task:set_settings(settings_obj)
task:cache_set('settings', settings_obj)
lua_squeeze.handle_settings(task, settings_obj)
apply_settings(task, settings_obj)


return true return true
else else
nset['default']['actions']['add header'] = ss nset['default']['actions']['add header'] = ss
end end


task:set_settings(nset)
task:cache_set('settings', nset)
lua_squeeze.handle_settings(task, nset)

apply_settings(task, nset)
return true return true
end end
end end
local id_str = tostring(settings_id) local id_str = tostring(settings_id)
local elt = settings_ids[id_str] local elt = settings_ids[id_str]
if elt and elt['apply'] then if elt and elt['apply'] then
task:set_settings(elt['apply'])
lua_squeeze.handle_settings(task, elt['apply'])
task:cache_set('settings', elt['apply'])

if elt.apply['add_headers'] or elt.apply['remove_headers'] then
local rep = {
add_headers = elt.apply['add_headers'] or {},
remove_headers = elt.apply['remove_headers'] or {},
}
task:set_rmilter_reply(rep)
end
apply_settings(task, elt['apply'])
rspamd_logger.infox(task, "applying settings id %s", id_str) rspamd_logger.infox(task, "applying settings id %s", id_str)

return true return true
end end
end end
rspamd_logger.infox(task, "<%1> apply settings according to rule %2", rspamd_logger.infox(task, "<%1> apply settings according to rule %2",
task:get_message_id(), s.name) task:get_message_id(), s.name)
if rule['apply'] then if rule['apply'] then
task:set_settings(rule['apply'])
lua_squeeze.handle_settings(task, rule['apply'])
task:cache_set('settings', rule['apply'])
apply_settings(task, rule['apply'])
applied = true applied = true
end end
if rule['symbols'] then if rule['symbols'] then
local obj = parser:get_object() local obj = parser:get_object()
rspamd_logger.infox(task, "<%1> apply settings according to redis rule %2", rspamd_logger.infox(task, "<%1> apply settings according to redis rule %2",
task:get_message_id(), id) task:get_message_id(), id)
task:set_settings(obj)
lua_squeeze.handle_settings(task, obj)
task:cache_set('settings', obj)
apply_settings(task, obj)
break break
end end
end end

Načítá se…
Zrušit
Uložit