Discussion:
[Mimedefang] limit Recipients for auth user
Roman Pretory
2015-11-27 10:27:30 UTC
Permalink
Greetings all,
I need to limit the Recipients from to, cc bcc  for auth user in the filter_recipient procedure .....is this possible?
Realy great it would be, to get the count for each to, cc, bcc in the part between  ##
filter_recipient () {
.....
if (defined($SendmailMacros{"auth_authen"})) {
##
my $recipient_to_count = ??;
my $recipient_cc_count = ??;
my $recipient_bcc_count = ??;
##
return("ACCEPT_AND_NO_MORE_FILTERING", "OK");
}
....
}
Thanks for help
RP


_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/ma
Benoit Panizzon
2015-11-27 11:01:26 UTC
Permalink
Hi Roman
Post by Roman Pretory
my $recipient_to_count = ??;
my $recipient_cc_count = ??;
my $recipient_bcc_count = ??;
I just re-read your email. I guess you want to distinguish the
different types of recipient (to,cc and bcc).

No, unfortunately this is not possible in filter_recipient as this
processes the rcpt to: commands from the MTA.

It would somehow unreliably be possible in filter or filter_end when
you get the message body. But you should not find BCC: Lines in the
body. Or the email client used to send that email is just broken and
discloses the BCC recipients.

So never trust the content of the email body regarding recipients.

Hmm, I should try adding this recipient to my email bodies :-)

To: ';drop database email;' <***@example.com>

-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
______________________________________________________

_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin
Benoit Panizzon
2015-11-27 10:55:52 UTC
Permalink
Hi Roman
Post by Roman Pretory
I need to limit the Recipients from to, cc bcc  for auth user in the
filter_recipient procedure .....is this possible? Realy great it
would be, to get the count for each to, cc, bcc in the part between
Sure it is. From the viewpoint of the SMTP Transfer, rcpt to: does not
distunguish between to, cc or bcc. All are just recipients.

[...]
require Storable;
[...]

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;
}

sub filter_recipient {
my ($recipient, $sender, $ip, $hostname, $first, $helo, $rcpt_mailer,
$rcpt_host, $rcpt_addr) = @_;
read_commands_file();
my $vars=&load_vars();
my($s_user,$s_domain) = split(/\@/,$SendmailMacros{auth_authen});
my $anonymous=0;
$anonymous = 1 if ($SendmailMacros{auth_authen} eq '');
if(!defined($vars->{imp_rcpt_count})) {
$vars->{imp_rcpt_count}=1;
}

[...]

if ($vars->{imp_rcpt_count} > 10) {
$vars->{imp_rcpt_count}++;
&store_vars($vars);
return ('TEMPFAIL', "Too many recipients: " .
$vars->{imp_rcpt_count}, 452, '4.5.3');
}
$vars->{imp_rcpt_count}++;
&store_vars($vars);
return ('CONTINUE', "ok");
};


I also store the count in a database for the last hour. So I can limit
the number of recipients per hour per authenticated user, and per ip
per hour for non authenticated users. For the later of course the
number is much smaler and the are being tempfailed with: "Please use
SMTP Authentication to send emails to more recipeints".

The vars.db is being stored in the MIMEDefang spoold dir of the email
being processed. So it's not getting mixed up with other emails.
MIMEDefang removes the spool directory after processing, so vars.db is
not left behind.

-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
______________________________________________________

_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mime
Roman Pretory
2015-11-27 13:11:33 UTC
Permalink
Hello Benoît

Thanks for your answer.
Are you sure that you forgot notthing from your code??

Because i try and it don't work :-(
I need at first only to log.

The parts I used below:

if ($Features{"SpamAssassin"}) {
spam_assassin_init()->compile_now(1) if defined(spam_assassin_init());
}

require ("/etc/mail/mimedefang-config");
++require Storable;
....
++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;
++}

...
sub filter_recipient{
($recipient, $sender, $ip, $name, $firstRecip, $helo, $rcpt_mailer, $rcpt_host, $rcpt_addr)= @_;
read_commands_file();
++ my $vars=&load_vars();
++if(!defined($vars->{imp_rcpt_count})) {$vars->{imp_rcpt_count}=1; }
++ md_syslog 'info', "COUNT RECIPIENT: ".$vars->{imp_rcpt_count};

Thanks
RP



_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mimed
Benoit Panizzon
2015-11-27 13:16:45 UTC
Permalink
Hi Roman
Post by Roman Pretory
Are you sure that you forgot notthing from your code??
Because i try and it don't work :-(
It was not working code. It was just a quick copy-paste from parts of
my code.

-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
______________________________________________________

_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roar
Roman Pretory
2015-11-27 13:24:02 UTC
Permalink
Hello Benoît

Please ,Is it maybe possible to get a slow copy and past und so a working code fragment :-)


Thanks Roman


_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mail
Benoit Panizzon
2015-11-27 13:39:10 UTC
Permalink
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) = @_;
read_commands_file();
my $vars=&load_vars();

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

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

$vars->{imp_rcpt_count}++;
&store_vars($vars);
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
______________________________________________________

_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists.roaringpenguin.com/mailman/listinfo/mi
Roman Pretory
2015-11-27 14:39:59 UTC
Permalink
Hello Benoît

.)filter_initialize {} and sub filter_cleanup {} are not inkl. In my filter :-(
I Put it now below sub filter_end ($) {}

.)perl module storable is default in my perl version lt. CPAN.
But if i send a Mail to more recipient to answer is the same .. only 1.
No error by mimedefang restart and filtersytax, no error in log, so it seems as it work.

Maybe my mimedefang version is reason I use 2.78-1


Thanks Roman


_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists
Roman Pretory
2015-11-27 14:39:18 UTC
Permalink
Hello Benoît

.)filter_initialize {} and sub filter_cleanup {} are not inkl. In my filter :-(
I Put it now below sub filter_end ($) {}

.)perl module storable is default in my perl version lt. CPAN.
But if i send a Mail to more recipient to answer is the same .. only 1.
No error by mimedefang restart and filtersytax, no error in log, so it seems as it work.

Maybe my mimedefang version is reason I use 2.78-1


Thanks Roman


_______________________________________________
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 ***@lists.roaringpenguin.com
http://lists

Loading...