File: rcpt_ok

package info (click to toggle)
qpsmtpd 0.84-9
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 1,376 kB
  • sloc: perl: 8,012; sh: 382; makefile: 61
file content (38 lines) | stat: -rw-r--r-- 1,224 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# this plugin checks the standard rcpthosts config
#
# It should be configured to be run _LAST_!
#
use Qpsmtpd::DSN;

sub hook_rcpt {
  my ($self, $transaction, $recipient, %param) = @_;
  my $host = lc $recipient->host;

  my @rcpt_hosts = ($self->qp->config("me"), $self->qp->config("rcpthosts"));
  
  # Allow 'no @' addresses for 'postmaster' and 'abuse'
  # qmail-smtpd will do this for all users without a domain, but we'll
  # be a bit more picky.  Maybe that's a bad idea.
  my $user = $recipient->user;
  $host = $self->qp->config("me")
    if ($host eq "" && (lc $user eq "postmaster" || lc $user eq "abuse"));
  
  # Check if this recipient host is allowed
  for my $allowed (@rcpt_hosts) {
    $allowed =~ s/^\s*(\S+)/$1/;
    return (OK) if $host eq lc $allowed;
    return (OK) if substr($allowed,0,1) eq "." and $host =~ m/\Q$allowed\E$/i;
  }

  my $more_rcpt_hosts = $self->qp->config('morercpthosts', 'map');
  return (OK) if exists $more_rcpt_hosts->{$host};

  if ( $self->qp->connection->relay_client ) { # failsafe
    return (OK);
  }
  else {
    # default of relaying_denied is obviously DENY, 
    # we use the default "Relaying denied" message...
    return Qpsmtpd::DSN->relaying_denied();
  }
}