]> source.dussan.org Git - rspamd.git/commitdiff
Support emails dnsbl
authorAndrew Lewis <nerf@judo.za.org>
Tue, 17 Feb 2015 10:47:17 +0000 (12:47 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Tue, 17 Feb 2015 10:47:17 +0000 (12:47 +0200)
conf/modules.conf
src/plugins/lua/rbl.lua

index 1a4185c9729d2bb82564a9b196947e3a9467a78b..1fd71f2ed6cf6fd213376700ce3abac7fdaa62e5 100644 (file)
@@ -201,6 +201,16 @@ rbl {
         }
     }
 
+    rambleremails {
+        symbol = RAMBLER_EMAILBL;
+        rbl = email-bl.rambler.ru;
+        from = false;
+        emails = true;
+        exclude_users = false;
+        exclude_private_ips = false;
+        exclude_local = false;
+    }
+
  }
 }
 
@@ -222,13 +232,8 @@ once_received {
 phishing {
     symbol = "PHISHING";
 }
-emails {
-    rule { 
-        symbol = RAMBLER_EMAILBL;
-        dnsbl = email-bl.rambler.ru;
-        domain_only = false;
-    }
-}
+#emails {
+#}
 spf {
     spf_cache_size = 2k;
     spf_cache_expire = 1d;
index 625333f016889b6ddf16aff6e8eeefce718bb525..852fe1f04318568248d001d7bc8df2729e6abf7e 100644 (file)
@@ -165,6 +165,51 @@ local function rbl_cb (task)
        end)()
       end
 
+      if rbl['emails'] then
+        (function()
+          if notgot['emails'] then
+            return
+          end
+          if not havegot['emails'] then
+            havegot['emails'] = task:get_emails()
+            if havegot['emails'] == nil then
+              notgot['emails'] = true
+              return
+            end
+            local cleanList = {}
+            for _, e in pairs(havegot['emails']) do
+              local localpart = e:get_user()
+              local domainpart = e:get_host()
+              if rbl['emails'] == 'domain_only' then
+                if not cleanList[domainpart] and validate_dns(domainpart) then
+                  cleanList[domainpart] = true
+                end
+              else
+                if validate_dns(localpart) and validate_dns(domainpart) then
+                  table.insert(cleanList, localpart .. '.' .. domainpart)
+                end
+              end 
+            end
+            havegot['emails'] = cleanList
+            if not next(havegot['emails']) then
+              notgot['emails'] = true
+              return
+            end
+          end
+          if rbl['emails'] == 'domain_only' then
+            for domain, _ in pairs(havegot['emails']) do
+              task:get_resolver():resolve_a(task:get_session(), task:get_mempool(),
+                domain .. '.' .. rbl['rbl'], rbl_dns_cb, k)
+            end
+          else
+            for _, email in pairs(havegot['emails']) do
+              task:get_resolver():resolve_a(task:get_session(), task:get_mempool(),
+                email .. '.' .. rbl['rbl'], rbl_dns_cb, k)
+            end
+          end
+        end)()
+      end
+
       if rbl['rdns'] then
        (function()
          if notgot['rdns'] then
@@ -248,6 +293,7 @@ if type(rspamd_config.get_api_version) ~= 'nil' then
     rspamd_config:register_module_option('rbl', 'local_exclude_ip_map', 'string')
     rspamd_config:register_module_option('rbl', 'default_exclude_local', 'string')
     rspamd_config:register_module_option('rbl', 'private_ips', 'string')
+    rspamd_config:register_module_option('rbl', 'default_emails', 'string')
   end
 end
 
@@ -286,6 +332,9 @@ end
 if(opts['default_exclude_local'] == nil) then
   opts['default_exclude_local'] = true
 end
+if(opts['default_emails'] == nil) then
+  opts['default_emails'] = false
+end
 if(opts['local_exclude_ip_map'] ~= nil) then
   local_exclusions = rspamd_config:add_radix_map(opts['local_exclude_ip_map'])
 end
@@ -296,7 +345,7 @@ end
 for key,rbl in pairs(opts['rbls']) do
   local o = {
     "ipv4", "ipv6", "from", "received", "unknown", "rdns", "helo", "exclude_users",
-    "exclude_private_ips", "exclude_local"
+    "exclude_private_ips", "exclude_local", "emails"
   }
   for i=1,table.maxn(o) do
     if(rbl[o[i]] == nil) then