Hi,
On Wed, 29 Sep 2004, Theo Van Dinter wrote:

> On Wed, Sep 29, 2004 at 03:32:22PM -0500, Bob Apthorpe wrote:
> > If I wanted to analyzed a message using either SA 2.6x or 3.x, what do I
> > use to encapsulate that message aside from
> > Mail::SpamAssassin::NoMailAudit? That is, how do I have to change:
> >
> > ----
> >         $self->{'_mail'} = Mail::SpamAssassin::NoMailAudit->new();
> >
> >         # Make a M::SA object; point to custom configs
> >         my $spamtest = Mail::SpamAssassin->new($self->{'sa_prefs'});
> >
> >         # Get verdict, score, list of rules
> >         my $status = $spamtest->check($self->{'_mail'});
> > ----
> >
> > so that it'll work with both SA 2.6x and 3.x?
>
> the top of the M::SA docs have it pretty clear:
>
>          my $spamtest = Mail::SpamAssassin->new();
>          my $mail = $spamtest->parse( $message );
>          my $status = $spamtest->check( $mail );
>
> We decided to change the API to just call parse() which will return the
> appropriate object instead of calling NoMailAudit (or in 3.0, Message,) and
> doing it yourself (although you can do that, the parse() method lets us change
> things on the backend without having to change the published API).
>
> So in theory, you could figure out what version you're on, then do an if/else
> to call NMA or parse() appropriately.

Ok, so let me see if I have this straight:

At the head of the module where all the 'use' statements live...
----
use Mail::SpamAssassin;

use Mail::Header;
use Mail::Internet;

if ($Mail::SpamAssassin::VERSION < 3) {
    use Mail::SpamAssassin::NoMailAudit;
} else {
    use Mail::SpamAssassin::Message;
}
----

Then later, once we've wrapped the text in fake mail headers to make
a RFC822-compliant message...
----
    my $message =
      Mail::Internet->new('Header' => $mailhead, 'Body' => $Rl_body);

    # Fake up a mail message and stuff the comment in the body
    if ($Mail::SpamAssassin::VERSION < 3) {
        $self->{'_mail'} =
          Mail::SpamAssassin::NoMailAudit->new('data' =>
[$message->as_string]);
    } else {
        $self->{'_mail'} =
          Mail::SpamAssassin::Message->new({'message' =>
$message->as_string});
    }
----

And finally, analyze the message...
----
    # Make a M::SA object; point to custom configs
    my $spamtest = Mail::SpamAssassin->new($self->{'sa_prefs'});

    # Get verdict, score, list of rules
    my $status = $spamtest->check($self->{'_mail'});
----

That should gracefully handle both SA 2.x and 3.x, correct?

-- Bob

Reply via email to