exiacl
changeset 2 d455c41ff7e7
parent 1 172ffeffaa3c
child 4 5c0e239c49c5
equal deleted inserted replaced
1:172ffeffaa3c 2:d455c41ff7e7
     1 #! /usr/bin/perl
     1 #! /usr/bin/perl
     2 # © Heiko Schlittermann
     2 # © Heiko Schlittermann
     3 # $Id$
     3 # $Id$
     4 # $URL$
     4 # $URL$
       
     5 
     5 
     6 
     6 use strict;
     7 use strict;
     7 use warnings;
     8 use warnings;
     8 use AppConfig;
     9 use AppConfig;
     9 use IPC::Open3;
    10 use IPC::Open3;
    31     exim    => { ARGS => "=s", DEFAULT => "exim"},
    32     exim    => { ARGS => "=s", DEFAULT => "exim"},
    32 );
    33 );
    33 
    34 
    34 sub exim_option($);
    35 sub exim_option($);
    35 sub read_exim($);
    36 sub read_exim($);
       
    37 sub write_exim($@);
    36 
    38 
    37 
    39 
    38 my $Cf;
    40 my $Cf;
    39 $Cf = new AppConfig CONFIG or die;
    41 $Cf = new AppConfig CONFIG or die;
    40     $Cf->dst(inet_ntoa(scalar gethostbyname(exim_option("primary_hostname"))));
    42     $Cf->dst(inet_ntoa(scalar gethostbyname(exim_option("primary_hostname"))));
    46 
    48 
    47 my $s = new IO::Select;
    49 my $s = new IO::Select;
    48 
    50 
    49 open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
    51 open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
    50 
    52 
    51 read_exim$r;
    53  read_exim $r;
    52 print $w "EHLO ".$Cf->helo."\n";
    54 write_exim $w, "EHLO ".$Cf->helo."\n";
    53 read_exim($r);
    55  read_exim $r;
    54 print $w "MAIL FROM: ".$Cf->From."\n";
    56 write_exim $w, "MAIL FROM: ".$Cf->From."\n";
    55 read_exim $r;
    57  read_exim $r;
    56 print $w "RCPT TO: ".$Cf->to."\n";
    58 write_exim $w, "RCPT TO: ".$Cf->to."\n";
    57 read_exim $r;
    59  read_exim $r;
    58 print $w "DATA\n";
    60 write_exim $w, "DATA\n";
    59 read_exim $r;
    61  read_exim $r;
    60 print $w "From: ".$Cf->from."\n";
    62 write_exim $w, "From: ".$Cf->from."\n";
    61 print $w "To: ".$Cf->to."\n";
    63 write_exim $w, "To: ".$Cf->to."\n";
    62 print $w "\n.\n";
    64 write_exim $w, "\n.\n";
    63 read_exim $r;
    65  read_exim $r;
    64 print $w "QUIT\n";
    66 write_exim $w, "QUIT\n";
    65 
    67 
    66 
    68 
    67 sub read_exim($) {
    69 sub read_exim($) {
    68     my $fh = shift;
    70     my $fh = shift;
    69     while (<$fh>) {
    71     while (<$fh>) {
    70 	if (/^\d\d\d/) { print; }
    72 	if (/^\d\d\d/) { print "< $_"; }
    71 	else { print STDERR; }
    73 	else { print STDERR; }
    72 
    74 
    73 	last if /^\d\d\d /;
    75 	last if /^\d\d\d /;
    74     }
    76     }
    75     exit if /^5/;
    77     exit if /^5/;
       
    78 }
       
    79 
       
    80 sub write_exim($@) {
       
    81     my $fh = shift;
       
    82     print "> ", @_;
       
    83     print $fh @_;
    76 }
    84 }
    77 
    85 
    78 
    86 
    79 {
    87 {
    80     my %opts;
    88     my %opts;