rspamd.local.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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.MAILCOW_MOO = function (task)
  10. return true
  11. end
  12. local modify_subject_map = rspamd_config:add_map({
  13. url = 'http://nginx:8081/tags.php',
  14. type = 'map',
  15. description = 'Map of users to use subject tags for'
  16. })
  17. local auth_domain_map = rspamd_config:add_map({
  18. url = 'http://nginx:8081/authoritative.php',
  19. type = 'map',
  20. description = 'Map of domains we are authoritative for'
  21. })
  22. rspamd_config.ADD_DELIMITER_TAG = {
  23. callback = function(task)
  24. local util = require("rspamd_util")
  25. local rspamd_logger = require "rspamd_logger"
  26. local user_env_tagged = task:get_recipients(1)[1]['user']
  27. local user_to_tagged = task:get_recipients(2)[1]['user']
  28. local domain = task:get_recipients(1)[1]['domain']
  29. local user_env, tag_env = user_env_tagged:match("([^+]+)+(.*)")
  30. local user_to, tag_to = user_to_tagged:match("([^+]+)+(.*)")
  31. local authdomain = auth_domain_map:get_key(domain)
  32. if tag_env then
  33. tag = tag_env
  34. user = user_env
  35. elseif tag_to then
  36. tag = tag_to
  37. user = user_env
  38. end
  39. if tag and authdomain then
  40. rspamd_logger.infox("Domain %s is part of mailcow, start reading tag settings", domain)
  41. local user_untagged = user .. '@' .. domain
  42. rspamd_logger.infox("Querying tag settings for user %1", user_untagged)
  43. if modify_subject_map:get_key(user_untagged) then
  44. rspamd_logger.infox("User wants subject modified for tagged mail")
  45. local sbj = task:get_header('Subject')
  46. if tag then
  47. rspamd_logger.infox("Found tag %1, will modify subject header", tag)
  48. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  49. task:set_rmilter_reply({
  50. remove_headers = {['Subject'] = 1},
  51. add_headers = {['Subject'] = new_sbj}
  52. })
  53. end
  54. else
  55. rspamd_logger.infox("Add X-Moo-Tag header")
  56. task:set_rmilter_reply({
  57. add_headers = {['X-Moo-Tag'] = 'YES'}
  58. })
  59. end
  60. else
  61. rspamd_logger.infox("Skip delimiter handling for untagged message or authenticated user")
  62. end
  63. return false
  64. end
  65. }