[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Sheflug] SpamAssassin problems. Was: (no subject)



    Richard> Hi I've been trying to get some help from the
    Richard> Spamassassin list and not had any replies so far.  I was
    Richard> wondering if Richard Stevenson or someone else might know
    Richard> a bit more about the internal workings of Spamassassin
    Richard> than myself.

    Richard> Seems that shortly after I set up my Mail::Audit
    Richard> application yesterday Spamassassin did try to work in the
    Richard> way that it should.  However, it looks as though the logs
    Richard> point towards the fact that it was trying to run as user
    Richard> Richard but didn't quite make it.  The Mail::Audit script
    Richard> which lives in a /home/richard/.spam files reads as....

[Richard's script]

#!/usr/bin/perl

  use Mail::Audit;
  use Mail::SpamAssassin;
  my $item  = Mail::Audit->new(nomime => 1);
  my $maildir = "/home/richard/inbox";
  while (<DATA>) {
        chomp;
        next unless $from =~ /$_/i or $to =~ /$_/i;
        print LOG "$from:$subject:Spam?\n";
        $item->accept($folder."/home/richard/Spam");
        my $spamtest = Mail::SpamAssassin->new();
        my $status = $spamtest->check($mail);

        if ($status->is_spam ()) {
        $status->rewrite_mail() };
        $mail->accept("/home/richard/Spam");
    }

  $item->accept;

Erm...ick! What's with processing the file using <DATA>?

If you're running this script via a .forward/.qmail file, then the
message is being fed in on STDIN, and the perl modules will handle
parsing the message for you.

You create a Mail::Audit object and store it in $item, but call
Mail::SpamAssassin on $mail. If you "use strict;", perl will tell you
about these errors.

Is that the whole script? 

This line:

	next unless $from =~ /$_/i or $to =~ /$_/i; 

Suggests you want to loop over a number of patterns and match the
From:/To: headers against those strings.

Below is a simple script to filter spam to /home/richard/Spam, and
accept everything else to /home/richard/inbox.
Add logging, other filtering to taste.
Untested, but should work.

#!/usr/bin/perl

use strict;
use warnings;

use Mail::Audit;
use Mail::SpamAssassin;

my $mailbox = "/home/richard/inbox"; # Why not $ENV{'MAIL'} ?

my $item     = Mail::Audit->new( nomime => 1, );
my $spamtest = Mail::SpamAssassin->new();
my $status   = $spamtest->check( $item );   # not $mail.

if ( $status->is_spam() ) {
    $status->rewrite_mail();
    $mail->accept( "/home/richard/Spam" );
} else {
    $mail->accept( $mailbox );
}


You're using Mail::Audit and Mail::SpamAssassin in your script, so
spamd/spamc shouldn't bew required, but I'll go into it anyhow.

    Richard> Can anyone shed some light on how spamd and spamc work so
    Richard> that I might be able to work out why Spamassassin isn't
    Richard> working properly on my machine ?

spamc is used to pass emails, one a time, IIRC, to spamd, usually as
part of the mail delivery process (i.e. from .forward/.qmail)
spamc reads mail from STDIN, spools it to spamd, and outputs the
results to STDOUT.
spamc should be run as the user whose config files should be read.

spamd is a daemon that can be used in place of the Perl
Mail::SpamAssassin module if a lot of mail needs to be processed, in
conjunction with spamc.

If you are using spamc/spamd, your filtering script only needs to
detect the X-Spam-Status header or [Spam] tag in the email subject
lines, not use Mail::SpamAssassin to repeat tests.

Something like the following will do:

#!/usr/bin/perl
 
use strict;
use warnings;
 
use Mail::Audit;

my $mailbox = "/home/richard/inbox"; # Why not $ENV{'MAIL'} ?
my $item    = Mail::Audit->new();
 
if ($mail->get("X-Spam-Status") =~ /Yes/ig) {
  # Spam.
  $item->accept( "/home/richard/Spam" );;
} else {
  $mail->accept( $mailbox );
}


    Richard> .spam is set as chmod 700 in /home/richard.  Spamassassin
    Richard> probably has different permissions ?  This may be the
    Richard> problem.  This is working well but it needs some support
    Richard> from Spamassassin to process mail properly when it is
    Richard> spam. Some spam isn't detected or processed by
    Richard> Mail::Audit at all.

Try fixing up your filtering script. 

It looks like you're using spamd/spamc _and_ Mail::SpamAssassin.

I'm not sure about spamd, it generally Just Works. I'd need to look
into it futher.
Normally, Mail::SpamAssassin should be enough for the job.

Cheers.

Baz.

-- 
Barrie J. Bremner
baz-sheflug [at] barriebremner.com      http://barriebremner.com/


___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.