Here's my first own plugin. I'd be grateful for any hints on the coding style etc.

What it does: It will only accept messages with an envelope sender of <> if the recipient is listed in the acceptbounce config file (or if that file doesn't exist, to protect from configuration errors etc). You can either add local parts or full addresses to the acceptbounce file (mine contains:
postmaster
abuse
webmaster
and my own e-mail
)

--- snipsnap ---

sub hook_mail {
  my ($self, $transaction, $sender) = @_;

  return (DECLINED) unless ($sender->format eq "<>");

  $self->log(LOGDEBUG, "sender is <>");
  $transaction->notes('bounce',1);

  return (DECLINED);
}

sub hook_rcpt {
  my ($self, $transaction, $rcpt) = @_;
  my $note = $transaction->notes('bounce');
  return DECLINED unless $note;

  my @acceptbounce = $self->qp->config("acceptbounce");
  return DECLINED unless (@acceptbounce);
  # Can't do this on one line becuase config is dependent on wantarray

  my $user = lc($rcpt->user);
  my $addr = $user . '@' . lc($rcpt->host);

  foreach my $to (@acceptbounce) {
        chomp $to;
        return DECLINED if ($user eq $to);
        return DECLINED if ($addr eq $to);
  }
  $self->log(LOGDEBUG, "not accepting bounces for $addr");
  return (DENY, "sorry, this address never sends mail ".
                "and therefore does not accept bounces");
}

Reply via email to