]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix domain_only emails RBL
authorAndrew Lewis <nerf@judo.za.org>
Thu, 6 Apr 2017 17:44:47 +0000 (19:44 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Thu, 6 Apr 2017 17:46:20 +0000 (19:46 +0200)
 - Also support hashing for domain_only

src/plugins/lua/rbl.lua

index edc55c9982d1342e9df182c370c62280bb5fb663..9f30760b66c05e6190792416dec2d85e64d1c1fb 100644 (file)
@@ -241,30 +241,6 @@ local function rbl_cb (task)
           notgot['emails'] = true
           return false
         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 rbl['hash'] then
-              table.insert(cleanList, make_hash(tostring(e), rbl['hash']))
-            else
-              if validate_dns(localpart) and validate_dns(domainpart) then
-                table.insert(cleanList, localpart .. '.' .. domainpart)
-              end
-            end
-          end
-        end
-        havegot['emails'] = cleanList
-        if not next(havegot['emails']) then
-          notgot['emails'] = true
-          return false
-        end
       end
     elseif rbl['from'] then
       if notgot['from'] then
@@ -333,13 +309,30 @@ local function rbl_cb (task)
   -- Emails RBLs
   fun.each(function(_, rbl)
     if rbl['emails'] == 'domain_only' then
-      for domain, _ in pairs(havegot['emails']) do
-        local to_resolve = domain .. '.' .. rbl['rbl']
+      local cleanList = {}
+      for _, email in ipairs(havegot['emails']) do
+        cleanList[email:get_host()] = true
+      end
+      for k in pairs(cleanList) do
+        local to_resolve
+        if rbl['hash'] then
+          to_resolve = make_hash(tostring(k), rbl['hash']) .. '.' .. rbl['rbl']
+        else
+          to_resolve = k .. '.' .. rbl['rbl']
+        end
         gen_rbl_rule(to_resolve, rbl)
       end
     else
-      for _, email in pairs(havegot['emails']) do
-        local to_resolve = email .. '.' .. rbl['rbl']
+      for _, email in ipairs(havegot['emails']) do
+        local to_resolve
+        if rbl['hash'] then
+          to_resolve = make_hash(tostring(email), rbl['hash']) .. '.' .. rbl['rbl']
+        else
+          local upart = email:get_user()
+          if validate_dns(upart) then
+            to_resolve = upart .. '.' .. email:get_host() .. '.' .. rbl['rbl']
+          end
+        end
         gen_rbl_rule(to_resolve, rbl)
       end
     end