Hi!
I've tried to block external emails coming to our mailing lists defined
in LDAP.
I've already tried the following means:
1) "LDAP_SOURCE mailsource" setting in ldapaliasrc, then "mailsource:
local" attribute on mailing lists in LDAP - it doesn't work as
documented, Courier's ldapaliasd does searches on that attribute
(&(mail=all)(mailsource=esmtp)), but still delivers to those lists
afterwards;
2) Delivery checks in maildroprc with forward to a moderator -
unacceptable, the moderator account receives as many copies of each mail
as there were members in a list; the envoronment variable AUTHENTICATED
isn't available to test whether the user authenticated with SMTP AUTH;
3) Alias filtering account specified in /etc/courier/aliasfilteracct -
it doesn't seem to work for LDAP aliases
4) Global perlfilter - hard to debug, dangerous and still doesn't work...
Ad. 4):
I can see filter processes:
courier 8229 0.0 0.0 4464 456 ? S 20:59 0:00 perlfilter
Filtering is enabled:
# cat /etc/courier/enablefiltering
esmtp local
But the following code from the filterdata() function doesn't seem to
give any results, as if it wasn't run at all:
<snip>
# Here's where the custom content filter is implemented. Use filehandles
# so that cleanup's automatic.
my $fh=new IO::File "< $filename";
return "" unless defined $fh;
my $line;
my $to_private_list = 0;
my $from_admin_account = 0;
my $logfh = new IO::File ">>/var/spool/courier/tmp/perlfilterlog.txt";
while ( defined ($line=<$fh>))
{
chomp $line;
last if $line eq ""; # End of headers
if (
$line =~ /^To:.+mailinglist\@.+$/i
) {
$to_private_list = 1;
}
if (
$line =~ /^From:.+admin\.account@domain\.com.+$/i
) {
print $logfh "From admin";
$from_admin_account = 1;
}
if ($to_private_list && ! $from_admin_account) {
return "550 Access to list denied."
}
return "";
</snip>