[Mimedefang] Blacklist_to or spam trap?

Stefano McGhee SMcGhee at ARCweb.com
Mon Jan 20 14:26:01 EST 2003


Hello all,
	So that all can benefit, if you choose to, here is how this little
endeavor panned out.  I was able to get this to work by inserting the code
at the end of this message into filter_begin.  What's interesting to note
is that I had to insert it at the very beginning of filter_begin, BEFORE
stream_by_recipient().  Otherwise, it didn't work.  I imagine this was
because stream by recipient breaks down the envelope recipient and doesn't
allow my code to bounce the entire message.  David, should the man page be
changed to say that stream_by_recipient() should be the first thing in
filter_begin, "in most cases"?  :-)
	Thanks to all of you who helped me figure this one out.  Perhaps
the code will be useful to someone else as well.

Cheers,

Stefano

> You cannot do this from filter_recipient.  You need to do it from
> filter_begin, because filter_recipient can (as you noticed) 
> only reject
> a particular recipient, not the whole message.
> 
> How about:
> 
> sub filter_begin {
>     my($recip);
>     foreach $recip (@Recipients) {
> 	if (is_former_employee($recip)) {
> 	    action_bounce("$recip doesn't live here any more");
> 	    return;
>         }
>     }
> }
> 
> That's way faster than running SpamAssassin.
> 
> I leave it to you to write the is_former_employee function.
> 

sub filter_begin () {
# Check for various recipients that need filtering out
    my @TrapAddr = qw(user1 user2 user3 user4);
    my ($recip, $baduser);
    foreach $recip (@Recipients) {
        foreach $baduser (@TrapAddr) {
                if ($recip =~ /^<?$baduser\@/i){
                        md_log('spam', "Message sent to $baduser dropped");
                        return action_bounce("Invalid envelope recipient");
                }
        }
     }
    # This line causes all messages that have more then one envelope
recipient
    # to be broken up and sent individually.  Done to allow people to opt
out of
    # SpamAssassin filtering later on in filter_end
    if (stream_by_recipient()) {
        return;
    }

...rest of filter begin....




More information about the MIMEDefang mailing list