By default the contents of the X-Synology-Spam-Status header are unsorted. Making it difficult to understand why a certain mail is flagged as spam or ham. Here is a tweak to sort the header by score.
Situation
Normally you can instruct rspamd to order the symbols by their score using the sort_scores
setting. So the highest scoring symbols are listed first, then going down to the negative scores at the end. But because of how Synology is generating the header, the sort_scores
setting has no effect. They are appended to the status massage by iteration.
By adding one line of code to the generator the list will be sorted without interfering with the rest of the processing. The trick is to add a table.sort
statement to the synology.lua
script, just before the symbols are processed.
How to fix
First make sure nano is installed. It is available in the Package Center in the SynoCli File Tools package, when you add the SynoCommunity repository. Or replace the nano
mentions with your favorite editor.
Open the SSH terminal with an admin user account.
Edit the synology.lua
file:
sudo nano '/volume1/@appstore/MailPlus-Server/etc/rspamd/synology.lua'
Now find the header generator.
Hit CTRL W and copy-paste this line, then enter key:
spam_status = spam_status .. ', ' .. symbol
Move the cursor 3 lines up so it is above the for
statement. Create some blank new lines to make room for the tweak:
-- Sort the spam status header by score
table.sort(symbols, function(a, b) return a.score > b.score end)
Should look like this

Save and close the file with CTRL X, hit Y [enter]. Finally exit the terminal with exit
[enter].
Notes
This is only tested on DSM 7.2.x
Updating the MailPlus Server package will very likely remove this change. You have to reapply the patch after an update and the paths and code location may have changed.
Bookmark this post for later in case this happens.
Leave a Reply