On 5/11/20 12:46 AM, Thomas Andrejak wrote: > Hello > > I came here because SpamAssassin Team tell me to : > https://bz.apache.org/SpamAssassin/show_bug.cgi?id=7814 > > As SpamAssassin has Syslog to send alerts, I want to add support for Prelude > to send alerts. Some people I know ask me this. > > Prelude is available in many Linux distribution through libprelude and have > the perl bindings. > > Can you give me some advice to build such plugin ? My first proposition does > not fit spamassassin phylosophie : > https://github.com/ToToL/spamassassin/commit/fa5a88c0c3fac815e2a2b69b1bb795f2fffa3684 > Attached you can find a WIP Prelude Plugin diff, there should be quite all info needed to integrate Prelude. Feel free to ask more info if needed. Giovanni
diff --git a/MANIFEST b/MANIFEST index 4a1b69f..f26b06b 100644 --- a/MANIFEST +++ b/MANIFEST @@ -99,6 +99,7 @@ lib/Mail/SpamAssassin/Plugin/OneLineBodyRuleType.pm lib/Mail/SpamAssassin/Plugin/Phishing.pm lib/Mail/SpamAssassin/Plugin/PhishTag.pm lib/Mail/SpamAssassin/Plugin/PDFInfo.pm +lib/Mail/SpamAssassin/Plugin/Prelude.pm lib/Mail/SpamAssassin/Plugin/Pyzor.pm lib/Mail/SpamAssassin/Plugin/RaciallyCharged.pm lib/Mail/SpamAssassin/Plugin/Razor2.pm diff --git a/lib/Mail/SpamAssassin/Plugin/Prelude.pm b/lib/Mail/SpamAssassin/Plugin/Prelude.pm new file mode 100644 index 0000000..c62b959 --- /dev/null +++ b/lib/Mail/SpamAssassin/Plugin/Prelude.pm @@ -0,0 +1,91 @@ +# <@LICENSE> +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# </@LICENSE> + +=head1 NAME + +Prelude - Prelude alerts plugin + +=head1 SYNOPSIS + + loadplugin Mail::SpamAssassin::Plugin::Prelude + +=head1 DESCRIPTION + +To try this plugin, write the above line in the synopsis to +C</etc/mail/spamassassin/plugintest.cf>. + +=cut + +package Mail::SpamAssassin::Plugin::Prelude; + +use Mail::SpamAssassin::Plugin; +use strict; +use warnings; +# use bytes; +use re 'taint'; + +use Mail::SpamAssassin::Logger; + +our @ISA = qw(Mail::SpamAssassin::Plugin); + +our $VERSION = '0.1'; + +use constant HAS_PRELUDE => eval { require Prelude; }; + +BEGIN +{ + eval{ + Prelude->import + }; +} + +# constructor: register the eval rule +sub new { + my $class = shift; + my $mailsaobject = shift; + + # some boilerplate... + $class = ref($class) || $class; + my $self = $class->SUPER::new($mailsaobject); + bless ($self, $class); + + return $self; +} + +sub _prelude_start { + my($self) = @_; + + $self->{prelude_client} = new Prelude::ClientEasy("SpamAssassin", 4, "SpamAssassin", "AntiSpam", "https://spamassassin.apache.org", $Mail::SpamAssassin::VERSION ); + $self->{prelude_client}->start(); +} + +sub check_post_learn { + my ($self, $opts) = @_; + + my $pms = $opts->{permsgstatus}; + + if ($pms->is_spam()) { + my $score = $pms->get_score(); + my $required_score = $pms->get_required_score(); + my $tests = join(",", sort(grep(length,$pms->get_names_of_tests_hit()))); + + dbg("Prelude: user: $pms->{main}->{username}, score: $score, required score: $required_score, tests: $tests"); + $self->_prelude_start(); + } +} + +1;