I use the code to redir smtp. And test the connection from outlook. But i find that
the <crlf>.<crlf> can not recv from socket($socket->recv($line, 1024)) . I use WPR PRO
to sniffer the packet , the outlook send out <crlf>.<crlf> .
=============================================================
package SMTP;
use strict;
use Apache2::Connection ( );
use APR::Socket ( );
use APR::Const -compile =>  qw(SO_NONBLOCK);
use Apache2::Const -compile => 'OK';
use HTTP::Date;
use Socket;
sub handler {
    my $c = shift;
 my $proto = getprotobyname('tcp');
 my $host='aaa.bbb.com.tw';
 my $port=25;
 my $iaddr = inet_aton($host);
 my $paddr = sockaddr_in( $port, $iaddr );
 socket( SOCK, PF_INET, SOCK_STREAM, $proto );
 connect( SOCK, $paddr ) ;
 select (SOCK);
 $|=1;
 select(STDOUT); 
    my $welcomemsg=<SOCK>;
    my $socket = $c->client_socket;
    $socket-> opt_set(APR::Const::SO_NONBLOCK, 0);
    $socket->send($welcomemsg, length $welcomemsg);
    my $lines;
 
    my $cmd;
    my $line;
    my $i=0;
    while( $socket->recv($line, 1024)){
 
      open(hh,">>/tmp/smtp.log");
      print hh $i.$line;
      print hh "----------------------($i)-----------------------------\n";
      close(hh);
       $i++;
   $lines .= $line;
 
  if ( $lines !~ /\n$/ )
  {
   next;
  }
 
    
    binmode(SOCK);
    syswrite (SOCK ,$lines);
    my $response;
    binmode(SOCK);
    my $bs = sysread(SOCK, $response, 1024);   
    $socket->send($response, length $response);
   
    $lines='';
 
  
   }
    return Apache2::Const::OK;
}

1;

Reply via email to