I have been doing a bit of digging in the lua.. One of them in particular looks like it could be breaking MIME formatting. Your thoughts on this would be helpfull.
1. Make the fallback MIME boundary unique (lines 184-185)
`- boundaries[#boundaries + 1] = boundary or '--XXX' -- line 184
+ boundaries[#boundaries + 1] = boundary or '--' .. rspamd_util.random_hex(8) -- line 184`
Using a hardcoded boundary like –XXX isn’t safe. Swapping in a random hex suffix keeps things unique and avoids accidental collisions.
2. Likely Bug: Incorrect string.sub when checking footer (lines 198-199)
- if content:sub(-(nlen), nlen + 1) == ending then -- line 198
+ if content:sub(-nlen) == ending then -- line 198
The original mixed a negative and positive index in string.sub, which doesn’t work properly. Fixing this should ensure the footer presence check works correctly and doesn’t break MIME structure.
3. Cleaner fallback for missing content (lines 205-208)
- local content = tp:get_content() -- line 205
- if not content then -- line 206
- content = rspamd_text.fromstring('') -- lines 207-208
- end
+ local content = rspamd_text.fromstring(tp:get_content() or '') -- line 205
Simplifies fallback to always get a rspamd_text object, even if content is empty.
4. Fix broken regex for IPv4 redaction (lines 247-248)
- ret = ret:gsub('[%d+%.%d+%.%d+%.%d+]', 'XXX.XXX.XXX.XXX') -- line 247
+ ret = ret:gsub('%d+%.%d+%.%d+%.%d+', 'XXX.XXX.XXX.XXX') -- line 247
Square brackets were turning the pattern into a char class; fixing it to a proper pattern matches IP addresses.
5. Optional tweak: make the HTML threshold configurable (lines 270-271)
- if part:is_html() and part:get_words_count() >= 10 then -- line 270
+ local html_min_words = 10 -- new line before 270
+ if part:is_html() and part:get_words_count() >= html_min_words then -- line 270
No functional change, just makes the word-count threshold easier to adjust.
Of all the bugs I could see from above #2 looks like the little blighter that could be braking MIME when domain footers are added, which could also cause attachments to be dropped as it seems to be messing around with the multipart structure.
Your thoughts on this would be great.