rspamd.local.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. local wants_subfolder_tag = task:get_symbol("RCPT_WANTS_SUBFOLDER_TAG")
  29. if wants_subject_tag then
  30. rspamd_logger.infox("user wants subject modified for tagged mail")
  31. local sbj = task:get_header('Subject')
  32. new_sbj = '=?UTF-8?B?' .. tostring(util.encode_base64('[' .. tag .. '] ' .. sbj)) .. '?='
  33. task:set_milter_reply({
  34. remove_headers = {['Subject'] = 1},
  35. add_headers = {['Subject'] = new_sbj}
  36. })
  37. elseif wants_subfolder_tag then
  38. rspamd_logger.infox("Add X-Moo-Tag header")
  39. task:set_milter_reply({
  40. add_headers = {['X-Moo-Tag'] = 'YES'}
  41. })
  42. end
  43. end
  44. end,
  45. priority = 11
  46. })
  47. rspamd_config:register_symbol({
  48. name = 'DYN_RL_CHECK',
  49. type = 'prefilter',
  50. callback = function(task)
  51. local util = require("rspamd_util")
  52. local redis_params = rspamd_parse_redis_server('dyn_rl')
  53. local rspamd_logger = require "rspamd_logger"
  54. local envfrom = task:get_from(1)
  55. local uname = task:get_user()
  56. if not envfrom or not uname then
  57. return false
  58. end
  59. local uname = uname:lower()
  60. local env_from_domain = envfrom[1].domain:lower() -- get smtp from domain in lower case
  61. local function redis_cb_user(err, data)
  62. if err or type(data) ~= 'string' then
  63. 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...", uname, data, err)
  64. local function redis_key_cb_domain(err, data)
  65. if err or type(data) ~= 'string' then
  66. 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)
  67. else
  68. rspamd_logger.infox(rspamd_config, "found dynamic ratelimit in redis for domain %s with value %s", env_from_domain, data)
  69. task:insert_result('DYN_RL', 0.0, data)
  70. end
  71. end
  72. local redis_ret_domain = rspamd_redis_make_request(task,
  73. redis_params, -- connect params
  74. env_from_domain, -- hash key
  75. false, -- is write
  76. redis_key_cb_domain, --callback
  77. 'HGET', -- command
  78. {'RL_VALUE', env_from_domain} -- arguments
  79. )
  80. if not redis_ret_domain then
  81. rspamd_logger.infox(rspamd_config, "cannot make request to load ratelimit for domain")
  82. end
  83. else
  84. rspamd_logger.infox(rspamd_config, "found dynamic ratelimit in redis for user %s with value %s", uname, data)
  85. task:insert_result('DYN_RL', 0.0, data)
  86. end
  87. end
  88. local redis_ret_user = rspamd_redis_make_request(task,
  89. redis_params, -- connect params
  90. uname, -- hash key
  91. false, -- is write
  92. redis_cb_user, --callback
  93. 'HGET', -- command
  94. {'RL_VALUE', uname} -- arguments
  95. )
  96. if not redis_ret_user then
  97. rspamd_logger.infox(rspamd_config, "cannot make request to load ratelimit for user")
  98. end
  99. return true
  100. end,
  101. priority = 20
  102. })
  103. rspamd_config:register_symbol({
  104. name = 'NO_LOG_STAT',
  105. type = 'postfilter',
  106. callback = function(task)
  107. local from = task:get_header('From')
  108. if from and (string.find(from, 'monitoring-system@everycloudtech.us', 1, true) or from == 'watchdog@localhost') then
  109. task:set_flag('no_log')
  110. task:set_flag('no_stat')
  111. end
  112. end
  113. })