I needed the feature to change spamassassin rules on a per policy-bank base.
So I created the attached patch, it would be nice if it can get integrated
into the next amavisd version. Just two notes:
- The file gets loaded via spamassassins read_scoreonly_config() function,
under normal circumstances you can only add score changes here, but no new
rules. If you need this you have to define "allow_user_rules" somewhere in
your global config. This file can never contain any administrator settings.
(I have a spamassassin module available that makes this possible, e.g. for
defining a policy-bank based bayes db - just ask me if you need it).
- Since we reuse the SA object during lifetime of the amavis child settings
from policy-banks can leak into other policy-banks (which is normally not
what you want). So I safe the configstate before loading the rules file and
restore it after parsing the mail.
How to use it:
Just define another SA rulesfile in your policy-bank:
$policy_bank{'foo'} = {
sa_site_rules_filename = '/etc/amavis/foo.sa',
}
Thats all :).
Thanks for your attention
Alex
diff -r 8574935af18f amavisd
--- a/amavisd Tue May 20 19:30:57 2008 +0200
+++ b/amavisd Wed Jun 04 17:00:18 2008 +0200
@@ -339,6 +339,8 @@
%admin_maps_by_ccat %warnrecip_maps_by_ccat
%always_bcc_by_ccat %dsn_bcc_by_ccat
%addr_extension_maps_by_ccat %addr_rewrite_maps_by_ccat
+
+ $sa_site_rules_filename
)],
'confvars' => # global settings (not per-policy, not per-recipient)
[qw(
@@ -20256,6 +20258,18 @@
my($sa_version_num); # turn '3.1.8-pre1' into 3.001008
$sa_version_num = sprintf("%d.%03d%03d", $1,$2,$3)
if $sa_version =~ /^(\d+)\.(\d+)(?:\.(\d+))/; # ignore trailing non-digits
+
+ my %conf_backup = ();
+ my ($sa_site_rule_file) = c('sa_site_rules_filename');
+
+ if ($sa_site_rule_file && $sa_version_num >= 3) {
+ $spamassassin_obj->copy_config(undef, \%conf_backup) ||
+ die "config: error returned from copy_config!\n";
+ do_log(4,"SA Config saved");
+ $spamassassin_obj->read_scoreonly_config ($sa_site_rule_file);
+ do_log(4,"SA ScoreOnlyConfig loaded");
+ }
+
my($spam_level,$sa_tests,$spam_report,$spam_summary,%supplementary_info);
my($fh) = $msginfo->mail_text;
$fh->seek($msginfo->skip_bytes, 0) or die "Can't rewind mail file: $!";
@@ -20330,6 +20344,11 @@
} or do { $eval_stat = $@ ne '' ? $@ : "errno=$!" };
$which_section = 'SA finish';
+ if ($sa_site_rule_file && $sa_version_num >= 3) {
+ $spamassassin_obj->copy_config(\%conf_backup, undef) ||
+ die "config: error returned from copy_config!\n";
+ do_log(4,"SA Config restored");
+ }
if (defined $per_msg_status)
{ $per_msg_status->finish; undef $per_msg_status }
if (defined $mail_obj && $sa_version_num >= 3)
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
AMaViS-user mailing list
AMaVi...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amavis-user
AMaViS-FAQ:http://www.amavis.org/amavis-faq.php3
AMaViS-HowTos:http://www.amavis.org/howto/
> I needed the feature to change spamassassin rules on a per policy-bank base.
> So I created the attached patch, it would be nice if it can get integrated
> into the next amavisd version. Just two notes:
nice patch, i have one question
can this olso make pr recipient bayes from amavisd when bayes is in sql ?
if so i like have the plugin
Benny Pedersen
Need more webspace ? http://www.servage.net/?coupon=cust37098
>
> On Thu, June 5, 2008 08:44, Alexander Wirt wrote:
>
> > I needed the feature to change spamassassin rules on a per policy-bank base.
> > So I created the attached patch, it would be nice if it can get integrated
> > into the next amavisd version. Just two notes:
>
> nice patch, i have one question
>
> can this olso make pr recipient bayes from amavisd when bayes is in sql ?
>
> if so i like have the plugin
Basically that should be possible. The plugin is a dirty hack that makes
administrative options non-administrative. This can be done with any option.
Especially with bayes_sql_override_username which should do the trick.
I never said its nice or anything else. But it works :).
I hacked together a version that can override bayes_sql_override_username.
Just add o_bayes_sql_override_username into your policy based SA config.
This is untested stuff, so please take care and use debugging output to
verify if its working.
Hmmm, after looking into Conf.pm I saw that bayes_sql_override_username is
not flagged as an administrative command. So maybe you don't need the plugin.
Anyway look here:
http://ned.snow-crash.org/~formorer/O_Bayes_SQL_Override_username.pm
Alex