exiacl.pl
changeset 24 a7a73cba1342
parent 22 e73bf6df70f0
child 25 3f3ae057210b
equal deleted inserted replaced
23:f4c012bc97c0 24:a7a73cba1342
    27     --[no]callout			[!$Cf->callout!]
    27     --[no]callout			[!$Cf->callout!]
    28 
    28 
    29     Environment used: $EXIM		[!$ENV{EXIM}!]
    29     Environment used: $EXIM		[!$ENV{EXIM}!]
    30                       $EXIM_CONF	[!$ENV{EXIM_CONF}!]
    30                       $EXIM_CONF	[!$ENV{EXIM_CONF}!]
    31 
    31 
    32     Data is read from STDIN unless it's connected to terminal.
    32     mail data is read from STDIN unless it's connected to terminal.
    33 
    33 
    34     $Id$
    34     $Id$
    35     $URL$
    35     $URL$
    36 #
    36 #
    37 
    37 
    45 use File::Basename;
    45 use File::Basename;
    46 
    46 
    47 our $VERSION = "0.8";
    47 our $VERSION = "0.8";
    48 
    48 
    49 sub exim_option($);
    49 sub exim_option($);
    50 sub read_exim($);
    50 sub read_exim($;$);
    51 sub write_exim($@);
    51 sub write_exim($@);
    52 sub addr(@);
    52 sub addr(@);
    53 sub hostname() { chomp (my $h = `hostname -f`); return $h;  }
    53 sub hostname() { chomp (my $h = `hostname -f`); return $h;  }
    54 
    54 
    55 sub which($) { (map { -x "$_/$_[0]" && "$_/$_[0]" || () } split /:/, $ENV{PATH})[0] }
    55 sub which($) { (map { -x "$_/$_[0]" && "$_/$_[0]" || () } split /:/, $ENV{PATH})[0] }
   131     print "**> @cmd\n";
   131     print "**> @cmd\n";
   132 
   132 
   133     $SIG{PIPE} = sub { exit };
   133     $SIG{PIPE} = sub { exit };
   134     my $pid = open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
   134     my $pid = open3($w, $r, undef, @cmd) or die "Can't run @cmd: $!\n";
   135 
   135 
       
   136 
   136      read_exim $r;
   137      read_exim $r;
   137     write_exim $w, "EHLO ".$Cf->Helo."\n";
   138     write_exim $w, "EHLO ".$Cf->Helo."\n";
   138      read_exim $r;
   139      read_exim $r;
   139     write_exim $w, "MAIL FROM: ".$Cf->From."\n";
   140     write_exim $w, "MAIL FROM: ".$Cf->From."\n";
   140      read_exim $r;
   141      read_exim $r;
   141     write_exim $w, "RCPT TO: ".$Cf->to."\n";
   142 
   142      read_exim $r;
   143     foreach my $rcpt (split /\s*,\s*/, $Cf->to) {
       
   144 	write_exim $w, "RCPT TO: $rcpt\n";
       
   145 	 read_exim $r, "5";
       
   146     }
   143     write_exim $w, "DATA\n";
   147     write_exim $w, "DATA\n";
   144      read_exim $r;
   148      read_exim $r;
   145     write_exim $w, "From: ".$Cf->from."\n";
   149     write_exim $w, "From: ".$Cf->from."\n";
   146     write_exim $w, "To: ".$Cf->to."\n";
   150     write_exim $w, "To: ".$Cf->to."\n";
   147     write_exim $w, "Subject: Test\n";
   151     write_exim $w, "Subject: Test\n";
   158     write_exim $w, "QUIT\n";
   162     write_exim $w, "QUIT\n";
   159 
   163 
   160 
   164 
   161 }
   165 }
   162 
   166 
   163 sub read_exim($) {
   167 sub read_exim($;$) {
   164     my $fh = shift;
   168     my $fh = shift;
       
   169     my $oh_my_dear = shift || "54";
   165     while (<$fh>) {
   170     while (<$fh>) {
   166 	/^\d\d\d/ and print("< $_") and next;
   171 	/^\d\d\d/ and print("< $_") and next;
   167 	/^LOG/ and print and next if $Cf->log;
   172 	/^LOG/ and print and next if $Cf->log;
   168 	print and next if $Cf->debug;
   173 	print and next if $Cf->debug;
   169     } continue {
   174     } continue {
   170 	last if /^\d\d\d\s/;
   175 	last if /^\d\d\d\s/;
   171     }
   176     }
   172     exit if defined and /^[54]/;
   177     exit if defined and /^[$oh_my_dear]/;
   173 }
   178 }
   174 
   179 
   175 sub write_exim($@) {
   180 sub write_exim($@) {
   176     my $fh = shift;
   181     my $fh = shift;
   177     print "> ", @_;
   182     print "> ", @_;