Mailing List Archive

svn commit: r441887 - in /spamassassin/trunk: lib/Mail/SpamAssassin.pm sa-learn.raw
Author: felicity
Date: Sat Sep 9 19:08:39 2006
New Revision: 441887

URL: http://svn.apache.org/viewvc?view=rev&rev=441887
Log:
add in a post_config_text option to M::SA::new() which adds the text to the end of the read-in configs, allowing for overrides of things like use_bayes and bayes_path. the previous fix for bug 4206 broke sa-learn options which used to ignore use_bayes. bug 3799: sa-learn --dbpath was accessing the configured bayes_path, then overrode the setting for further use. however, that means we end up touching the configured db before overriding to the one requested. use the new post_config_text to get around that.

Modified:
spamassassin/trunk/lib/Mail/SpamAssassin.pm
spamassassin/trunk/sa-learn.raw

Modified: spamassassin/trunk/lib/Mail/SpamAssassin.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin.pm?view=diff&rev=441887&r1=441886&r2=441887
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin.pm Sat Sep 9 19:08:39 2006
@@ -213,6 +213,11 @@
override the settings for C<rules_filename>, C<site_rules_filename>,
and C<userprefs_filename>.

+=item post_config_text
+
+Similar to C<config_text>, this text is placed after config_text to allow an
+override of config files.
+
=item force_ipv4

If set to 1, DNS tests will not attempt to use IPv6. Use if the existing tests
@@ -1369,8 +1374,6 @@
if (!defined $self->{config_text}) {
$self->{config_text} = '';

- my $fname;
-
# read a file called "init.pre" in site rules dir *before* all others;
# even the system config.
my $siterules = $self->{site_rules_filename};
@@ -1393,25 +1396,23 @@
warn "config: could not find sys rules directory\n";
}

- $fname = $sysrules;
- if ($fname) {
- $self->{config_text} .= $self->read_cf ($fname, 'default rules dir');
+ if ($sysrules) {
+ $self->{config_text} .= $self->read_cf ($sysrules, 'default rules dir');
}

if (!$self->{languages_filename}) {
$self->{languages_filename} = $self->find_rule_support_file("languages");
}

- $fname = $siterules;
- if ($fname) {
- $self->{config_text} .= $self->read_cf ($fname, 'site rules dir');
+ if ($siterules) {
+ $self->{config_text} .= $self->read_cf ($siterules, 'site rules dir');
}

if ( $use_user_pref != 0 ) {
$self->get_and_create_userstate_dir();

# user prefs file
- $fname = $self->{userprefs_filename};
+ my $fname = $self->{userprefs_filename};
$fname ||= $self->first_existing_path (@default_userprefs_path);

if (!$self->{dont_copy_prefs}) {
@@ -1427,6 +1428,8 @@
$self->{config_text} .= $self->read_cf ($fname, 'user prefs file');
}
}
+
+ $self->{config_text} .= $self->{post_config_text} if ($self->{post_config_text});

if ($self->{config_text} !~ /\S/) {
warn "config: no configuration text or files found! please check your setup\n";

Modified: spamassassin/trunk/sa-learn.raw
URL: http://svn.apache.org/viewvc/spamassassin/trunk/sa-learn.raw?view=diff&rev=441887&r1=441886&r2=441887
==============================================================================
--- spamassassin/trunk/sa-learn.raw (original)
+++ spamassassin/trunk/sa-learn.raw Sat Sep 9 19:08:39 2006
@@ -195,6 +195,27 @@
}
}

+my $post_config = '';
+
+# kluge to support old check_bayes_db operation
+# bug 3799: init() will go r/o with the configured DB, and then dbpath needs
+# to override. Just access the dbpath version via post_config_text.
+if ( defined $bayes_override_path ) {
+ # Add a default prefix if the path is a directory
+ if ( -d $bayes_override_path ) {
+ $bayes_override_path = File::Spec->catfile( $bayes_override_path, 'bayes' );
+ }
+
+ $post_config .= "bayes_path $bayes_override_path\n";
+}
+
+# These options require bayes_scanner, which requires "use_bayes 1", but
+# that's not necessary for these commands.
+if (defined $opt{'dump'} || defined $opt{'import'} || defined $opt{'clear'} ||
+ defined $opt{'backup'} || defined $opt{'restore'}) {
+ $post_config .= "use_bayes 1\n";
+}
+
# create the tester factory
$spamtest = new Mail::SpamAssassin(
{
@@ -208,6 +229,7 @@
PREFIX => $PREFIX,
DEF_RULES_DIR => $DEF_RULES_DIR,
LOCAL_RULES_DIR => $LOCAL_RULES_DIR,
+ post_config_text => $post_config,
}
);

@@ -216,20 +238,6 @@
if (Mail::SpamAssassin::Util::am_running_on_windows()) {
binmode(STDIN); # bug 4363
binmode(STDOUT);
-}
-
-# kluge to support old check_bayes_db operation
-if ( defined $bayes_override_path ) {
-
- # Add a default prefix if the path is a directory
- if ( -d $bayes_override_path ) {
- $bayes_override_path = File::Spec->catfile( $bayes_override_path, 'bayes' );
- }
-
- # init() above ties to the db r/o and leaves it that way
- # so we need to untie before dumping (it'll reopen)
- $spamtest->finish_learner();
- $spamtest->{conf}->{bayes_path} = $bayes_override_path;
}

if ( defined $opt{'dump'} ) {