=head1 NAME

denysoft_multi_rcpt

=head1 DESCRIPTION

Plugin to return DENYSOFT for all recipients after the first (or all
recipients having a different domain than the first, if 'match domain' 
set).

=head1 CONFIG

The following parameters can be passed to denysoft_multi_rcpt:

=over 4

=item match (domain|config)

B<match domain>: denysoft all recipients having a different domain to the 
first recipient. Subdomains do not match i.e. they are denied.

B<match config>: denysoft all recipients who have different sets of config
files to the first recipient. This option currently only supports 
per_user_config style configs. If using this option, the plugin must 
come I<after> the per_user_config plugin.

=back

=head1 AUTHOR

Written by Gavin Carr <gavin@openfusion.com.au>.

=cut

my $VERSION = 0.01;

sub register {
  my ($self, $qp, %arg) = @_;
  $self->{_match} = $arg{match};
  $self->register_hook("rcpt", "denysoft_multi_rcpt");
}

sub denysoft_multi_rcpt {
  my ($self, $transaction, $rcpt) = @_;
  # Always decline the first
  if (! $self->{_rcpt}) {
    $self->{_rcpt} = $rcpt;
    $self->{_rcpt_configdir} = $transaction->notes('per_rcpt_configdir');
    return DECLINED;
  }
  # If domain matching, allow if host portions match
  if ($self->{_match} eq 'domain') {
    return DECLINED if $self->{_rcpt}->host eq $rcpt->host;
  }
  elsif ($self->{_match} eq 'config') {
    my $configdir = $transaction->notes('per_rcpt_configdir');
    return DECLINED 
      if defined $self->{_rcpt_configdir} && defined $configdir && 
      $self->{_rcpt_configdir} eq $configdir;
    $self->log(6, sprintf("config mismatch: %s (%s) != %s (%s)",
      $self->{_rcpt_configdir} || '', $self->{_rcpt}->address,
      $configdir || '', $rcpt->address));
  }
  # Default deny
  return (DENYSOFT, "delivery to recipient temporarily unavailable");
}

# arch-tag: cd362eab-2f01-4e2d-bf36-e82dc73721b2

