Migrating spamassassin to version 4.0

December 27, 2023 Roberto Puzzanghera 0 comments

Install spamassassin v. 4

SA v.4 DMARC plugin requires Mail::DMARC::PurePerl, while DecodeShortURLs requires DBD::SQLite ( or DBD::MariaDB or DBD::mysql), so it's better to install them before the upgrade:

perl -MCPAN -e shell
cpan> force notest install Mail::DMARC::PurePerl DBD::SQLite
cpan> quit

Stop qmail and spamd and then upgrade spamassassin, run sa-update and restart the services: 

qmailctl stop
spamdctl stop

perl -MCPAN -e shell
cpan> force notest install Mail::SpamAssassin Mail::SpamAssassin::Plugin::Razor2
cpan> quit

sa-update
spamdctl start
qmailctl start

Load the new plugins

Load all plugins commented out in /etc/mail/spamassassin/v400.pre. Then add your config to your local.cf. This is for ExtractText

###################### extracttext 
ifplugin Mail::SpamAssassin::Plugin::ExtractText 
extracttext_use       pdftotext  .pdf application/pdf 
extracttext_use       docx2txt   .docx application/docx 
extracttext_use       antiword   .doc application/(?:vnd\.?)?ms-?word.* 
extracttext_use       unrtf      .doc .rtf application/rtf text/rtf 
extracttext_use       odt2txt    .odt .ott application/.*?opendocument.*text 
extracttext_use       odt2txt    .sdw .stw application/(?:x-)?soffice application/(?:x-)?starwriter 
extracttext_use       tesseract  .jpg .png .bmp .tif .tiff image/(?:jpeg|png|x-ms-bmp|tiff)

add_header   all          ExtractText-Flags _EXTRACTTEXTFLAGS_ 
header       PDF_NO_TEXT  X-ExtractText-Flags =~ /\bpdftotext_NoText\b/ 
describe     PDF_NO_TEXT  PDF without text 
score        PDF_NO_TEXT  0.001zzz

header       DOC_NO_TEXT  X-ExtractText-Flags =~ /\b(?:antiword|openxml|unrtf|odt2txt)_NoText\b/ 
describe     DOC_NO_TEXT  Document without text 
score        DOC_NO_TEXT  0.001

header       EXTRACTTEXT  exists:X-ExtractText-Flags 
describe     EXTRACTTEXT  Email processed by extracttext plugin 
score        EXTRACTTEXT  0.001 
endif

Update the RC's sauserprefs plugin

Update your johndoh/roundcube-sauserprefs plugin by downloading it from github, as the v. 1.20.1 version is not yet available as a composer installable plugin.

cd /var/www/roundcube/htdocs/plugins
wget https://github.com/johndoh/roundcube-sauserprefs/archive/refs/tags/1.20.1.tar.gz
tar xzf 1.20.1.tar.gz
mv roundcube-sauserprefs-1.20.1/ sauserprefs
mv config.inc.php.dist config.inc.php

setup MySQL login. Then turn this flag to true to gain spamassassin v.4 compatibility:

$config['sauserprefs_sav4'] = true;

All rules, functions, command line options and modules that contain "whitelist" or "blacklist" have been renamed to contain more racially neutral "welcomelist" and "blocklist" terms. So we have to update our sauserprefs DB records. Use this php scriplet from command line to do the job, after adjusting your mysql login:

cat > sauserprefs_blocklist_welcomelist.php << __EOF__
#!/usr/bin/php
<?php
/************************************************************************************************
Finds and replaces deprecated strings blacklist_from/whitelist_from in spamassassin.userpref
db table to blocklist_from/welcomelist_from respectively.
************************************************************************************************/

$host = "localhost";
$database = "spamassassin";
$user = "spamassassin";
$password = "xxxxxxxxxxxxxxxxxx";

$link = mysqli_connect($host, $user, $password, $database) or die("Unable to connect to MySQL");
$query ="UPDATE userpref SET preference = REPLACE(REPLACE(preference, 'whitelist_from', 'welcomelist_from'), 'blacklist_from', 'blocklist_from')";
mysqli_query($link, $query) or die(mysqli_error($link));
print "job done\n";
__EOF__

chmod +x sauserprefs_blocklist_welcomelist.php
./sauserprefs_blocklist_welcomelist.php

Add a comment