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