smtpprox and postfix

From: Martijn Stam (spam.me_at_offizi.nl)
Date: 11/30/04


Date: Tue, 30 Nov 2004 15:19:35 -0500

Hello,

I need to replace our domain name amstec.net for a couple of domain names in
the e-mail headers.
I use smtpprox as transparent proxy now, but I'm not able to modify the
script to do a find and replace.

What it has to do:

1. Find the domain name part of the To address in the e-mail headers.
2. Split the domain name on domain and extension
3. Read the content of a text file or preferable a MySQL database and if the
domain name from the To address is in the file/database then replace all
instances of amstec.net with the domain name.

Some code snippets:

while (1) {
    $server->accept(%opts);
    my $client = MSDW::SMTP::Client->new(interface => $dstaddr, port =>
$dstport);
    my $banner = $client->hear;
    $banner = "220 $debugtrace.$$" if defined $debugtrace;
    $server->ok($banner);
    while (my $what = $server->chat) {
        if ($what eq '.') {
            spew ( $client, *PREPEND ) if defined($prependheader);
            #spew ( $client );
           $client->yammer($server->{data});
        } else {
            $client->say($what);
        }
        $server->ok($client->hear);
    }
    $client = undef;
    delete $server->{"s"};
    exit 0 if $lives-- <= 0;
}

sub spew
{
 my ($client, $fh ) = @_;
 seek( $fh, 0, 0);
 local( *_ );
 local( $/ ) = "\r\n";
 while ( <$fh> )
 {
  s/[\r\n]*$//;
  $client->say($_);
 }
}

This example adds extra headers read from an external file. It needs to be
modified to do a find and replace.

Martijn Stam