rspamd.local.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. rspamd_config.MAILCOW_AUTH = {
  2. callback = function(task)
  3. local uname = task:get_user()
  4. if uname then
  5. return 1
  6. end
  7. end
  8. }
  9. local redis_params
  10. redis_params = rspamd_parse_redis_server('tag_settings')
  11. if redis_params then
  12. rspamd_config:register_symbol({
  13. name = 'TAG_MOO',
  14. type = 'postfilter',
  15. callback = function(task)
  16. local util = require("rspamd_util")
  17. local rspamd_logger = require "rspamd_logger"
  18. local tagged_rcpt = task:get_symbol("TAGGED_RCPT")
  19. local mailcow_domain = task:get_symbol("RCPT_MAILCOW_DOMAIN")
  20. local user = task:get_recipients(0)[1]['user']
  21. local domain = task:get_recipients(0)[1]['domain']
  22. local rcpt = user .. '@' .. domain
  23. if tagged_rcpt and mailcow_domain then
  24. local tag = tagged_rcpt[1].options[1]
  25. rspamd_logger.infox("found tag: %s", tag)
  26. local action = task:get_metric_action('default')
  27. rspamd_logger.infox("metric action now: %s", action)
  28. if action ~= 'no action' and action ~= 'greylist' then
  29. rspamd_logger.infox("skipping tag handler for action: %s", action)
  30. task:set_metric_action('default', action)
  31. return true
  32. end
  33. local wants_subject_tag = task:get_symbol("RCPT_WANTS_SUBJECT_TAG")
  34. if wants_subject_tag then
  35. rspamd_logger.infox("user wants subject modified for tagged mail")
  36. local sbj = task:get_header('Subject')
  37. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  38. task:set_milter_reply({
  39. remove_headers = {['Subject'] = 1},
  40. add_headers = {['Subject'] = new_sbj}
  41. })
  42. else
  43. rspamd_logger.infox("Add X-Moo-Tag header")
  44. task:set_milter_reply({
  45. add_headers = {['X-Moo-Tag'] = 'YES'}
  46. })
  47. end
  48. end
  49. end,
  50. priority = 11
  51. })
  52. end