You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by jm...@apache.org on 2007/08/20 20:55:04 UTC
svn commit: r567784 - in
/spamassassin/branches/jm_bug_3852_two_level_configs:
lib/Mail/SpamAssassin/ lib/Mail/SpamAssassin/Conf/
lib/Mail/SpamAssassin/Plugin/ lib/Mail/SpamAssassin/Util/ t/
Author: jm
Date: Mon Aug 20 11:55:01 2007
New Revision: 567784
URL: http://svn.apache.org/viewvc?rev=567784&view=rev
Log:
more stuff working with double-layer Conf hashes
Modified:
spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf.pm
spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf/Parser.pm
spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Plugin/Check.pm
spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierArray.pm
spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierHash.pm
spamassassin/branches/jm_bug_3852_two_level_configs/t/two_tier_config.t
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf.pm?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf.pm (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf.pm Mon Aug 20 11:55:01 2007
@@ -3219,6 +3219,8 @@
# create a new config tier for user configuration
sub push_tier {
my ($self) = @_;
+ dbg ("config: pushing new tier");
+
$self->{tiers}->[1] = $self->new_tier();
$self->{activetier} = $self->{tiers}->[1];
$self->create_lookup_doublehashes();
@@ -3232,6 +3234,8 @@
# and delete it once the user is no longer active
sub pop_tier {
my ($self) = @_;
+ dbg ("config: popping tier");
+
%{$self} = (); # clears the top tier entirely
$self->{ACTIVETIER} = 0;
@@ -3271,15 +3275,11 @@
sub new_two_tier_hash {
my ($self, $name, $t0, $t1) = @_;
if (!defined $t0) {
- if (!defined $self->{tiers}->[0]->{$name}) {
- $self->{tiers}->[0]->{$name} = { };
- }
+ $self->{tiers}->[0]->{$name} ||= { };
$t0 = $self->{tiers}->[0]->{$name};
}
if (!defined $t1) {
- if (!defined $self->{tiers}->[1]->{$name}) {
- $self->{tiers}->[1]->{$name} = { };
- }
+ $self->{tiers}->[1]->{$name} ||= { };
$t1 = $self->{tiers}->[1]->{$name};
}
@@ -3332,7 +3332,7 @@
sub set_score_set {
my ($self, $set) = @_;
- $self->{activetier}->{scoreset_current} = $set;
+ $self->{scoreset_current} = $set;
# use TwoTierHash objects to represent certain hashes; lookups
# in these "hashes" will fall through correctly to the other tiers.
@@ -3345,7 +3345,7 @@
sub get_score_set {
my($self) = @_;
- return $self->{activetier}->{scoreset_current};
+ return $self->{scoreset_current};
}
sub delete_rule {
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf/Parser.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf/Parser.pm?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf/Parser.pm (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Conf/Parser.pm Mon Aug 20 11:55:01 2007
@@ -682,12 +682,12 @@
sub set_template_append {
my ($conf, $key, $value, $line) = @_;
if ( $value =~ /^"(.*?)"$/ ) { $value = $1; }
- $conf->{activetier}->{$key} .= $value."\n";
+ $conf->{$key} .= $value."\n";
}
sub set_template_clear {
my ($conf, $key, $value, $line) = @_;
- $conf->{activetier}->{$key} = '';
+ $conf->{$key} = '';
}
###########################################################################
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Plugin/Check.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Plugin/Check.pm?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Plugin/Check.pm (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Plugin/Check.pm Mon Aug 20 11:55:01 2007
@@ -792,34 +792,31 @@
sub do_head_eval_tests {
my ($self, $pms, $priority) = @_;
- return unless (defined($pms->{conf}->{head_evals}->{$priority}));
$self->run_eval_tests ($pms, $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS,
'head_evals', '', $priority);
}
sub do_body_eval_tests {
my ($self, $pms, $priority, $bodystring) = @_;
- return unless (defined($pms->{conf}->{body_evals}->{$priority}));
$self->run_eval_tests ($pms, $Mail::SpamAssassin::Conf::TYPE_BODY_EVALS,
'body_evals', 'BODY: ', $priority, $bodystring);
}
sub do_rawbody_eval_tests {
my ($self, $pms, $priority, $bodystring) = @_;
- return unless (defined($pms->{conf}->{rawbody_evals}->{$priority}));
$self->run_eval_tests ($pms, $Mail::SpamAssassin::Conf::TYPE_RAWBODY_EVALS,
'rawbody_evals', 'RAW: ', $priority, $bodystring);
}
sub do_full_eval_tests {
my ($self, $pms, $priority, $fullmsgref) = @_;
- return unless (defined($pms->{conf}->{full_evals}->{$priority}));
$self->run_eval_tests($pms, $Mail::SpamAssassin::Conf::TYPE_FULL_EVALS,
'full_evals', '', $priority, $fullmsgref);
}
sub run_eval_tests {
- my ($self, $pms, $testtype, $confhashname, $prepend2desc, $priority, @extraevalargs) = @_;
+ my ($self, $pms, $testtype, $confhashname,
+ $prepend2desc, $priority, @extraevalargs) = @_;
return if $self->{main}->call_plugins("have_shortcircuited",
{ permsgstatus => $pms });
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierArray.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierArray.pm?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierArray.pm (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierArray.pm Mon Aug 20 11:55:01 2007
@@ -31,6 +31,7 @@
# and all reads from tier 1, and if not found there, tier 0. In
# effect tier 1 overrides tier 0. Note that writes will NEVER affect
# tier 0; create a new object to modify the contents of that tier.
+# This is different from how TwoTierHash works (which can be written to)
###########################################################################
@@ -48,7 +49,7 @@
sub STORE {
my ($self, $i, $v) = @_;
my $a0size = scalar @{$self->{a0}};
- if ($i > $a0size) {
+ if ($i >= $a0size) {
$self->{a1}->[$i - $a0size] = $v;
} else {
# a write to the a0 area! we cannot do this!
@@ -59,7 +60,7 @@
sub FETCH {
my ($self, $i) = @_;
my $a0size = scalar @{$self->{a0}};
- if ($i > $a0size) {
+ if ($i >= $a0size) {
return $self->{a1}->[$i - $a0size];
} else {
return $self->{a0}->[$i];
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierHash.pm
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierHash.pm?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierHash.pm (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/lib/Mail/SpamAssassin/Util/TwoTierHash.pm Mon Aug 20 11:55:01 2007
@@ -40,7 +40,7 @@
my $self = {
h0 => $h0,
h1 => $h1,
- activetier => $h1
+ activetier => $h0
};
return bless $self, $class;
}
Modified: spamassassin/branches/jm_bug_3852_two_level_configs/t/two_tier_config.t
URL: http://svn.apache.org/viewvc/spamassassin/branches/jm_bug_3852_two_level_configs/t/two_tier_config.t?rev=567784&r1=567783&r2=567784&view=diff
==============================================================================
--- spamassassin/branches/jm_bug_3852_two_level_configs/t/two_tier_config.t (original)
+++ spamassassin/branches/jm_bug_3852_two_level_configs/t/two_tier_config.t Mon Aug 20 11:55:01 2007
@@ -18,7 +18,7 @@
use lib '.'; use lib 't';
use SATest; sa_t_init("two_tier_config");
-use Test; BEGIN { plan tests => 12 };
+use Test; BEGIN { plan tests => 33 };
use strict;
require Mail::SpamAssassin;
@@ -27,6 +27,7 @@
my $sa = create_saobj({'dont_copy_prefs' => 1, post_config_text => q{
+ allow_user_rules 1
header LAST_RCVD_LINE Received =~ /www.fasttrec.com/
header MESSAGEID_MATCH MESSAGEID =~ /fasttrec.com/
header ENV_FROM EnvelopeFrom =~ /jm.netnoteinc.com/
@@ -34,13 +35,15 @@
uri URI_RULE /WWW.SUPERSITESCENTRAL.COM/i
body BODY_LINE_WRAP /making obscene amounts of money from the/
header RELAYS X-Spam-Relays-Untrusted =~ / helo=www.fasttrec.com /
-
required_score 7
rewrite_header Subject FOO
add_header spam Foo Hello
whitelist_from jm@example.com
blacklist_from n1@example.com
score URI_RULE 10
+ redirector_pattern /^http:\/\/foo.com\/(.*)$/i
+ clear_report_template
+ report Foo
}}); $sa->init(0);
@@ -49,7 +52,13 @@
ok ($sa->{conf}->{headers_spam}->{Foo}, "Hello");
ok ($sa->{conf}->{whitelist_from}->{'jm@example.com'}, '^jm\@example\.com$');
ok ($sa->{conf}->{blacklist_from}->{'n1@example.com'}, '^n1\@example\.com$');
+ok grep { $_ eq '^jm\@example\.com$' } values %{$sa->{conf}->{whitelist_from}};
+
ok ($sa->{conf}->{scores}->{URI_RULE}, 10);
+ok grep { m!http:\\/\\/foo.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+ok !grep { m!http:\\/\\/bar.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+
+ok ($sa->{conf}->{report_template}, "Foo\n");
# ---------------------------------------------------------------------------
@@ -63,6 +72,10 @@
unblacklist_from n1@example.com
whitelist_from n2@example.com
score URI_RULE 5
+ redirector_pattern /^http:\/\/bar.com\/(.*)$/i
+
+ # should append
+ report Bar
}; close OUT or die;
$sa->read_scoreonly_config("log/localrules.tmp/tier1.cf");
@@ -75,6 +88,10 @@
ok ($sa->{conf}->{whitelist_from}->{'n2@example.com'}, '^n2\@example\.com$');
ok ($sa->{conf}->{blacklist_from}->{'n1@example.com'}, undef);
ok ($sa->{conf}->{scores}->{URI_RULE}, 5);
+ok grep { m!http:\\/\\/foo.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+ok grep { m!http:\\/\\/bar.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+
+ok ($sa->{conf}->{report_template}, "Foo\nBar\n");
# ---------------------------------------------------------------------------
@@ -87,6 +104,10 @@
ok ($sa->{conf}->{blacklist_from}->{'n1@example.com'}, '^n1\@example\.com$');
ok ($sa->{conf}->{blacklist_from}->{'n2@example.com'}, undef);
ok ($sa->{conf}->{scores}->{URI_RULE}, 10);
+ok grep { m!http:\\/\\/foo.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+ok !grep { m!http:\\/\\/bar.com\\/! } @{$sa->{conf}->{redirector_patterns}};
+
+ok ($sa->{conf}->{report_template}, "Foo\n");
# ---------------------------------------------------------------------------