filtering on two headers at once / blocking out-of-office replies to a list

Mark Martinec Mark.Martinec+amavis at ijs.si
Wed Dec 14 19:43:38 CET 2011


Daniel,

> We have a departmental mail server set up with a postfix/amavisd-new mail
> gateway.
> 
> The problem I'm having is that out-of-office replies from some members of
> one of our mailing lists are being sent to the list itself rather than the
> sender of a specific message.
> 
> I don't want to block all out-of-office messages from coming in, only those
> addressed to the mailing list itself. I also don't want to block all
> messages to the list address, as that would prevent some members from
> sending messages to the list.
> 
> What I've come up with so far is that the while the out-of-office messages
> ostensibly come from the user, the Return-Path header is set to <>:
> 
> Return-Path: <>
> 
> I'd like to set up a filter that says:
> 
> if Return-Path: = <> and To: = the_list_address
> then DISCARD
> 
> Unfortunately, postfix header_checks only operate on one header at a time.
> Is there some way I could set up a custom filter in amavisd that would do
> what I want? I've been digging through the documentation, and while it
> *seems* possible I'm still not seeing what path I should investigate.


Yes, a custom hook could do the trick:

amavisd.conf:
[...]
  include_config_files('/etc/amavisd-custom.conf');
[...]


/etc/amavisd-custom.conf :

package Amavis::Custom;
use strict;
BEGIN {
  import Amavis::Conf qw(:platform c cr ca);
  import Amavis::Util qw(do_log);
}

sub new {
  my($class,$conn,$msginfo) = @_;
  bless {}, $class;
}

sub checks {
  my($self,$conn,$msginfo) = @_;
  my(@rfc2822_to) = do { my $f = $msginfo->rfc2822_to; ref $f ? @$f : $f };
  if ($msginfo->is_auto &&
      grep(lc($_) eq lc('a.mailing.list at example.org'), @rfc2822_to)) {
    do_log(5, "custom checks: blocking an autoresponse");
    for my $r (@{$msginfo->per_recip_data}) {  # for each recipient
      next  if $r->recip_done;  # already dealt with
      $r->recip_destiny(D_DISCARD);
      $r->recip_smtp_response('554 5.7.0 Auto-responses to a mailing list '.
                              'are rejected');
      $r->recip_done(1);
      $r->spam_tests([])  if !defined $r->spam_tests;
      unshift(@{$r->spam_tests}, \'AM.AUTORESP');
    }
  }
}

1;  # insure a defined return



If using SpamAssassin, using a meta rule would be more straightforward.

  Mark


More information about the amavis-users mailing list