rspamd.local.lua 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. rspamd_config:register_symbol({
  10. name = 'TAG_MOO',
  11. type = 'postfilter',
  12. callback = function(task)
  13. local util = require("rspamd_util")
  14. local rspamd_logger = require "rspamd_logger"
  15. local tagged_rcpt = task:get_symbol("TAGGED_RCPT")
  16. local mailcow_domain = task:get_symbol("RCPT_MAILCOW_DOMAIN")
  17. if tagged_rcpt and mailcow_domain then
  18. local tag = tagged_rcpt[1].options[1]
  19. rspamd_logger.infox("found tag: %s", tag)
  20. local action = task:get_metric_action('default')
  21. rspamd_logger.infox("metric action now: %s", action)
  22. if action ~= 'no action' and action ~= 'greylist' then
  23. rspamd_logger.infox("skipping tag handler for action: %s", action)
  24. task:set_metric_action('default', action)
  25. return true
  26. end
  27. local wants_subject_tag = task:get_symbol("RCPT_WANTS_SUBJECT_TAG")
  28. if wants_subject_tag then
  29. rspamd_logger.infox("user wants subject modified for tagged mail")
  30. local sbj = task:get_header('Subject')
  31. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  32. task:set_milter_reply({
  33. remove_headers = {['Subject'] = 1},
  34. add_headers = {['Subject'] = new_sbj}
  35. })
  36. else
  37. rspamd_logger.infox("Add X-Moo-Tag header")
  38. task:set_milter_reply({
  39. add_headers = {['X-Moo-Tag'] = 'YES'}
  40. })
  41. end
  42. end
  43. end,
  44. priority = 11
  45. })