You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by pa...@apache.org on 2005/06/06 07:15:37 UTC

svn commit: r180222 - in /spamassassin/trunk: MANIFEST lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm rules/50_scores.cf rules/60_whitelist_subject.cf rules/init.pre t/whitelist_subject.t

Author: parker
Date: Sun Jun  5 22:15:36 2005
New Revision: 180222

URL: http://svn.apache.org/viewcvs?rev=180222&view=rev
Log:
Bug 4058: WhiteListSubject Plugin

Added:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm
    spamassassin/trunk/rules/60_whitelist_subject.cf
    spamassassin/trunk/t/whitelist_subject.t   (with props)
Modified:
    spamassassin/trunk/MANIFEST
    spamassassin/trunk/rules/50_scores.cf
    spamassassin/trunk/rules/init.pre

Modified: spamassassin/trunk/MANIFEST
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/MANIFEST?rev=180222&r1=180221&r2=180222&view=diff
==============================================================================
--- spamassassin/trunk/MANIFEST (original)
+++ spamassassin/trunk/MANIFEST Sun Jun  5 22:15:36 2005
@@ -83,6 +83,7 @@
 lib/Mail/SpamAssassin/Plugin/Test.pm
 lib/Mail/SpamAssassin/Plugin/TextCat.pm
 lib/Mail/SpamAssassin/Plugin/URIDNSBL.pm
+lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm
 lib/Mail/SpamAssassin/PluginHandler.pm
 lib/Mail/SpamAssassin/Reporter.pm
 lib/Mail/SpamAssassin/SQLBasedAddrList.pm
@@ -196,6 +197,7 @@
 rules/60_awl.cf
 rules/60_whitelist.cf
 rules/60_whitelist_spf.cf
+rules/60_whitelist_subject.cf
 rules/STATISTICS-set1.txt
 rules/STATISTICS-set2.txt
 rules/STATISTICS-set3.txt
@@ -432,6 +434,7 @@
 t/utf8.t
 t/whitelist_addrs.t
 t/whitelist_from.t
+t/whitelist_subject.t
 t/whitelist_to.t
 t/zz_cleanup.t
 tools/README.speedtest

