On Wed, 28 Jan 2009 16:23:01 +0100, Julien wrote: > The config file (/var/qmail/control/aliasdomains) contain one > remplacment per line, each remplacment consist of 'olddomain' and > 'newdomain' seperate by a ':' like : > > test.domain.com:domain.com > > So address jul...@test.domain.com sould be rewrite to jul...@domain.com > > I'm sure there is a very elegant way to do this in perl ...
Yeah it's pretty simple: #!perl -w my %domain_map; sub init { my ($self) = @_; for ($self->qp->config('aliasdomains')) { my ($from, $to) = split(/:/, $_, 2); $domain_map{$from} = $to; } } sub hook_rcpt { my ($self, $transaction) = (shift, shift); my $rcpt_domain = $_[0]->host; if (my $rewrite_to_domain = $domain_map{$rcpt_domain}) { $self->log(LOGINFO, "Rewriting $rcpt_domain to $rewrite_to_domain"); $_[0]->host($rewrite_to_domain); } return DECLINED; }