end
end
end
+ -- Off-by one: match returns 0 based positions while we use 1 based in Lua
+ for _,m in ipairs(matches_flattened) do
+ m[1][1] = m[1][1] - 1
+ m[1][2] = m[1][2] - 1
+ end
+
-- Now flattened match table is sorted by start pos and has the maximum overlapped pattern
+ -- Matches with the same start and end are covering the same replacement
+ -- e.g. we had something like [1 .. 2] -> replacement 1 and [1 .. 4] -> replacement 2
+ -- after flattening we should have [1 .. 4] -> 2 and [1 .. 4] -> 2
+ -- we can safely ignore those duplicates in the following code
local cur_start = 1
local fragments = {}
cur_start = m[1][2] + 1 -- end of match
end
end
+
-- last part
if cur_start < #content then
fragments[#fragments + 1] = content:span(cur_start)
-- Final stuff
out[#out + 1] = {encode_func(rspamd_text.fromtable(fragments)), false}
- out[#out + 1] = {'', true}
else
-- No matches
out[#out + 1] = {part:get_raw_headers(), true}