ivm-sg.lua 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. -- Thanks to https://raw.githubusercontent.com/fatalbanana
  2. local lua_maps = require 'lua_maps'
  3. local rspamd_regexp = require 'rspamd_regexp'
  4. local rspamd_util = require 'rspamd_util'
  5. local ivm_sendgrid_ids = lua_maps.map_add_from_ucl(
  6. 'https://www.invaluement.com/spdata/sendgrid-id-dnsbl.txt',
  7. 'set',
  8. 'Invaluement Service Provider DNSBL: Sendgrid IDs'
  9. )
  10. local ivm_sendgrid_envfromdomains = lua_maps.map_add_from_ucl(
  11. 'https://www.invaluement.com/spdata/sendgrid-envelopefromdomain-dnsbl.txt',
  12. 'set',
  13. 'Invaluement Service Provider DNSBL: Sendgrid envelope domains'
  14. )
  15. local cb_id = rspamd_config:register_symbol({
  16. name = 'IVM_SENDGRID',
  17. callback = function(task)
  18. -- Is it Sendgrid?
  19. local sg_hdr = task:get_header('X-SG-EID')
  20. if not sg_hdr then return end
  21. -- Get original envelope from
  22. local env_from = task:get_from{'smtp', 'orig'}
  23. if not env_from then return end
  24. -- Check normalised domain in domains list
  25. if ivm_sendgrid_envfromdomains and ivm_sendgrid_envfromdomains:get_key(rspamd_util.get_tld(env_from[1].domain)) then
  26. task:insert_result('IVM_SENDGRID_DOMAIN', 1.0)
  27. end
  28. -- Check ID in ID list
  29. local lp_re = rspamd_regexp.create_cached([[^bounces\+(\d+)-]])
  30. local res = lp_re:search(env_from[1].user, true, true)
  31. if not res then return end
  32. if ivm_sendgrid_ids and ivm_sendgrid_ids:get_key(res[1][2]) then
  33. task:insert_result('IVM_SENDGRID_ID', 1.0)
  34. end
  35. end,
  36. description = 'Invaluement Service Provider DNSBL: Sendgrid',
  37. type = 'callback',
  38. })
  39. rspamd_config:register_symbol({
  40. name = 'IVM_SENDGRID_DOMAIN',
  41. parent = cb_id,
  42. group = 'ivmspdnsbl',
  43. score = 8.0,
  44. type = 'virtual',
  45. })
  46. rspamd_config:register_symbol({
  47. name = 'IVM_SENDGRID_ID',
  48. parent = cb_id,
  49. group = 'ivmspdnsbl',
  50. score = 8.0,
  51. type = 'virtual',
  52. })