]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Multimap Received headers: fixes 1406/head
authorAndrew Lewis <nerf@judo.za.org>
Wed, 8 Feb 2017 13:34:21 +0000 (15:34 +0200)
committerAndrew Lewis <nerf@judo.za.org>
Wed, 8 Feb 2017 14:36:33 +0000 (16:36 +0200)
 - Deal with gaps in Received headers indexes
 - Deal with rspamd_ip values
 - Fix min_pos/max_pos

src/plugins/lua/multimap.lua

index dd474d0c80c66046b393d031e21710dae949d99e..a5152a458d0250e7829237d6984586639b2ad8de 100644 (file)
@@ -543,28 +543,34 @@ local function multimap_callback(task, rule)
       local max_pos = tonumber(r['max_pos'])
       if min_pos then
         if min_pos < 0 then
-          if (pos - (min_pos*-1)) < pos then
-            return
-          end
-        else
-          if pos < min_pos then
-            return
+          if min_pos == -1 then
+            if (pos ~= total) then
+              return
+            end
+          else
+            if pos <= (total - (min_pos*-1)) then
+              return
+            end
           end
+        elseif pos < min_pos then
+          return
         end
       end
       if max_pos then
-        if max_pos < 0 then
-          if (pos - (max_pos*-1)) > pos then
+        if max_pos < -1 then
+          if (total - (max_pos*-1)) >= pos then
             return
           end
-        else
+        elseif max_pos > 0 then
           if pos > max_pos then
             return
           end
         end
       end
       if filter == 'real_ip' or filter == 'from_ip' then
-        v = rspamd_ip.from_string(v)
+        if type(v) == 'string' then
+          v = rspamd_ip.from_string(v)
+        end
         if v and v:is_valid() then
           match_rule(r, v)
         end
@@ -706,7 +712,12 @@ local function multimap_callback(task, rule)
     received = function()
       local hdrs = task:get_received_headers()
       if hdrs and hdrs[1] then
-        local num_hdrs = #hdrs
+        local num_hdrs = 0
+        for i in ipairs(hdrs) do
+          if i > num_hdrs then
+            num_hdrs = i
+          end
+        end
         for pos, h in ipairs(hdrs) do
           match_received_header(rule, pos, num_hdrs, h)
         end