diff options
author | Andrew Lewis <nerf@judo.za.org> | 2017-02-08 15:34:21 +0200 |
---|---|---|
committer | Andrew Lewis <nerf@judo.za.org> | 2017-02-08 16:36:33 +0200 |
commit | 0b69b0452e370f33b678bf87fc041ae5e2f86cc8 (patch) | |
tree | a14bb920bee27c8c44443cfb2093a57c85c19755 | |
parent | 2f5cc0b94fb8957d9e01390326a06f5bbda15d9a (diff) | |
download | rspamd-0b69b0452e370f33b678bf87fc041ae5e2f86cc8.tar.gz rspamd-0b69b0452e370f33b678bf87fc041ae5e2f86cc8.zip |
[Minor] Multimap Received headers: fixes
- Deal with gaps in Received headers indexes
- Deal with rspamd_ip values
- Fix min_pos/max_pos
-rw-r--r-- | src/plugins/lua/multimap.lua | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/plugins/lua/multimap.lua b/src/plugins/lua/multimap.lua index dd474d0c8..a5152a458 100644 --- a/src/plugins/lua/multimap.lua +++ b/src/plugins/lua/multimap.lua @@ -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 |