Link to home
Start Free TrialLog in
Avatar of howart
howartFlag for Netherlands

asked on

mimefang and filter_recipient

How can I discard messages with mimedefang and filter recipient.
If I use the sugessted method i will produce backscatter

sub filter_recipient {
    my($recip, $sender, $ip, $host, $first, $helo,
       $rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
   if ( md_check_against_smtp_server($sender, $recip,
       "muncher.poppers.local","msx-poppers.poppers.local")){
       md_syslog('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
      return 'REJECT', "Recipient unkown" ;
    }
#    return md_check_against_smtp_server($sender, $recip,
#       "muncher.poppers.local","msx-poppers.poppers.local"); 
     return 'CONTINUE', 'ok';
}

Open in new window

Avatar of howart
howart
Flag of Netherlands image

ASKER

What i try to do is to discard messages to unkown recipients in our domains.
When I use mimedefang  with recipient_filter messages get rejected when i try to send to an unkown recipient.

So I made  a routine in sub filter


# Check if recipient does exist on receiving mail server 
    foreach (@Recipients) {
        my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $_,
        "muncher.poppers.local","msx-poppers.poppers.local");
        # print STDERR $smtp_status;
        if ( $smtp_status == 'CONTINUE' ) {
             md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
        } else {
             md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
             action_bounce('Unknown MSX recipient');
        }
    }

Open in new window

Avatar of howart

ASKER

this does not work where am i going wrong?
ASKER CERTIFIED SOLUTION
Avatar of noci
noci

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of howart

ASKER

got now this
but stil get a bounce


sub filter_recipient {
    my($recip, $sender, $ip, $host, $first, $helo,
       $rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
    # Check if recipient does exist on receiving mail server 
       my $file = "/tmp/testmd.log";
       open (FILE, ">>$file");
 
       my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $recip,
                       "muncher.poppers.local","192.168.1.13");
 
       print FILE $smtp_status,$smtp_message,$Sender,$_,"\n";
       if ( $smtp_status == 'CONTINUE' ) {
            md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
            return ("CONTINUE", "");
       } else {
            md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
            retrun ('DISCARD', "discarded");
       }
       close(FILE);
 
}

Open in new window

Avatar of howart

ASKER

I c the error
retrun instead of return
lets c if it works now
Avatar of howart

ASKER

does still not work

Avatar of noci
noci

   if ( $smtp_status == 'CONTINUE' ) {
should be:
    if ( $smtp_status eq 'CONTINUE' ) {

(== if for numeric, eq for string compares).
(it would allways be true  0 == 0.)

running perl -cw <file>

can check a file for syntax errors.
Avatar of howart

ASKER

I have put the code in sub filter there it works!! :)

for some reason sub filter_recipient does not execute
Do you know what goes wrong there?
Avatar of howart

ASKER

here is my code in sub filter


# Check if recipient does exist on receiving mail server 
    my $file = "/tmp/test_md_filter.log";
    open (FILE, ">>$file");
    print FILE "youre now in mimdefang-filter sub filter\n";
    foreach (@Recipients) {
        my($smtp_status, $smtp_message) =  md_check_against_smtp_server($Sender, $_,
        "muncher.poppers.local","192.168.1.13");
        print FILE $smtp_status,$smtp_message,$Sender,$_,"\n";
        # print STDERR $smtp_status;
        if ( $smtp_status eq 'CONTINUE' ) {
             md_graphdefang_log($smtp_status,$_,'Recipient MSX exists');
        } else {
             md_graphdefang_log('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");
             #action_bounce('Unknown MSX recipient');
             action_discard();
        }
    }
    close(FILE);

Open in new window

Is there no problem when opening the file?
like: /tmp/test....log owned by another user?

Maybe it is better to add
 md_syslog('info' , "MDLOG, $MsgID,unkownrecipient,$hostname,$ip");

Calls and check the syslog output for messages.