[Mimedefang] limit Recipients for auth user

Benoit Panizzon benoit.panizzon at imp.ch
Fri Nov 27 08:39:10 EST 2015

Hi Roman

At the start of your mimedefang-filter, where the 'use' statements are,
add the Perl Storable Module. (You need to have the storable
perl module installed for this to work).

require Storable;

You probably have sub filter_initialize {} and sub filter_cleanup {}
somewhere in your code. Just add those two subs there:

sub store_vars {
         my($vars) = @_;
         Storable::store($vars, 'vars.db');

sub load_vars {
         my $vars = {};
         if(-f 'vars.db') {
                 $vars = Storable::retrieve('vars.db');
         return $vars;

Then replace your filter_recipient with this very basic one:

sub filter_recipient {
  my ($recipient, $sender, $ip, $hostname, $first, $helo, $rcpt_mailer,
  $rcpt_host, $rcpt_addr) = @_;
  my $vars=&load_vars();

  if(!defined($vars->{imp_rcpt_count})) {

  md_syslog('warning',"COUNTING: Auth-By: " .
  $SendmailMacros{auth_authen} ." Recipient $recipient is number: " .

  return ('CONTINUE', "ok");

But this is basicly just usefull if you want do act differently when
you reached a specific number of recipients, like limiting the number
of emails sent by a user during a certain time. If you just want to
know how many recipients the email goes to, you can use the size of
the array @Recipients in filter_begin, filter or filter_end.

-Benoît Panizzon-
I m p r o W a r e   A G    -    Leiter Commerce Kunden

Zurlindenstrasse 29             Tel  +41 61 826 93 00
CH-4133 Pratteln                Fax  +41 61 826 93 01
Schweiz                         Web  http://www.imp.ch

More information about the MIMEDefang mailing list