Spam filtering in autoreplies
authorJamie Cameron <jcameron@webmin.com>
Fri, 6 Aug 2010 08:25:06 +0000 (01:25 -0700)
committerJamie Cameron <jcameron@webmin.com>
Fri, 6 Aug 2010 08:25:06 +0000 (01:25 -0700)
postfix/CHANGELOG
qmailadmin/CHANGELOG
sendmail/CHANGELOG
sendmail/autoreply.pl

index 7a22c02..5bf101c 100644 (file)
@@ -75,3 +75,4 @@ If a map is made up of files in multiple directories and a Webmin user has a dir
 Fixed the descriptions of logged events as shown in the Webmin Actions Log module.
 ---- Changes since 1.510 ----
 Added support for CIDR maps and multiple SMTP client restriction maps.
+Added spam checking to the autoreply script, if spamassassin is installed.
index c773dee..45b150b 100644 (file)
@@ -12,3 +12,5 @@ Added checkboxes and Delete Selected buttons on the aliases, virtual mappings, d
 ---- Changes since 1.490 ----
 Autoreply messages starting with <html> or <body> will now be sent using the tex
 t/html MIME type.
+---- Changes since 1.510 ----
+Added spam checking to the autoreply script, if spamassassin is installed.
index cc1d648..96b7f15 100644 (file)
@@ -49,3 +49,4 @@ If multiple alias files are defined, one can be selected when adding a new alias
 Autoreply messages starting with <html> or <body> will now be sent using the text/html MIME type.
 ---- Changes since 1.510 ----
 Added validation when manually editing the aliases and other map files.
+Added spam checking to the autoreply script, if spamassassin is installed.
index 17b6f1d..56a63a8 100755 (executable)
@@ -38,6 +38,7 @@ if (!$config{'sendmail_path'} || !-x $config{'sendmail_path'}) {
 # read headers and body
 $lnum = 0;
 while(<STDIN>) {
+       $headers .= $_;
        s/\r|\n//g;
        if (/^From\s+(\S+)/ && $lnum == 0) {
                # Magic From line
@@ -74,6 +75,32 @@ if ($header{'from'} =~ /postmaster|mailer-daemon/i ||
        exit 0;
        }
 
+# if spamassassin is installed, feed the email to it
+$spam = &has_command("spamassassin");
+if ($spam) {
+       $temp = "/tmp/autoreply.spam.$$";
+       unlink($temp);
+       open(SPAM, "| $spam >$temp 2>/dev/null");
+       print SPAM $headers;
+       print SPAM $body;
+       close(SPAM);
+       $isspam = undef;
+       open(SPAMOUT, $temp);
+       while(<SPAMOUT>) {
+               if (/^X-Spam-Status:\s+(\S+)/i) {
+                       $isspam = lc($1) eq 'yes' ? 1 : 0;
+                       last;
+                       }
+               last if (!/\S/);
+               }
+       close(SPAMOUT);
+       unlink($temp);
+       if ($isspam) {
+               print STDERR "Not autoreplying to spam\n";
+               exit 0;
+               }
+       }
+
 # work out the correct to address
 @to = ( &split_addresses($header{'to'}),
        &split_addresses($header{'cc'}),
@@ -382,3 +409,16 @@ $t =~ s/([=\177-\377])/sprintf("=%2.2X",ord($1))/ge;
 return $t;
 }
 
+sub has_command
+{
+local ($cmd) = @_;
+if ($cmd =~ /^\//) {
+       return -x $cmd ? $cmd : undef;
+       }
+else {
+       foreach my $d (split(":", $ENV{'PATH'}), "/usr/bin", "/usr/local/bin") {
+               return "$d/$cmd" if (-x "$d/$cmd");
+               }
+       return undef;
+       }
+}