If you are running debian etch postfix with heavy spam filtering on one machine and debian etch mailman on another machine without much spam filtering

this script will take the postfix virtual-mailman file on the listserv mailman machine and create the files needed by postfix
to relay the mail to the listserv machine after spam filtering

Changes to DNS and /etc/postfix/main.cf left as exercise to reader.



########### cut here ##########
#!/usr/bin/perl -wT

# copyright [EMAIL PROTECTED]
# license GNU GPL v3 or later
# (a bit self important to dignify
# this hack w/ a license)

# script converts contents of mailman-virtual
# generated on csl-lists-01.thecsl.org to
# form needed to postfix needed to relay to that host
# see book of posfix chapter 13 'mail gateways'

# before running:

        # from your listserv machine:
                # copy /var/lib/mailman/data/virtual-mailman
        # to:
                /tmp/
        #... on your postfix machine


use strict;
# untaint
$ENV{PATH}='';

my $VIRTUAL_MAILMAN_FILE   = '/tmp/virtual-mailman';
my $RELAY_RECIPIENTS_FILE  = '/etc/postfix/relay_recipients';
my $TRANSPORT_MAPS_FILE    = '/etc/postfix/transport';
my $RELAY_DOMAINS_FILE     ='/etc/postfix/relay_domains';

{    #main
    warn_if_old_file($VIRTUAL_MAILMAN_FILE);

    my @emails  = get_emails($VIRTUAL_MAILMAN_FILE);
    my @domains = get_domains(@emails);

my @relay_domain_map_lines = map { sprintf "%-55s OK\n", $_ } @domains;

    my @transport_map_lines =
      map { sprintf "%-35s smtp:[$_]\n", "$_"; } @domains;

my @relay_recipient_lines = map { sprintf "%-55s OK\n", $_ } @emails;

    write_and_postmap($TRANSPORT_MAPS_FILE,@transport_map_lines);
write_and_postmap($RELAY_RECIPIENTS_FILE, @relay_recipient_lines);
    write_and_postmap($RELAY_DOMAINS_FILE, @relay_domain_map_lines);

    # reload postfix config
    my $cmd="/usr/sbin/postfix reload";
    (system($cmd)==0) or die "FAILED: $cmd \n"


}

sub warn_if_old_file {
    my $file        = shift;
    my $change_time = ( stat $file )[9];
warn "\n\n$file is more than an hour old. Did you forget to copy the new file?\n\n"
      if ( time() - $change_time > 3600 );
}

sub get_emails {
    my $file = shift;
    my $IN;
    open $IN, $file
      or die "$! ";
    my @emails;
    while ( my $line = <$IN> ) {

        #    next if $line !~ /lists.thecsl.org/;
        next if $line !~ /\@/;
        my $email = ( split /\s+/, $line )[0];
        push @emails, $email;
    }
    @emails = sort @emails;
    close $IN or die "bad close: $!";
    return @emails;
}

sub get_domains {
    my @emails = @_;
    my @domains;
    foreach my $email (@emails) {
        $email =~ /([\w_\-\.]+)$/;
        push @domains, $1;
    }
    my %unique_domains;
    foreach my $domain (@domains) {
        $unique_domains{$domain}++;

    }
    return sort keys %unique_domains;
}

sub write_and_postmap {
 my $file=shift;
 my @[EMAIL PROTECTED];
 my $OUT_FH;

 open $OUT_FH, '>', $file
        or die "couldn't open $file for writing: $!\n";
 print $OUT_FH @lines ;
 my $cmd="/usr/sbin/postmap $file";
 (system($cmd)==0)
        or die "FAILED: $cmd ";

}
########### cut here ##########

------------------------------------------------------
Mailman-Users mailing list
[email protected]
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-users/archive%40jab.org

Security Policy: 
http://www.python.org/cgi-bin/faqw-mm.py?req=show&amp;file=faq01.027.htp

Reply via email to