[Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread Benoit Panizzon
Hello

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.

Solution:
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 {
$rcpt_count++;
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 PrattelnFax  +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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread Dale Moore
In this case, we merely 
  main::delete_recipient($recipient_A); 
then
  main::action_accept()
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-boun...@lists.roaringpenguin.com 
[mailto:mimedefang-boun...@lists.roaringpenguin.com] On Behalf Of Benoit 
Panizzon
Sent: Tuesday, April 16, 2013 5:52 AM
To: mimedefang@lists.roaringpenguin.com
Subject: [Mimedefang] How to count recipients in filter_recipient

Hello

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.

Solution:
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 {
$rcpt_count++;
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 PrattelnFax  +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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

___
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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread Benoit Panizzon
Hi Dale

 In this case, we merely
   main::delete_recipient($recipient_A);
 then
   main::action_accept()
 for the rest of the recipients.

This is what we don't want to do. Immagine it is a false positive.
The Maillogs of the sender, any maybe even an MDN Messages confirm, the email 
has been received by the server. So that email just disappears. This is what 
we want to avoid.

 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.

Yes, but I know what spam action (reject or accept) the individual recipient 
has. So I can first handel alle the recipients who want to reject spam and 
tempfail all the others, and the vice versa. I do not need to know if the 
email will be handled as spam at that point. I just make sure, that if it will 
be handled as spam, I only have recipients that want spam rejected.

 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.

After some more Googleing I think I found a solution.
For each smtp session, MIMEDefang uses a different spool directory and CWD's 
to that directory.
So I am now writing the recipient and spam settings to a file in the actual 
CWD and on each recipient I can get the count and what kind of recipients I 
accept from that file.

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 PrattelnFax  +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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread David F. Skoll
On Tue, 16 Apr 2013 11:51:50 +0200
Benoit Panizzon benoit.paniz...@imp.ch wrote:

 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?

No, but you can store persistent state in a file.  See the
MAINTAINING STATE section of mimedefang-filter(5).  You could also use
a database, though that may be overkill.

Regards,

David.
___
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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread kd6lvw
--- On Tue, 4/16/13, Dale Moore dale.mo...@cs.cmu.edu wrote:
 In this case, we merely main::delete_recipient($recipient_A); 
 then main::action_accept() 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.

Look at how the Recipients array is defined during filter_recipient:

[A]fter calling read_commands_file within filter_recipient, the current 
recipient under consideration is in the final position of the array, at 
$Recipients[-1], while any previous (and accepted) recipients are at the 
beginning of the array, that is, in @Recipients[0 .. $#Recipients-1].

At the array lists only accepted recipients, one can easily reject or tempfail 
any future recipient that has a different spam policy than the first recipient 
(and only the first need be checked, since one checked for differences with the 
other elements as the array was built -- one recipient at a time).
___
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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang


Re: [Mimedefang] How to count recipients in filter_recipient

2013-04-16 Thread Dale Moore
My mistake.  Thanks for pointing this out.

Dale Moore

-Original Message-
From: mimedefang-boun...@lists.roaringpenguin.com 
[mailto:mimedefang-boun...@lists.roaringpenguin.com] On Behalf Of 
kd6...@yahoo.com
Sent: Tuesday, April 16, 2013 2:32 PM
To: mimedefang@lists.roaringpenguin.com
Subject: Re: [Mimedefang] How to count recipients in filter_recipient

--- On Tue, 4/16/13, Dale Moore dale.mo...@cs.cmu.edu wrote:
 In this case, we merely main::delete_recipient($recipient_A); 
 then main::action_accept() 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.

Look at how the Recipients array is defined during filter_recipient:

[A]fter calling read_commands_file within filter_recipient, the current 
recipient under consideration is in the final position of
the array, at $Recipients[-1], while any previous (and accepted) recipients are 
at the beginning of the array, that is, in
@Recipients[0 .. $#Recipients-1].

At the array lists only accepted recipients, one can easily reject or tempfail 
any future recipient that has a different spam policy
than the first recipient (and only the first need be checked, since one checked 
for differences with the other elements as the array
was built -- one recipient at a time).
___
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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

___
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@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang