Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 594817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:59:39+00:00 2026-05-13T15:59:39+00:00

I use the following code to generate a spam report using SpamAssassin: use Mail::SpamAssassin;

  • 0

I use the following code to generate a spam report using SpamAssassin:

use Mail::SpamAssassin;

my $sa = Mail::SpamAssassin->new();

open FILE, "<", "mail.txt";
my @lines = <FILE>;
my $mail = $sa->parse(@lines);

my $status = $sa->check($mail);

my $report = $status->get_report();
$report =~ s/\n/\n<br>/g;

print "<h1>Spam Report</h1>";
print $report;

$status->finish();
$mail->finish();
$sa->finish();

The problem I have is that it classifies ‘sample-nonspam.txt’ as spam:

Content preview: [...] 

Content analysis details: (6.9 points, 5.0 required) 

pts rule name description 
---- ---------------------- -------------------------------------------------- 
-0.0 NO_RELAYS Informational: message was not relayed via SMTP 
1.2 MISSING_HEADERS Missing To: header 
0.1 MISSING_MID Missing Message-Id: header 
1.8 MISSING_SUBJECT Missing Subject: header 
2.3 EMPTY_MESSAGE Message appears to have no textual parts and no 
Subject: text 
-0.0 NO_RECEIVED Informational: message has no Received headers 
1.4 MISSING_DATE Missing Date: header 
0.0 NO_HEADERS_MESSAGE Message appears to be missing most RFC-822 headers 

And that information -is- in the file. What worries me is that in the documentation, it states “Parse will return a Mail::SpamAssassin::Message object with just the headers parsed.”. Does that mean it will not return a full message?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:59:39+00:00Added an answer on May 13, 2026 at 3:59 pm

    You’re missing a single character:

    my $mail = $sa->parse(\@lines);
    

    From the docs (with emphasis added):

    parse($message, $parse_now [, $suppl_attrib])

    Parse will return a Mail::SpamAssassin::Message object with just the headers parsed. When calling this function, there are two optional parameters that can be passed in: $message is either undef (which will use STDIN), a scalar of the entire message, an array reference of the message with 1 line per array element, or a file glob which holds the entire contents of the message; and $parse_now, which specifies whether or not to create the MIME tree at parse time or later as necessary.

    With the change above, I get the following output (HTML stripped):

     pts rule name              description
    ---- ---------------------- --------------------------------------------------
    -2.6 BAYES_00               BODY: Bayesian spam probability is 0 to 1%
                                [score: 0.0000]

    As the docs mention, parse is flexible. You could instead use

    my $mail = $sa->parse(join "" => <FILE>);  # scalar of the entire message
    

    or

    my $mail = $sa->parse(\*FILE);             # a file glob with the entire contents
    

    or

    my $mail;
    { local $/; $mail = $sa->parse(<FILE>) }   # scalar of the entire message
    

    or even

    open STDIN, "<", "mail.txt" or die "$0: open: $!";
    my $mail = $sa->parse(undef);              # undef means read STDIN
    

    You’d remove my @lines = <FILE> for these last four examples to function as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 299k
  • Answers 299k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I assume you're using MasterType because you need some property… May 13, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer Very nice jQuery gallery that also suport custom filmstrip is… May 13, 2026 at 7:46 pm
  • Editorial Team
    Editorial Team added an answer I guess you're using MySQL? The only way that I… May 13, 2026 at 7:45 pm

Related Questions

I use the following code to compile a cpp file to object file. g++
I am looking to encrypt data. I want to generate encryption keys based on
I don't know a better title, but I'll describe the problem. A piece of
Possible Duplicate: How Random is System.Guid.NewGuid()? Based on this question I would like to
I am having trouble setting up the configuration of Spring.Net so that I can

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.