[Mimedefang] How to count recipients in filter_recipient

Dale Moore Dale.moore at cs.cmu.edu
Tue Apr 16 07:39:08 EDT 2013

In this case, we merely 
for the rest of the recipients.

You cant tempfail individual recipients once you peek at the message
and see that it is spam.  By the time you see the message, you've already
accepted the recipients.

Different mimedefang-milter processes might handle the same message.
One milter process could handle the relay while a different one handles
the sender.  In fact, different processes could handle different recipients
of the same message.  This makes persistent variables like $rcpt_count
difficult to implement.

Dale Moore
Carnegie Mellon University

-----Original Message-----
From: mimedefang-bounces at lists.roaringpenguin.com [mailto:mimedefang-bounces at lists.roaringpenguin.com] On Behalf Of Benoit Panizzon
Sent: Tuesday, April 16, 2013 5:52 AM
To: mimedefang at lists.roaringpenguin.com
Subject: [Mimedefang] How to count recipients in filter_recipient


The situation:

Recipients have different SpamAssassin Settings:

Recipeint A => "NO FILTERING";
Recipient B => "REJECT SPAM";

Now an email arrives
mail from:<sender>
rcpt to:<Recipient A>
rcpt to:<Recipient B>

Now if this is an email that will be handled as spam, we have the problem, 
that Recipeint A does want to receive that email and Recipient B want us to 
reject it during SMTP Handshake.

We could:
Accept the Email and deliver it only to Recipient A.

Problem: If it was a false positive, that sender does not know it was not 
delivered to Recipient B. His Maillog will tell him it was successfully 
delivered. => NoGo.

We could:
Reject that email: Recipient A will complain that we filtered the email even 
though his settings tell us not to do so. = NoGo.

We only accept those recipients which have identical anti-spam settings and 
tempfail the others, forcing the sending MTA to resent them in a separate 
session. So we can then handle that session according the users settings.

sub filter_sender {
  $rcpt_count = 0;
  return ('CONTINUE',"ok");

sub filter_recipient {
  if ($rcpt_count eq 0) {
    my $filterrule = &getspamsettings($recipient);
  } else {
    return ('TEMPFAIL', "Too many Recipients") if ($rcpt_count > 50);
	return ('TEMPFAIL', "Different Spam Setting, please resend separately") if  
($filterrule != &getspamsettings($recipient));
  return ('CONTINUE',"ok");

Well, this is the basic idea. Please ignore the syntax errors :-), I just 
started with the $rcpt_count in my code. Unfortunately filter_sender and 
filter_recipient calls are carried to different filter processes. So the 
counter is not reset.

Is there a way to define some sort of over-global variable that is consistent 
for one SMTP session between all of the mimedefang processes?

Kind regards

Benoit Panizzon
I m p r o W a r e   A G    -    

Zurlindenstrasse 29             Tel  +41 61 826 93 07
CH-4133 Pratteln                Fax  +41 61 826 93 02
Schweiz                         Web  http://www.imp.ch
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list MIMEDefang at lists.roaringpenguin.com

More information about the MIMEDefang mailing list