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/05/07 17:51:12 UTC
svn commit: r169087 - in /spamassassin/trunk: lib/Mail/SpamAssassin.pm
t/SATest.pm t/razor2.t
Author: parker
Date: Sat May 7 08:51:11 2005
New Revision: 169087
URL: http://svn.apache.org/viewcvs?rev=169087&view=rev
Log:
Bug 4311: Added ability to parse multiple .pre files and then wrote out a test .pre file that loads the Razor2 plugin for the razor2 test
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin.pm
spamassassin/trunk/t/SATest.pm
spamassassin/trunk/t/razor2.t
Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/lib/Mail/SpamAssassin.pm?rev=169087&r1=169086&r2=169087&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Sat May 7 08:51:11 2005
@@ -1302,17 +1302,10 @@
$sysrules ||= $self->first_existing_path (@default_rules_path);
if ($siterules) {
- $fname = File::Spec->catfile ($siterules, "init.pre");
-
- if (-f $fname) {
- $self->{config_text} .= $self->read_cf ($fname, 'site rules init.pre');
-
- } else {
- $fname = File::Spec->catfile ($sysrules, "init.pre");
- if (-f $fname) {
- $self->{config_text} .= $self->read_cf ($fname, 'sys rules init.pre');
- }
- }
+ $self->{config_text} .= $self->read_pre($siterules, 'site rules pre files');
+ }
+ if ($sysrules) {
+ $self->{config_text} .= $self->read_pre($sysrules, 'sys rules pre files');
}
$fname = $sysrules;
@@ -1395,6 +1388,27 @@
return $txt;
}
+
+sub read_pre {
+ my ($self, $path, $desc) = @_;
+
+ return '' unless defined ($path);
+
+ dbg("config: using \"$path\" for $desc");
+ my $txt = '';
+
+ if (-d $path) {
+ foreach my $file ($self->get_pre_files_in_dir($path)) {
+ $txt .= read_cf_file($file); # ok to use read_cf_file at this point
+ }
+
+ } elsif (-f $path && -s _ && -r _) {
+ $txt .= read_cf_file($path);
+ }
+
+ return $txt;
+}
+
sub read_cf_file {
my($path) = @_;
my $txt = '';
@@ -1563,6 +1577,16 @@
opendir(SA_CF_DIR, $dir) or warn "config: cannot opendir $dir: $!\n";
my @cfs = grep { /\.cf$/i && -f "$dir/$_" } readdir(SA_CF_DIR);
closedir SA_CF_DIR;
+
+ return map { "$dir/$_" } sort { $a cmp $b } @cfs;
+}
+
+sub get_pre_files_in_dir {
+ my ($self, $dir) = @_;
+
+ opendir(SA_PRE_DIR, $dir) or warn "config: cannot opendir $dir: $!\n";
+ my @cfs = grep { /\.pre$/i && -f "$dir/$_" } readdir(SA_PRE_DIR);
+ closedir SA_PRE_DIR;
return map { "$dir/$_" } sort { $a cmp $b } @cfs;
}
Modified: spamassassin/trunk/t/SATest.pm
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/SATest.pm?rev=169087&r1=169086&r2=169087&view=diff
==============================================================================
--- spamassassin/trunk/t/SATest.pm (original)
+++ spamassassin/trunk/t/SATest.pm Sat May 7 08:51:11 2005
@@ -195,6 +195,16 @@
$scr_pref_args = "-p log/tst.cf";
}
+# creates a .pre file in the localrules dir to be parsed alongside init.pre
+# make it zz_* just to make sure it is parse last
+
+sub tstpre {
+ my $lines = shift;
+
+ open (OUT, ">log/localrules.tmp/zz_tst.pre") or die;
+ print OUT $lines; close OUT;
+}
+
# Run spamassassin. Calls back with the output.
# in $args: arguments to run with
# in $read_sub: callback for the output (should read from <IN>).
Modified: spamassassin/trunk/t/razor2.t
URL: http://svn.apache.org/viewcvs/spamassassin/trunk/t/razor2.t?rev=169087&r1=169086&r2=169087&view=diff
==============================================================================
--- spamassassin/trunk/t/razor2.t (original)
+++ spamassassin/trunk/t/razor2.t Sat May 7 08:51:11 2005
@@ -36,6 +36,10 @@
}
}
+tstpre ("
+loadplugin Mail::SpamAssassin::Plugin::Razor2
+");
+
sarun ("-t < data/spam/001", \&patterns_run_cb);
skip_all_patterns($razor_not_available);