#!/usr/bin/perl =head1 NAME aliases_rewrite - rewrite recipient list according to alias expansion =head1 DESCRIPTION FIXME: This plugin now uses address notes instead of transaction notes. This plugin maps the recipients of the message to addresses stored in the expanded_recipients transaction note. Typically this note was filled in by the companion plugin aliases_check. =head1 HOOKS =over =item data_post replace_rcpt =back =head1 TRANSACTION NOTES This plugin uses one transaction note: =over =item expanded_recipients A reference to a hash of arrays. The keys of the hash are the recipients as passed in the RCPT commands and as stored in $transaction->recipients. Each value is a list of addresses this recipient should be replaced with. All addresses are strings, not Qpsmtpd::Address objects, and they are full RFC-2821-style addresses, except that delimiting angle brackets are omitted. So the note should look something like this: { 'hjp@wsr.ac.at' => [ 'hjp@asherah.wsr.ac.at' }, 'peter.holzer@wsr.ac.at' => [ 'hjp@asherah.wsr.ac.at' }, ... 'postmaster@wsr.ac.at' => [ 'hjp@asherah.wsr.ac.at', 'gina@wsr.ac.at' ], ... } =back =cut use strict; use Time::HiRes qw(time); use Data::Dumper; sub register { my ($self, $qp) = @_; $self->log(LOGINFO, "in register"); $self->register_hook("data_post", "replace_rcpt"); } =head2 data_post: replace_rcpt Replace all recipients with the list collected in note 'expanded_recipients'. =cut sub replace_rcpt { my ($self, $transaction) = @_; $self->log(LOGDEBUG, "clearing recipients"); my @new_recipients = (); for ($transaction->recipients()) { my $e = $_->notes('deliver_to'); push (@new_recipients, @$e) if ($e); $self->log(LOGINFO, "replace_rcpt: recipient: ", $_->address(), " -> @$e"); } return (DENY, "no recipients") unless @new_recipients; my @nra = (); for (@new_recipients) { $self->log(LOGDEBUG, "adding $_"); push @nra, Qpsmtpd::Address->new($_); } $transaction->recipients(@nra); $self->log(LOGDEBUG, "checking recipients"); for ($transaction->recipients()) { $self->log(LOGDEBUG, "recipient: ", $_->address()); } $self->log(LOGDEBUG, "checking recipients done"); return DECLINED; } =head1 BUGS None known (yet). =head1 COPYRIGHT AND LICENSE Copyright (c) 2003-2006 Peter J. Holzer This plugin is licensed under the same terms as the qpsmtpd package itself. Please see the LICENSE file included with qpsmtpd for details. =cut