On Tue, Feb 17, 2004 at 07:20:31PM +1100, Gavin Carr wrote:
> On Mon, Feb 16, 2004 at 06:39:28PM -0700, Chris Stone wrote:
> > Yes, I am trying to setup the per_user_config plugin
> > (http://www.nntp.perl.org/group/perl.qpsmtpd/963 - followup from the link
> > you noted). It's all setup, but I am to the point now of trying to figure
> > out how to now point spamassassin at the per-user/domain configs and/or what
> > the heck this config/spamassassin file contains - seems to be my 'missing
> > link' in this setup.
> 
> Yeah sorry, the docs are a bit misleading in that regard - to my knowledge 
> there's no spamassassin plugin that does that yet. I've been planning to look 
> at either the stock spamassassin plugin or Aran's spamassassin_spamc (?) and 
> make one or both per_user_config-aware. But haven't got there as yet.

Okay - from tonight's quick-hack-on-the-train department, attached is a
patch against Aran's spamassassin_spamc plugin (http://projects.bluefeet.net)
which makes it per_user_config aware, turned on via the config/plugins line:

  spamassassin_spamc per_recipient 1

It also adds a 'filter' argument (default 1) to allow the plugin to be off
by default (and turned back on per-recipient via the config file, of course):

  spamassassin_spamc per_recipient 1 filter 0

The spamassassin_spamc config file can contain the reject_threshold, 
munge_subject_threshold, and filter arguments, one per line, keys and
values space-separated.

A gotcha is that in per_recipient mode the spamassassin_spamc line has to
be *before* the check_relay line - I tend to move the check_relay line 
immediately before the qmail-queue line these days.

Only very lightly tested at this point - handle with care. :-)

Cheers,
Gavin

-- 
Open Fusion P/L - Open Source Business Solutions [ Linux - Perl - Apache ]
ph:  02 9875 5032                        fax: 02 9875 4317
web: http://www.openfusion.com.au        mob: 0403 171712
- Fashion is a variable, but style is a constant - Programming Perl
--- spamassassin_spamc.dist     2004-02-17 19:36:12.000000000 +1100
+++ spamassassin_spamc  2004-02-17 23:00:08.000000000 +1100
@@ -11,14 +11,32 @@
   $self->log(0, "Bad parameters for the spamassassin plugin")
     if @_ % 2;
 
-  %{$self->{_args}} = @args;
+  %{$self->{_args}} = ( filter => 1, @args);
+  $self->register_hook("rcpt", "load_config") 
+    if $self->{_args}->{per_recipient};
 
   $self->register_hook("data_post", "check_spam_reject")
-    if $self->{_args}->{reject_threshold};
+    if $self->{_args}->{reject_threshold} or $self->{_args}->{per_recipient};
 
   $self->register_hook("data_post", "check_spam_munge")
-    if $self->{_args}->{munge_subject_threshold};
+    if $self->{_args}->{munge_subject_threshold} or $self->{_args}->{per_recipient};
+}
+
+sub load_config {
+  my ($self, $transaction, $rcpt) = @_;
 
+  # Setup only once (data plugin: must assume all recipients use the same config!)
+  return (DECLINED) if $transaction->notes('spamassassin_spamc_config');
+  $transaction->notes('spamassassin_spamc_config', 1);
+
+  # Setup config from defaults and per_recipient spamassassin config
+  my @config = $self->qp->config('spamassassin_spamc', { rcpt => $rcpt });
+  $self->{_args} = { 
+    %{$self->{_args}},
+    @config ? map { split /\s+/, $_, 2 } @config : ()
+  };
+  $self->log(4, "spamassassin_spamc config: " . join(', ',map { $_ . '=' . 
$self->{_args}->{$_} } sort keys %{$self->{_args}}));
+  return (DECLINED);
 }
 
 sub check_spam {
@@ -26,6 +44,7 @@
 
   return (DECLINED) if $transaction->body_size > 250_000;
   # spamc's default reject threshhold is 250k
+  return (DECLINED) unless $self->{_args}->{filter};
 
   $transaction->body_resetpos;
   open2(\*SR, \*SW, "/usr/bin/spamc -c");

@@ -46,6 +65,7 @@
 
 sub check_spam_reject {
        my ($self, $transaction) = @_;
+        return DECLINED unless $self->{_args}->{reject_threshold};
        if( $transaction->notes('spam_score') >= $self->{_args}->{reject_threshold} ){
                return (DENY, "spam score exceeded threshold");
        }
@@ -54,6 +74,7 @@
 
 sub check_spam_munge {
        my ($self, $transaction) = @_;
+        return DECLINED unless $self->{_args}->{munge_subject_threshold};
        if( $transaction->notes('spam_score') < 
$self->{_args}->{munge_subject_threshold} ){
                return DECLINED;
        }

Reply via email to