aboutsummaryrefslogtreecommitdiffstats
path: root/test/functional/lua/prepostfilters.lua
blob: c87c958490f92cf54bf5b80ba905222c8bc52e7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
for i = 1,10 do
  local name = string.format('DEP_TEST%d', i)
  local dep_name = string.format('DEP_TEST%d', i - 1)
  rspamd_config:register_symbol({
    type = 'normal',
    name = name,
    callback = function(task)
      local function dns_cb()
        if i ~= 1 then
          if task:has_symbol(dep_name) then
            task:insert_result(name, 1.0)
          end
        else
          task:insert_result(name, 1.0)
        end
      end
      if task:has_symbol('TEST_PRE') then
        local r = task:get_resolver()
        r:resolve_a({task = task, name = 'example.com', callback = dns_cb})
      end
    end
  })

  if i ~= 1 then
    rspamd_config:register_dependency(name, dep_name)
  end

  rspamd_config:set_metric_symbol({
    name = name,
    score = 1.0
  })
end


rspamd_config:register_symbol({
  type = 'postfilter',
  name = 'TEST_POST',
  callback = function(task)
    for i = 1,10 do
      local name = string.format('DEP_TEST%d', i)
      if not task:has_symbol(name) then
        return
      end
    end
    if task:has_symbol('TEST_PRE') then
      task:insert_result('TEST_POST', 1.0)
    end
  end
})
rspamd_config:set_metric_symbol({
  name = 'TEST_POST',
  score = 1.0
})

rspamd_config:register_symbol({
  type = 'prefilter',
  name = 'TEST_PRE',
  callback = function(task)
    task:insert_result('TEST_PRE', 1.0)
  end
})
rspamd_config:set_metric_symbol({
  name = 'TEST_PRE',
  score = 1.0
})