You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

url_tags.lua 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. local rspamd_logger = require 'rspamd_logger'
  2. rspamd_config:register_symbol({
  3. name = 'ADDED_TAGS',
  4. score = 1.0,
  5. callback = function(task)
  6. if not task:get_request_header('addtags') then
  7. return true, 'nope! not requested'
  8. end
  9. local urls = task:get_urls()
  10. if not (urls and urls[1]) then
  11. return true, 'nope! found no urls'
  12. end
  13. local mpool = task:get_mempool()
  14. for _, u in ipairs(urls) do
  15. u:add_tag('test1', 'meta1', mpool)
  16. u:add_tag('test1', 'meta2', mpool)
  17. u:add_tag('test2', 'http://www.example.com', mpool)
  18. end
  19. return true, 'no worry'
  20. end
  21. })
  22. rspamd_config:register_symbol({
  23. name = 'FOUND_TAGS',
  24. score = 1.0,
  25. callback = function(task)
  26. local urls = task:get_urls()
  27. if not (urls and urls[1]) then
  28. return true, 'nope! found no urls'
  29. end
  30. for _, u in ipairs(urls) do
  31. local tags = u:get_tags()
  32. rspamd_logger.debugx(task, 'tags: %1', tags)
  33. if not tags['test1'] then
  34. return true, 'no key - test1'
  35. end
  36. local found1, found2 = false, false
  37. for _, e in ipairs(tags['test1']) do
  38. if e == 'meta1' then found1 = true end
  39. if e == 'meta2' then found2 = true end
  40. end
  41. if not (found1 and found2) then
  42. return true, 'missing metatags in test1'
  43. end
  44. if not tags['test2'] then
  45. return true, 'no key - test2'
  46. end
  47. if not tags['test2'][1] == 'http://www.example.com' then
  48. return true, 'wrong value in test2 metatag: ' .. tags['test2'][1]
  49. end
  50. end
  51. return true, 'no worry'
  52. end
  53. })