On Fri, Dec 28, 2012 at 12:45:03AM -0800, Sean Tout wrote: > Hello, > > I wrote a short Perl program that reads email from an existing mbox > formatted file, passes each individual email to Spamassassin for parse and > score, then prints a report for each email. The strange thing is that I keep > getting the same report score for all messages. I did confirm that I'm > reading each message by printing it after reading it. I tried the below code > on many different emails (spam and ham) yet I get the same report score for > all of them. What am I doing wrong?
You need to completely destroy SpamAssassin after usage. Change this: > my $spamtest = Mail::SpamAssassin->new(); > > # This is the main loop. It's executed once for each email > while(!$folder_reader->end_of_file()) > { > $email = $folder_reader->read_next_email(); > $mail = $spamtest->parse($email); > $status = $spamtest->check($mail); > print RFILE $status->get_report(); > print RFILE "\n"; > } To something like this: while(!$folder_reader->end_of_file()) { my $email = $folder_reader->read_next_email(); my $spamtest = Mail::SpamAssassin->new(); my $mail = $spamtest->parse($email); my $status = $spamtest->check($mail); print RFILE $status->get_report(); print RFILE "\n"; $status->finish(); # important $mail->finish(); # important $spamtest->finish(); # important } I can't remember from the top of my head if $spamtest can be reused after finish(), but atleast this should work 100%.