Eval2.pm


package Eval2;

use strict;
use warnings;

use base 'Mail::SpamAssassin::Plugin';
use Mail::SpamAssassin::Logger;

sub new {
    my ( $class, $mailsa ) = @_;

    $class = ref($class) || $class;
    my $self = $class->SUPER::new($mailsa);
    bless $self, $class;

    ### register the eval rule
    $self->register_eval_rule("check_stockspam");

    return $self;
}

my $stock_token_regex = qr{
        (?:\b|_)                            # word boundary, or _
        (?i:Inc|Corp(?:oration)?|Gr[0o]up)  # "inc" or something
        [.,]?                               # optional dot or comma
        \s*\n                               # match to end of line
        ^\s*(?i:Sym\w*\s*:\s*)?             # next line optional sym(bol):
        (                                   # start capture
                (?:[A-Z]\s{0,3}){3}             # match three letters, optional spaces
                [A-Z]                           # match last letter
        )                                   # end capture
        \s*$                                # match until end of line
}xsm;

my %ticker_symbol = map { $_ => 1 } qw(
    MRDY LVCC NNCP CTCX
);

sub check_stockspam {
    my ( $self, $per_msg_status, $body_ref ) = @_;

    my $msg_text = join( '', @$body_ref );
    dbg("Eval2: check_stockspam called");
    while ( my ($possible_symbol) = $msg_text =~ /$stock_token_regex/ ) {
        ### trim all non-letters
        $possible_symbol =~ tr/A-Za-z//cd;
        dbg("Eval2: testing possible symbol: $possible_symbol");
        return 1 if exists $ticker_symbol{$possible_symbol};
    }
    return 0;
}

1;