Debian Codegraph @

test/functional/lua/neural.lua

raw
1 local logger = require "rspamd_logger"
2
3 for i = 1,14 do
4 rspamd_config:register_symbol({
5 name = 'SPAM_SYMBOL'..tostring(i),
6 score = 5.0,
7 callback = function()
8 return true, 'Fires always'
9 end
10 })
11 rspamd_config:register_symbol({
12 name = 'HAM_SYMBOL'..tostring(i),
13 score = -3.0,
14 callback = function()
15 return true, 'Fires always'
16 end
17 })
18 end
19
20
21
22 rspamd_config:register_symbol({
23 name = 'NEUTRAL_SYMBOL',
24 score = 1.0,
25 flags = 'explicit_disable',
26 callback = function()
27 return true, 'Fires always'
28 end
29 })
30
31 rspamd_config.SAVE_NN_ROW = {
32 callback = function(task)
33 local fname = os.tmpname()
34 task:cache_set('nn_row_tmpfile', fname)
35 return true, 1.0, fname
36 end
37 }
38
39 rspamd_config.SAVE_NN_ROW_IDEMPOTENT = {
40 callback = function(task)
41 local function tohex(str)
42 return (str:gsub('.', function (c)
43 return string.format('%02X', string.byte(c))
44 end))
45 end
46 local fname = task:cache_get('nn_row_tmpfile')
47 if not fname then
48 return
49 end
50 local f, err = io.open(fname, 'w')
51 if not f then
52 logger.errx(task, err)
53 return
54 end
55 f:write(tohex(task:cache_get('SHORT_neural_vec_mpack') or ''))
56 f:close()
57 return
58 end,
59 type = 'idempotent',
60 flags = 'explicit_disable',
61 priority = 100,
62 }
63
64 dofile(rspamd_env.INSTALLROOT .. "/share/rspamd/rules/controller/init.lua")