[Mimedefang] Running SA checks on specific users only

Kelson Vibber kelson at speed.net
Thu May 29 19:04:00 EDT 2003


Jason Englander <jason at englanders.cc> wrote:
>On Wed, 28 May 2003 listuser at numbnuts.net wrote:
> > filtering.  Is it possible to only run SA checks on those users and not
> > the rest (which are Sendmail aliases)?

If you're likely to have a large number of users who do/don't want 
SpamAssassin, or the list is likely to change much, you can try this:  I 
have a text file with a list of addresses (in my case those who have opted 
out, in your case those who have opted in).  When a MD slave starts, it 
loads those addresses into a hash table.  (First, it's a lot faster to look 
for a hash key than to look through a list; second, I use the value to 
indicate whether someone has a custom threshold score for dropping spam).

So to modify this code...
>my $use_spamassassin = 0;
>foreach my $recip (@Recipients) {
>   $recip = lc($recip);
>   $recip =~ tr/<>//d;

$use_spamassassin = 1 if ( exists($SAUser{$recip}) );

>}

This makes it more manageable for when the list of SA/non-SA users changes.

>If you truly only want it run on certain users, and not just messages
>where one of those users is one of the recipients, use
>stream_by_recipient()

A way to get away with this more efficiently is to only stream the message 
when you have to.  I have a function, check_recipients_custom, which 
essentially runs the code above except it returns a 1 or 0 depending on 
whether any have been found, instead of setting a variable.  Additionally, 
I check whether the sending relay is local or not. (There are several ways 
to do this, so I'll show it as the made-up function "not_a_local_relay" 
here)  Using that, at the start of filter_begin I have (essentially):

         return if ( not_a_local_relay() && 
check_recipients_custom(@Recipients) && stream_by_recipient() );

Due to the wonders of short-circuit evaluation, this manages to (A) call 
stream_by_recipient if and only if it is incoming mail for people who want 
SpamAssassin, and (B) only return if streaming was successful.

Of course, it would be even better if it only streamed the message if it 
was a *mix* of users who do and don't want SpamAssassin  This should be 
pretty easy, but I just haven't gotten around to it.


Kelson Vibber
SpeedGate Communications <www.speed.net>  




More information about the MIMEDefang mailing list