exiacl
changeset 1 172ffeffaa3c
child 2 d455c41ff7e7
equal deleted inserted replaced
0:0f0e42034fb2 1:172ffeffaa3c
       
     1 #! /usr/bin/perl
       
     2 # © Heiko Schlittermann
       
     3 # $Id$
       
     4 # $URL$
       
     5 
       
     6 use strict;
       
     7 use warnings;
       
     8 use AppConfig;
       
     9 use IPC::Open3;
       
    10 use IO::Select;
       
    11 use Socket;
       
    12 use File::Basename;
       
    13 use Sys::Hostname;
       
    14 
       
    15 
       
    16 use constant ME => basename $0;
       
    17 use constant CONFIG => (
       
    18     { CASE => 1 },
       
    19     config  => { ARGS => "=s", DEFAULT => "exim.conf.t", ALIAS => "C" },
       
    20 
       
    21     src	    => { ARGS => "=s", DEFAULT => "131.107.0.15" },
       
    22     dst	    => { ARGS => "=s"  },
       
    23 
       
    24     helo    => { ARGS => "=s", DEFAULT => "mail.microsoft.com" },
       
    25 
       
    26     From    => { ARGS => "=s" },
       
    27     from    => { ARGS => "=s", DEFAULT => "hanson\@gmx.net" },
       
    28 
       
    29     to	    => { ARGS => "=s", DEFAULT => "hans\@pobox.com" },
       
    30 
       
    31     exim    => { ARGS => "=s", DEFAULT => "exim"},
       
    32 );
       
    33 
       
    34 sub exim_option($);
       
    35 sub read_exim($);
       
    36 
       
    37 
       
    38 my $Cf;
       
    39 $Cf = new AppConfig CONFIG or die;
       
    40     $Cf->dst(inet_ntoa(scalar gethostbyname(exim_option("primary_hostname"))));
       
    41     $Cf->getopt(\@ARGV);
       
    42     $Cf->From($Cf->From || $Cf->from);
       
    43 
       
    44 my ($w, $r);
       
    45 my @cmd = ($Cf->exim, -C => $Cf->config, $Cf->dst ? (-oMi => $Cf->dst) : (), -bhc => $Cf->src);
       
    46 
       
    47 my $s = new IO::Select;
       
    48 
       
    49 open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
       
    50 
       
    51 read_exim$r;
       
    52 print $w "EHLO ".$Cf->helo."\n";
       
    53 read_exim($r);
       
    54 print $w "MAIL FROM: ".$Cf->From."\n";
       
    55 read_exim $r;
       
    56 print $w "RCPT TO: ".$Cf->to."\n";
       
    57 read_exim $r;
       
    58 print $w "DATA\n";
       
    59 read_exim $r;
       
    60 print $w "From: ".$Cf->from."\n";
       
    61 print $w "To: ".$Cf->to."\n";
       
    62 print $w "\n.\n";
       
    63 read_exim $r;
       
    64 print $w "QUIT\n";
       
    65 
       
    66 
       
    67 sub read_exim($) {
       
    68     my $fh = shift;
       
    69     while (<$fh>) {
       
    70 	if (/^\d\d\d/) { print; }
       
    71 	else { print STDERR; }
       
    72 
       
    73 	last if /^\d\d\d /;
       
    74     }
       
    75     exit if /^5/;
       
    76 }
       
    77 
       
    78 
       
    79 {
       
    80     my %opts;
       
    81 sub exim_option($) {
       
    82     my $opt = shift;
       
    83     if (!%opts) {
       
    84 	%opts = map { chomp; /^(.*?)\s*=\s*(.*)/ ? ($1, $2) : (/no_(.*)/ ? ($1, 0) : ($_, 1)) } grep !/^\s*$/, `exim -bP`;
       
    85     }
       
    86     $opts{$opt}
       
    87 } }
       
    88 
       
    89 # vim:sts=4 sw=4 aw ai sm: