[Mimedefang] md_check_against_smtp_server

Jim McCullars jim at info.uah.edu
Thu Dec 18 22:21:49 EST 2003



On Thu, 18 Dec 2003, James Miller wrote:

> 1.  Where should filter_recipient be called in mimedefang-filter.pl?  I'm

   It doesn't matter where you put it - it gets called by mimedefang.pl at
the proper point in the SMTP dialog.

> 2.  Here's what my filter looks like.
> sub filter_recipient
> {
>     my($recip, $sender, $ip, $host, $first, $helo,
> 	$rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
>     return md_check_against_smtp_server($sender, $recip,
>       "relay_mailserver.ourdomain.com","mailserver.ourdomain.com");
> }
>
>
> I get the feeling that I'm missing a 'what to do with it now' part.. a
> if address is good then return('CONTINUE', 'ok');
> else return('REJECT', 'That is a bad email address')'

   You are already doing that.  Note your use of the return command before
the function call.  The value of the call to md_check_against_smtp_server
will be either a (1 "OK") if it finds the recipient or (0 $msg) (where
$msg is the response code from the SMTP server) if it doesn't.  Since you
preface the call to md_check_against_smtp_server with a return statement
you are doing that already.

>
> But the RHS of the @ can be about 30 different domains for us.. so I'm not
> sure how to structure a if/then/else function for each of our domains

   FWIW, the approach I would take would be a hash.  I would define
something like this:

my %relaytable = qw(domain1.com relay.domain1.com
                    domain2.com whatever.domain2.com);

Where the first value is the hash key (name of the domain) and the second
value is the value for that key (relay for that domain).  Then strip off
the domain part of the email address and look up the relay in your hash.
Maybe something like:

sub filter_recipient {
     my($recip, $sender, $ip, $host, $first, $helo,
       $rcpt_mailer, $rcpt_host, $rcpt_addr) = @_;
  $recip =~ /.+\@(.+)>?/;  # extract domain part (minus angle bracket)
  my $domain = $1;
  my $relay = $relaytable{$domain}; # get relay
  if ($relay) {          # is there a relay for this domain?
    return md_check_against_smtp_server($sender, $recip,
         "some HELO value", $relay) # yes, do the check
  }
return('CONTINUE', "OK");  # accept recipient if dont find relay
}

   This is what I would try for 30 or so domains.  If it were a lot more,
or if the relays changed very much, I would consider using Net::DNS to
look up the MX rather than a hash that you would have to keep updated.

   Note that this is untested, off-the-top-of-my-head code.

   HTH...

Jim




More information about the MIMEDefang mailing list