This is a discussion on RE: [courier-users] SpamAssassin during SMTP dialog within the Courier-Imap forums, part of the Mail Servers and Related category; This is a multi-part message in MIME format. ------=_NextPart_000_0024_01C52367.22470310 Content-Type: text/plain; charset="ISO-8859-15&...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
This is a multi-part message in MIME format.
------=_NextPart_000_0024_01C52367.22470310 Content-Type: text/plain; charset="ISO-8859-15" Content-Transfer-Encoding: 7bit Jay Lee wrote: > with some perl scripting, one could probably get something similar with > Spamassassin at SMTP time A simple SpamAssassin module for Courier::Filter might look like the following. I just hacked it together off the top of my head, so it hasn't been tested, but I will probably include a tested one in the next release of C:F. A documented version is attached. ----8<----snip----8<---- package Courier::Filter::Module::SpamAssassin; use warnings; use strict; use base qw(Courier::Filter::Module); use Mail::SpamAssassin; sub new { my ($class, %options) = @_; my $spamassassin = Mail::SpamAssassin->new({ rules_filename => $options{rules_file_name} }); $spamassassin->compile_now(); my $module = $class->SUPER::new( %options, spamassassin => $spamassassin ); return $module; } sub match { my ($module, $message) = @_; my $class = ref($module); my $spamassassin = $module->{spamassassin}; my $sa_message = $spamassassin->parse($message->text); my $status = $spamassassin->check($sa_message); my $is_spam = $status->is_spam; my $score = $status->get_score; my $tests_hit = $status->get_names_of_tests_hit; $status->finish(); return 'SpamAssassin: Message looks like spam (score: ' . $score . '; ' . $tests_hit . ')' if $is_spam; return undef; # otherwise. } 1; ------=_NextPart_000_0024_01C52367.22470310 Content-Type: application/octet-stream; name="SpamAssassin.pm" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="SpamAssassin.pm" #=0A= # Courier::Filter::Module::SpamAssassin class=0A= #=0A= # (C) 2005 Julian Mehnle <julian@mehnle.net>=0A= # $Id$=0A= #=0A= ################################################## #######################= #####=0A= =0A= =3Dhead1 NAME=0A= =0A= Courier::Filter::Module::SpamAssassin - A SpamAssassin message filter = module=0A= for the Courier::Filter framework=0A= =0A= =3Dcut=0A= =0A= package Courier::Filter::Module::SpamAssassin;=0A= =0A= =3Dhead1 VERSION=0A= =0A= 0.10=0A= =0A= =3Dcut=0A= =0A= our $VERSION =3D '0.10';=0A= =0A= =3Dhead1 SYNOPSIS=0A= =0A= use Courier::Filter::Module::SpamAssassin;=0A= =0A= my $module =3D Courier::Filter::Module::SpamAssassin->new(=0A= rules_file_name=0A= =3D> $rules_file_name,=0A= =0A= logger =3D> $logger,=0A= inverse =3D> 0,=0A= trusting =3D> 0,=0A= testing =3D> 0,=0A= debugging =3D> 0=0A= );=0A= =0A= my $filter =3D Courier::Filter->new(=0A= ...=0A= modules =3D> [ $module ],=0A= ...=0A= );=0A= =0A= =3Dcut=0A= =0A= use warnings;=0A= use strict;=0A= =0A= use base qw(Courier::Filter::Module);=0A= =0A= use Mail::SpamAssassin;=0A= =0A= # Constants:=0A= ################################################## #######################= #####=0A= =0A= use constant TRUE =3D> (0 =3D=3D 0);=0A= use constant FALSE =3D> not TRUE;=0A= =0A= # Interface:=0A= ################################################## #######################= #####=0A= =0A= =3Dhead1 DESCRIPTION=0A= =0A= This class is a filter module class for use with Courier::Filter. It = matches a=0A= message if its SpamAssassin spam score exceeds the configured threshold.=0A= =0A= =3Dcut=0A= =0A= sub new;=0A= =0A= sub match;=0A= =0A= # Implementation:=0A= ################################################## #######################= #####=0A= =0A= =3Dhead2 Constructor=0A= =0A= The following constructor is provided:=0A= =0A= =3Dover=0A= =0A= =3Ditem B<new(%options)>: RETURNS Courier::Filter::Module::SpamAssassin=0A= =0A= Creates a new B<SpamAssassin> filter module.=0A= =0A= %options is a list of key/value pairs representing any of the following=0A= options:=0A= =0A= =3Dover=0A= =0A= =3Ditem B<config_file_name>=0A= =0A= A string specifying the absolute file name of a SpamAssassin config = file. If=0A= B<undef>, only uses the SpamAssassin default configuration. Defaults to=0A= B<undef>.=0A= =0A= =3Dback=0A= =0A= All options of the B<Courier::Filter::Module> constructor are also = supported.=0A= Please see L<Courier::Filter::Module/"new"> for their descriptions.=0A= =0A= =3Dcut=0A= =0A= sub new {=0A= my ($class, %options) =3D @_;=0A= =0A= my $spamassassin =3D Mail::SpamAssassin->new({=0A= rules_filename =3D> $options{rules_file_name}=0A= });=0A= $spamassassin->compile_now();=0A= =0A= my $module =3D $class->SUPER::new(=0A= %options,=0A= spamassassin =3D> $spamassassin=0A= );=0A= =0A= return $module;=0A= }=0A= =0A= =3Dback=0A= =0A= =3Dhead2 Instance methods=0A= =0A= See L<Courier::Filter::Module/"Instance methods"> for a description of = the=0A= provided instance methods.=0A= =0A= =3Dcut=0A= =0A= sub match {=0A= my ($module, $message) =3D @_;=0A= my $class =3D ref($module);=0A= =0A= my $spamassassin =3D $module->{spamassassin};=0A= my $sa_message =3D $spamassassin->parse($message->text);=0A= my $status =3D $spamassassin->check($sa_message);=0A= =0A= my $is_spam =3D $status->is_spam;=0A= my $score =3D $status->get_score;=0A= my $tests_hit =3D $status->get_names_of_tests_hit;=0A= =0A= $status->finish();=0A= =0A= return 'SpamAssassin: Message looks like spam (score: ' . $score . = '; ' . $tests_hit . ')'=0A= if $is_spam;=0A= =0A= return undef;=0A= # otherwise.=0A= }=0A= =0A= =3Dhead1 SEE ALSO=0A= =0A= L<Courier::Filter::Module>, L<Courier::Filter::Overview>.=0A= =0A= For AVAILABILITY, SUPPORT, COPYRIGHT, and LICENSE information, see=0A= L<Courier::Filter::Overview>.=0A= =0A= =3Dhead1 AUTHOR=0A= =0A= Julian Mehnle <julian@mehnle.net>=0A= =0A= =3Dcut=0A= =0A= TRUE;=0A= =0A= # vim:tw=3D79=0A= ------=_NextPart_000_0024_01C52367.22470310-- ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click _______________________________________________ courier-users mailing list courier-users@lists.sourceforge.net Unsubscribe: https://lists.sourceforge.net/lists/.../courier-users |