Added: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm?rev=180222&view=auto
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm (added)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/WhiteListSubject.pm Sun Jun  5 22:15:36 2005
@@ -0,0 +1,143 @@
+# <@LICENSE>
+# Copyright 2004 Apache Software Foundation
+# 
+# Licensed 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
+
+Mail::SpamAssassin::Plugin::WhiteListSubject
+
+=head1 SYNOPSIS
+
+ loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject
+
+ header SUBJECT_IN_WHITELIST eval:check_subject_in_whitelist()
+ header SUBJECT_IN_BLACKLIST eval:check_subject_in_blacklist()
+
+ score SUBJECT_IN_WHITELIST -100
+ score SUBJECT_IN_BLACKLIST 100
+
+ whitelist_subject [Bug *]
+ blacklist_subject Make Money Fast
+
+=head1 DESCRIPTION
+
+This SpamAssassin plugin module provides eval tests for whitelisting and blacklisting
+particular strings in the Subject header.  The value for whitelist_subject or
+blacklist_subject are strings which may contain file -glob -style patterns,
+similar to the other whitelist_* config options.
+
+=cut
+
+package Mail::SpamAssassin::Plugin::WhiteListSubject;
+
+use Mail::SpamAssassin::Plugin;
+use strict;
+use warnings;
+use bytes;
+
+use vars qw(@ISA);
+@ISA = qw(Mail::SpamAssassin::Plugin);
+
+# constructor: register the eval rule
+sub new {
+  my $class = shift;
+  my $mailsaobject = shift;
+
+  $class = ref($class) || $class;
+  my $self = $class->SUPER::new($mailsaobject);
+  bless ($self, $class);
+
+  $self->register_eval_rule ("check_subject_in_whitelist");
+  $self->register_eval_rule ("check_subject_in_blacklist");
+
+  $self->set_config($mailsaobject->{conf});
+
+  return $self;
+}
+
+sub set_config {
+  my ($self, $conf) = @_;
+
+  my @cmds = ();
+
+  push(@cmds, {
+	       setting => 'whitelist_subject',
+	       code => sub {
+		 my ($self, $key, $value, $line) = @_;
+
+		 $value = lc $value;
+		 my $re = $value;
+		 $re =~ s/[\000\\\(]/_/gs;                   # paranoia
+		 $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g;        # escape any possible metachars
+		 $re =~ tr/?/./;                             # "?" -> "."
+                 $re =~ s/\*/\.\*/g;                         # "*" -> "any string"
+		 $conf->{$key}->{$value} = ${re};
+	       }});
+
+  push(@cmds, {
+	       setting => 'blacklist_subject',
+	       code => sub {
+		 my ($self, $key, $value, $line) = @_;
+
+		 $value = lc $value;
+		 my $re = $value;
+		 $re =~ s/[\000\\\(]/_/gs;                   # paranoia
+		 $re =~ s/([^\*\?_a-zA-Z0-9])/\\$1/g;        # escape any possible metachars
+		 $re =~ tr/?/./;                             # "?" -> "."
+                 $re =~ s/\*/\.\*/g;                         # "*" -> "any string"
+		 $conf->{$key}->{$value} = ${re};
+	       }});
+
+  $conf->{parser}->register_commands(\@cmds);
+}
+
+sub check_subject_in_whitelist {
+  my ($self, $permsgstatus) = @_;
+
+  my $subject = $permsgstatus->get('Subject');
+
+  return 0 unless $subject;
+
+  return $self->_check_subject($permsgstatus->{conf}->{whitelist_subject}, $subject);
+}
+
+sub check_subject_in_blacklist {
+  my ($self, $permsgstatus) = @_;
+
+  my $subject = $permsgstatus->get('Subject');
+
+  return 0 unless $subject;
+
+  return $self->_check_subject($permsgstatus->{conf}->{blacklist_subject}, $subject);
+}
+
+sub _check_subject {
+  my ($self, $list, $subject) = @_;
+
+  $subject = lc $subject;
+
+  return 1 if defined($list->{$subject});
+
+  study $subject;
+  foreach my $regexp (values %{$list}) {
+    if ($subject =~ qr/$regexp/i) {
+      return 1;
+    }
+  }
+
+  return 0;
+}
+
+1;

Modified: spamassassin/trunk/rules/50_scores.cf
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/rules/50_scores.cf?rev=180222&r1=180221&r2=180222&view=diff
==============================================================================
--- spamassassin/trunk/rules/50_scores.cf (original)
+++ spamassassin/trunk/rules/50_scores.cf Sun Jun  5 22:15:36 2005
@@ -584,6 +584,11 @@
 score USER_IN_DEF_WHITELIST -15.000
 score USER_IN_BLACKLIST_TO 10.000
 
+ifplugin Mail::SpamAssassin::Plugin::WhiteListSubject
+score SUBJECT_IN_WHITELIST -100
+score SUBJECT_IN_BLACKLIST 100
+endif # Mail::SpamAssassin::Plugin::WhiteListSubject
+
 ifplugin Mail::SpamAssassin::Plugin::SPF
 score USER_IN_SPF_WHITELIST -100.000
 score USER_IN_DEF_SPF_WL -7.500

Added: spamassassin/trunk/rules/60_whitelist_subject.cf
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/rules/60_whitelist_subject.cf?rev=180222&view=auto
==============================================================================
--- spamassassin/trunk/rules/60_whitelist_subject.cf (added)
+++ spamassassin/trunk/rules/60_whitelist_subject.cf Sun Jun  5 22:15:36 2005
@@ -0,0 +1,41 @@
+# SpamAssassin rules file: default whitelist/blacklist subject
+#
+# Please don't modify this file as your changes will be overwritten with
+# the next update. Use @@LOCAL_RULES_DIR@@/local.cf instead.
+# See 'perldoc Mail::SpamAssassin::Conf' for details.
+#
+# <@LICENSE>
+# Copyright 2004 Apache Software Foundation
+# 
+# Licensed 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>
+
+###########################################################################
+# Whitelist/Blacklist rules
+#
+# Note that most of these get 'noautolearn'.  They should not be
+# considered when deciding whether to auto-learn a message, as a
+# user slip-up could result in scribbling side-effects in the bayes
+# db as a result -- which is hard to remedy.
+
+ifplugin Mail::SpamAssassin::Plugin::WhiteListSubject
+
+header SUBJECT_IN_WHITELIST	eval:check_subject_in_whitelist()
+describe SUBJECT_IN_WHITELIST	Subject: contains string in the user's white-list
+tflags SUBJECT_IN_WHITELIST	userconf nice noautolearn
+
+header SUBJECT_IN_BLACKLIST	eval:check_subject_in_blacklist()
+describe SUBJECT_IN_BLACKLIST	Subject: contains string in the user's black-list
+tflags SUBJECT_IN_BLACKLIST	userconf noautolearn
+
+endif # Mail::SpamAssassin::Plugin::WhiteListSubject
\ No newline at end of file

Modified: spamassassin/trunk/rules/init.pre
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/rules/init.pre?rev=180222&r1=180221&r2=180222&view=diff
==============================================================================
--- spamassassin/trunk/rules/init.pre (original)
+++ spamassassin/trunk/rules/init.pre Sun Jun  5 22:15:36 2005
@@ -72,6 +72,10 @@
 #
 #loadplugin Mail::SpamAssassin::Plugin::AccessDB
 
+# WhitelistSubject - Whitelist/Blacklist certain subject regular expressions
+#
+loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject
+
 ###########################################################################
 # experimental plugins
 

Added: spamassassin/trunk/t/whitelist_subject.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/whitelist_subject.t?rev=180222&view=auto
==============================================================================
--- spamassassin/trunk/t/whitelist_subject.t (added)
+++ spamassassin/trunk/t/whitelist_subject.t Sun Jun  5 22:15:36 2005
@@ -0,0 +1,38 @@
+#!/usr/bin/perl
+
+use lib '.'; use lib 't';
+use SATest; sa_t_init("whitelist_subject");
+use Test; BEGIN { plan tests => 4 };
+
+# ---------------------------------------------------------------------------
+
+%is_whitelist_patterns = (
+q{ SUBJECT_IN_WHITELIST }, 'whitelist-subject'
+);
+
+%is_blacklist_patterns = (
+q{ SUBJECT_IN_BLACKLIST }, 'blacklist-subject'
+);
+
+tstpre("
+loadplugin Mail::SpamAssassin::Plugin::WhiteListSubject
+");
+
+tstprefs ("
+use_bayes 0
+use_auto_whitelist 0
+$default_cf_lines
+whitelist_subject [HC Anno*]
+blacklist_subject whitelist test
+	");
+
+%patterns = %is_whitelist_patterns;
+
+ok(sarun ("-L -t < data/nice/016", \&patterns_run_cb));
+ok_all_patterns();
+
+%patterns = %is_blacklist_patterns;
+
+# force us to blacklist a nice msg
+ok(sarun ("-L -t < data/nice/015", \&patterns_run_cb));
+ok_all_patterns();

Propchange: spamassassin/trunk/t/whitelist_subject.t
------------------------------------------------------------------------------
    svn:executable = *