2
0

rspamd.local.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 tagged_rcpt[1].options 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. })
  46. rspamd_config:register_symbol({
  47. name = 'DYN_RL_CHECK',
  48. type = 'prefilter',
  49. callback = function(task)
  50. local util = require("rspamd_util")
  51. local redis_params = rspamd_parse_redis_server('dyn_rl')
  52. local rspamd_logger = require "rspamd_logger"
  53. local envfrom = task:get_from(1)
  54. if not envfrom then
  55. return false
  56. end
  57. local env_from_domain = envfrom[1].domain:lower() -- get smtp from domain in lower case
  58. local env_from_addr = envfrom[1].addr:lower() -- get smtp from addr in lower case
  59. local function redis_cb_user(err, data)
  60. if err or type(data) ~= 'string' then
  61. rspamd_logger.infox(rspamd_config, "dynamic ratelimit request for user %s returned invalid or empty data (\"%s\") or error (\"%s\") - trying dynamic ratelimit for domain...", env_from_addr, data, err)
  62. local function redis_key_cb_domain(err, data)
  63. if err or type(data) ~= 'string' then
  64. rspamd_logger.infox(rspamd_config, "dynamic ratelimit request for domain %s returned invalid or empty data (\"%s\") or error (\"%s\")", env_from_domain, data, err)
  65. else
  66. rspamd_logger.infox(rspamd_config, "found dynamic ratelimit in redis for domain %s with value %s", env_from_domain, data)
  67. task:insert_result('DYN_RL', 0.0, data)
  68. end
  69. end
  70. local redis_ret_domain = rspamd_redis_make_request(task,
  71. redis_params, -- connect params
  72. env_from_domain, -- hash key
  73. false, -- is write
  74. redis_key_cb_domain, --callback
  75. 'HGET', -- command
  76. {'RL_VALUE', env_from_domain} -- arguments
  77. )
  78. if not redis_ret_domain then
  79. rspamd_logger.infox(rspamd_config, "cannot make request to load ratelimit for domain")
  80. end
  81. else
  82. rspamd_logger.infox(rspamd_config, "found dynamic ratelimit in redis for user %s with value %s", env_from_addr, data)
  83. task:insert_result('DYN_RL', 0.0, data)
  84. end
  85. end
  86. local redis_ret_user = rspamd_redis_make_request(task,
  87. redis_params, -- connect params
  88. env_from_addr, -- hash key
  89. false, -- is write
  90. redis_cb_user, --callback
  91. 'HGET', -- command
  92. {'RL_VALUE', env_from_addr} -- arguments
  93. )
  94. if not redis_ret_user then
  95. rspamd_logger.infox(rspamd_config, "cannot make request to load ratelimit for user")
  96. end
  97. return true
  98. end,
  99. priority = 20
  100. })
  101. rspamd_config:register_symbol({
  102. name = 'NO_LOG_STAT',
  103. type = 'postfilter',
  104. callback = function(task)
  105. local from = task:get_header('From')
  106. if from and (from == 'monitoring-system@everycloudtech.us' or from == 'watchdog@localhost') then
  107. task:set_flag('no_log')
  108. task:set_flag('no_stat')
  109. end
  110. end
  111. })