spamassassin-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kris Deugau <>
Subject Re: using SA as a tool
Date Fri, 01 Oct 2010 15:57:50 GMT
Diffenderfer, Randy wrote:
> I was under the impression that there was a clear-cut way to use SA as a 
> factory within a custom perl wrapper (I have looked at the 
> Mail::SpamAssassin doco).  My objective is to do various things to the 
> parsed message, such as distill out URLs for example.
> Is there indeed a clear way to do this?

I had some trouble making sense of the Mail::SpamAssassin API docs 
myself, but I kept at it for a while since it still looked to be easier 
than effectively rewriting big chunks of SA's message-parsing code.

Here are the basics I'm using to extract URIs and last-external relay IPs:

# note you may need a use lib '/path/to/sa' if you've installed from
# source in a custom location
use Mail::SpamAssassin;
use Mail::SpamAssassin::PerMsgStatus;

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

foreach (@msglist) {
   # <load a message from IMAP into $msg>
   my $mail = $spamtest->parse($msg);
   my $status = $spamtest->check($mail);

   my $skip_domains = $status->{main}->{conf}->{uridnsbl_skip_domains};

   # Generate the full list of html-parsed domains.
   # Returns hashref.
   my $uris = $status->get_uri_detail_list();

   my $stmsg = $status->get_message();
   my @untrusted = @{$stmsg->{metadata}->{relays_untrusted}};

   my $relayip = $untrusted[0]->{ip};


View raw message