#!/bin/sh #---------------------------------------------------------------------------------- # /var/install/bin/antispam-cleanup-awl - remove invalid addresses from AWL # # Copyright (c) 2001-2024 The Eisfair Team, team(at)eisfair(dot)org # # Creation: 2012-06-24 jed # Last Update: $Id$ # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #---------------------------------------------------------------------------------- # read eislib etc. . /var/install/include/eislib #exec 2>/tmp/antispam-cleanup-awl-trace-$$.log #set -x pgmname=`basename $0` antispam_config_path=/var/antispam debug=0 tmpdir=/tmp awlfile=${antispam_config_path}/spamassassin/auto-whitelist tmpfile1=${tmpdir}/antispam-awl-db-dump.$$ tmpfile2=${tmpdir}/antispam-awl-db-addresses.$$ tmpfile3=${tmpdir}/antispam-awl-db-sorted.$$ tmpfile4=${tmpdir}/antispam-awl-output.$$ dbscript=${tmpdir}/antispam-awl-db-read.pl doctitle="remove 'bad' addresses from AWL database" clrhome mecho --info "Antispam remove 'bad' addresses from AWL database" mecho if [ -f ${awlfile} ] then # create perl script to read database in raw mode { echo '#!/usr/bin/perl' echo echo '# DB_File lesen' echo 'use strict;' echo 'use DB_File;' echo 'my $dbfile = $ARGV[0] or die $!;' echo 'my %data;' echo "tie(%data, 'DB_File', \$dbfile, O_RDONLY, 0600) or die(\"Can't tie data with file \$dbfile\");" echo 'foreach my $k(keys %data){' echo ' print "$k $data{$k}\n";' echo '}' echo 'untie %data;' } > ${dbscript} chmod +x ${dbscript} # read awl database and extract addresses ${dbscript} ${awlfile} > ${tmpfile1} grep --binary-files=text -v "[0-9]$" ${tmpfile1} | sed 's/|/:|/g' | cut -d'|' -f1 > ${tmpfile2} if [ -s ${tmpfile2} ] then # sort and cleanup data sort ${tmpfile2} | uniq > ${tmpfile3} # remove 'bad' addresses from awl database idx=`wc -l ${tmpfile3} | cut -d' ' -f1` if [ ${idx} -gt 0 ] then { echo echo "Number of 'bad' email addresses found: ${idx}" echo "An automatic clean-up process will be started now." echo echo "Removing the following addresses:" echo } > ${tmpfile4} fi ( techo --file --begin '1' '6r' '2' '70' while read line do email=`echo "${line}" | sed 's/:$//g'` techo --file row "" "${idx}" "-" "'${email}'" >> ${tmpfile4} spamassassin --remove-addr-from-whitelist="${email}" > /dev/null idx=`expr ${idx} - 1` done < ${tmpfile3} techo --file --end { echo echo "done." } >> ${tmpfile4} ) & # check if show-doc.cui supports colors color='' frame='' if $(grep -qE "^MENU=['\"]/var/install/bin/show-menu['\"]" /etc/config.d/setup) then color='--nocolor' frame='--noframe' fi /var/install/bin/show-doc.cui ${color} ${frame} --follow --title "${doctitle}" ${tmpfile4} else echo "nothing to do." fi if [ ${debug} -eq 0 ] then # remove temporary files rm -f ${tmpfile1} ${tmpfile2} ${tmpfile3} ${tmpfile4} rm -f ${dbscript} fi else mecho --error "Antispam auto-whitelist database couldn't be found!" fi exit 0