Rule2XSBody

Sa-compile must be run in advance, in order to compile the ruleset using re2c and the C compiler.

This plugin will use native-code object files representing the ruleset, in order to provide significant speedups in rule evaluation.

Install the required packages

// RHEL / Centos (re2c is in the EPEL repo)
yum install gcc re2c make

// Debian / Ubuntu
apt-get install gcc re2c make

Edit the Plesk spamassassin rules update cron file /etc/cron.daily/60sa-update and add the text /usr/bin/sa-compile --quiet && to line 10.

#!/bin/bash
### Copyright 1999-2016. Parallels IP Holdings GmbH. All Rights Reserved.

sa_update()
{
        /usr/bin/sa-update
        local rc="$?"
        case $rc in
                # Only restart spamd if sa-update returns 0, meaning it updated the rules
                0) /usr/bin/sa-compile --quiet && env PATH=/opt/psa/admin/sbin:/usr/local/psa/admin/sbin:$PATH spammng --condrestart ;;
                # If sa-update returns 1 then there are no updates
                1) exit 0 ;;
        esac
        return $rc
}

sa_update >> /var/log/sa-update.log 2>&1

Edit the file /etc/mail/spamassassin/v320.pre and remove the comment to enable the Rule2XSBody plugin

# Rule2XSBody - speedup by compilation of ruleset to native code
#
loadplugin Mail::SpamAssassin::Plugin::Rule2XSBody  

You can test to see if the rules compile sucessfully by running the command:

/usr/bin/sa-compile

You should see it compile the rules and copy them to your spamassassin compiled rules directory.

SELinux Problems

With Rule2XSBody enabled when restarting Spamassassin you might see this if SELinux is enabled:

Oct 29 10:28:25 web spamd[19433]: logger: removing stderr method
Oct 29 10:28:27 web spamd[19477]: Can't load '/var/lib/spamassassin/compiled/5.016/3.004002/auto/Mail/SpamAssassin/CompiledRegexps/body_0/body_0.so' for module Mail::SpamAssassin::CompiledRegexps::body_0: /var/lib/spamassassin/compiled/5.016/3.004002/auto/Mail/SpamAssassin/CompiledRegexps/body_0/body_0.so: failed to map segment from shared object: Permission denied at /usr/share/perl5/XSLoader.pm line 68.
Oct 29 10:28:27 web spamd[19477]: at /var/lib/spamassassin/compiled/5.016/3.004002/Mail/SpamAssassin/CompiledRegexps/body_0.pm line 364.
Oct 29 10:28:27 web spamd[19477]: Can't load '/var/lib/spamassassin/compiled/5.016/3.004002/auto/Mail/SpamAssassin/CompiledRegexps/body_0/body_0.so' for module Mail::SpamAssassin::CompiledRegexps::body_0: /var/lib/spamassassin/compiled/5.016/3.004002/auto/Mail/SpamAssassin/CompiledRegexps/body_0/body_0.so: failed to map segment from shared object: Permission denied at /usr/share/perl5/XSLoader.pm line 68.
Oct 29 10:28:27 web spamd[19477]: at /var/lib/spamassassin/compiled/5.016/3.004002/Mail/SpamAssassin/CompiledRegexps/body_0.pm line 364.
Oct 29 10:28:27 web spamd[19477]: BEGIN failed--compilation aborted at /var/lib/spamassassin/compiled/5.016/3.004002/Mail/SpamAssassin/CompiledRegexps/body_0.pm line 365.
Oct 29 10:28:27 web spamd[19477]: Compilation failed in require at (eval 1591) line 1.

The fix is to re-apply the SELinux labels on the /var/lib/spamassassin/compiled/ directory:

restorecon -R -v "/var/lib/spamassassin/compiled/"