|
From: <jgr...@us...> - 2003-03-06 21:25:58
|
Update of /cvsroot/popfile/engine/Proxy
In directory sc8-pr-cvs1:/tmp/cvs-serv15347/Proxy
Modified Files:
POP3.pm SMTP.pm
Log Message:
Enabled SMTP support
Index: POP3.pm
===================================================================
RCS file: /cvsroot/popfile/engine/Proxy/POP3.pm,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** POP3.pm 5 Mar 2003 21:36:57 -0000 1.46
--- POP3.pm 6 Mar 2003 21:25:54 -0000 1.47
***************
*** 36,41 ****
$self->name( 'pop3' );
! $self->{child_} = \&child__;
! $self->{flush_child_data_} = \&flush_child_data__;
return $self;
--- 36,43 ----
$self->name( 'pop3' );
! $self->{child_} = \&child__;
! $self->{connection_timeout_error_} = '-ERR no response from mail server';
! $self->{connection_failed_error_} = '-ERR can\'t connect to';
! $self->{good_response_} = '^\+OK';
return $self;
***************
*** 73,138 ****
$self->global_config_( 'ecount', 0 );
- # This counter is used when creating unique IDs for message stored
- # in the history. The history message files have the format
- #
- # popfile{download_count}={message_count}.msg
- #
- # Where the download_count is derived from this value and the
- # message_count is a local counter within that download, for sorting
- # purposes must sort on download_count and then message_count
- $self->config_( 'download_count', 0 );
-
# The separator within the POP3 username is :
$self->config_( 'separator', ':' );
return 1;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # flush_child_data__
- #
- # Called to flush data from the pipe of each child as we go, I did this because there
- # appears to be a problem on Windows where the pipe gets a lot of read data in it and
- # then causes the child not to be terminated even though we are done. Also this is nice
- # because we deal with the statistics as we go
- #
- # $handle The handle of the child's pipe
- #
- # ---------------------------------------------------------------------------------------------
- sub flush_child_data__
- {
- my ( $self, $handle ) = @_;
-
- my $stats_changed = 0;
-
- while ( &{$self->{pipeready_}}($handle) )
- {
- my $class = <$handle>;
-
- if ( defined( $class ) ) {
- $class =~ s/[\r\n]//g;
-
- $self->{classifier__}->set_bucket_parameter( $class, 'count',
- $self->{classifier__}->get_bucket_parameter( $class, 'count' ) + 1 );
- $self->global_config_( 'mcount', $self->global_config_( 'mcount' ) + 1 );
- $stats_changed = 1;
-
- $self->log_( "Incrementing $class" );
- } else {
- # This is here so that we get in errorneous position where the pipeready
- # function is returning that there's data, but there is none, in fact the
- # pipe is dead then we break the cycle here. This was happening to me when
- # I tested POPFile running under cygwin.
-
- last;
- }
- }
-
- if ( $stats_changed ) {
- $self->{ui__}->invalidate_history_cache();
- $self->{configuration__}->save_configuration();
- $self->{classifier__}->write_parameters();
- }
}
--- 75,82 ----
Index: SMTP.pm
===================================================================
RCS file: /cvsroot/popfile/engine/Proxy/SMTP.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** SMTP.pm 3 Mar 2003 15:21:48 -0000 1.4
--- SMTP.pm 6 Mar 2003 21:25:55 -0000 1.5
***************
*** 1,3 ****
! # DISABLED POPFILE LOADABLE MODULE
package Proxy::SMTP;
--- 1,3 ----
! # POPFILE LOADABLE MODULE
package Proxy::SMTP;
***************
*** 28,32 ****
{
my $type = shift;
! my $self;
# Must call bless before attempting to call any methods
--- 28,32 ----
{
my $type = shift;
! my $self = Proxy::Proxy->new();
# Must call bless before attempting to call any methods
***************
*** 36,39 ****
--- 36,44 ----
$self->name( 'smtp' );
+ $self->{child_} = \&child__;
+ $self->{connection_timeout_error_} = '554 Transaction failed';
+ $self->{connection_failed_error_} = '554 Transaction failed, can\'t connect to';
+ $self->{good_response_} = '^[23]';
+
return $self;
}
***************
*** 50,62 ****
my ( $self ) = @_;
! # Default ports for SMTP
! $self->{configuration}->{configuration}{smtp_port} = 25;
# Where to forward on to
! $self->{configuration}->{configuration}{smtp_chain_server} = '';
! $self->{configuration}->{configuration}{smtp_chain_port} = 25;
# Only accept connections from the local machine for smtp
! $self->{configuration}->{configuration}{smtp} = 1;
return 1;
--- 55,70 ----
my ( $self ) = @_;
! # Default port for SMTP service
!
! $self->config_( 'port', 25 );
# Where to forward on to
!
! $self->config_( 'chain_server', '' );
! $self->config_( 'chain_port', 25 );
# Only accept connections from the local machine for smtp
!
! $self->config_( 'local', 1 );
return 1;
***************
*** 65,69 ****
# ---------------------------------------------------------------------------------------------
#
! # child
#
# The worker method that is called when we get a good connection from a client
--- 73,77 ----
# ---------------------------------------------------------------------------------------------
#
! # child__
#
# The worker method that is called when we get a good connection from a client
***************
*** 73,77 ****
#
# ---------------------------------------------------------------------------------------------
! sub child
{
my ( $self, $client, $download_count ) = @_;
--- 81,85 ----
#
# ---------------------------------------------------------------------------------------------
! sub child__
{
my ( $self, $client, $download_count ) = @_;
***************
*** 84,88 ****
# Tell the client that we are ready for commands and identify our version number
! tee( $self, $client, "220 SMTP POPFile (v$self->{configuration}->{major_version}.$self->{configuration}->{minor_version}.$self->{configuration}->{build_version}) server ready$eol" );
# Retrieve commands from the client and process them until the client disconnects or
--- 92,96 ----
# Tell the client that we are ready for commands and identify our version number
! $self->tee_( $client, "220 SMTP POPFile (vTODO.TODO.TODO) server ready$eol" );
# Retrieve commands from the client and process them until the client disconnects or
***************
*** 96,115 ****
$command =~ s/(\015|\012)//g;
! debug( $self, "Command: --$command--" );
!
! # Check for a possible abort
! last if ( $self->{alive} == 0 );
if ( $command =~ /HELO/ ) {
! if ( $self->{configuration}->{configuration}{smtp_chain_server} ne '' ) {
! if ( $mail = verify_connected( $self, $mail, $client, $self->{configuration}->{configuration}{smtp_chain_server}, $self->{configuration}->{configuration}{smtp_chain_port} ) ) {
! echo_response( $self, $mail, $client, $command );
} else {
last;
}
! flush_extra( $self, $mail, $client, 0 );
} else {
! tee( $self, $client, "421 service not available$eol" );
}
--- 104,120 ----
$command =~ s/(\015|\012)//g;
! $self->log_( "Command: --$command--" );
if ( $command =~ /HELO/ ) {
! if ( $self->config_( 'chain_server' ) ) {
! if ( $mail = $self->verify_connected_( $mail, $client, $self->config_( 'chain_server' ), $self->config_( 'chain_port' ) ) ) {
! $self->echo_response_( $mail, $client, $command );
} else {
last;
}
! $self->flush_extra_( $mail, $client, 0 );
} else {
! $self->tee_( $client, "421 service not available$eol" );
}
***************
*** 124,129 ****
( $command =~ /HELP/i ) ||
( $command =~ /RSET/i ) ) {
! echo_response( $self, $mail, $client, $command );
! flush_extra( $self, $mail, $client, 0 );
next;
}
--- 129,134 ----
( $command =~ /HELP/i ) ||
( $command =~ /RSET/i ) ) {
! $self->echo_response_( $mail, $client, $command );
! $self->flush_extra_( $mail, $client, 0 );
next;
}
***************
*** 132,139 ****
# Get the message from the remote server, if there's an error then we're done, but if not then
# we echo each line of the message until we hit the . at the end
! if ( echo_response( $self, $mail, $client, $command ) ) {
$count += 1;
! $self->{pop3}->classify_and_modify( $self, $mail, $client, $download_count, $count, 0, '' );
! flush_extra( $self, $mail, $client, 0 );
next;
}
--- 137,146 ----
# Get the message from the remote server, if there's an error then we're done, but if not then
# we echo each line of the message until we hit the . at the end
! if ( $self->echo_response_( $mail, $client, $command ) ) {
$count += 1;
! $self->{classifier__}->classify_and_modify( $client, $mail, $download_count, $count, 0, '' );
! my $response = <$mail>;
! $self->tee_( $client, $response );
! $self->flush_extra_( $mail, $client, 0 );
next;
}
***************
*** 145,152 ****
if ( $command =~ /QUIT/i ) {
if ( $mail ) {
! echo_response( $self, $mail, $client, $command );
close $mail;
} else {
! tee( $self, $client, "221 goodbye$eol" );
}
last;
--- 152,159 ----
if ( $command =~ /QUIT/i ) {
if ( $mail ) {
! $self->echo_response_( $mail, $client, $command );
close $mail;
} else {
! $self->tee_( $client, "221 goodbye$eol" );
}
last;
***************
*** 155,163 ****
# Don't know what this is so let's just pass it through and hope for the best
if ( $mail && $mail->connected ) {
! echo_response( $self, $mail, $client, $command );
! flush_extra( $self, $mail, $client, 0 );
next;
} else {
! tee( $self, $client, "500 unknown command or bad syntax$eol" );
last;
}
--- 162,170 ----
# Don't know what this is so let's just pass it through and hope for the best
if ( $mail && $mail->connected ) {
! $self->echo_response_( $mail, $client, $command );
! $self->flush_extra_( $mail, $client, 0 );
next;
} else {
! $self->tee_( $client, "500 unknown command or bad syntax$eol" );
last;
}
***************
*** 166,320 ****
close $mail if defined( $mail );
close $client;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # get_response
- #
- # $mail The stream (created with IO::) to send the message to (the remote mail server)
- # $client The local mail client (created with IO::) that needs the response
- # $command The text of the command to send (we add an EOL)
- #
- # Send $command to $mail, receives the response and echoes it to the $client and the debug
- # output. Returns the response
- #
- # ---------------------------------------------------------------------------------------------
- sub get_response
- {
- my ( $self, $mail, $client, $command ) = @_;
-
- unless ( $mail ) {
- # $mail is undefined - return an error intead of crashing
- tee( $self, $client, "554 Transaction failed$eol" );
- return "554";
- }
-
- # Send the command (followed by the appropriate EOL) to the mail server
- tee( $self, $mail, $command. $eol );
-
- my $response;
-
- # Retrieve a single string containing the response
- if ( $mail->connected ) {
- $response = <$mail>;
-
- if ( $response ) {
- # Echo the response up to the mail client
- tee( $self, $client, $response );
- } else {
- # An error has occurred reading from the mail server
- tee( $self, $client, "554 Transaction failed$eol" );
- return "554";
- }
- }
-
- return $response;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # echo_response
- #
- # $mail The stream (created with IO::) to send the message to (the remote mail server)
- # $client The local mail client (created with IO::) that needs the response
- # $command The text of the command to send (we add an EOL)
- #
- # Send $command to $mail, receives the response and echoes it to the $client and the debug
- # output. Returns true if the response was +OK and false if not
- #
- # ---------------------------------------------------------------------------------------------
- sub echo_response
- {
- my ( $self, $mail, $client, $command ) = @_;
-
- # Determine whether the response began with the string +OK. If it did then return 1
- # else return 0
- return ( get_response( $self, $mail, $client, $command ) < 400 );
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # verify_connected
- #
- # $mail The handle of the real mail server
- # $client The handle to the mail client
- # $hostname The host name of the remote server
- # $port The port
- #
- # Check that we are connected to $hostname on port $port putting the open handle in $mail.
- # Any messages need to be sent to $client
- #
- # ---------------------------------------------------------------------------------------------
- sub verify_connected
- {
- my ( $self, $mail, $client, $hostname, $port ) = @_;
-
- # Check to see if we are already connected
- return $mail if ( $mail && $mail->connected );
-
- # Connect to the real mail server on the standard port
- $mail = IO::Socket::INET->new(
- Proto => "tcp",
- PeerAddr => $hostname,
- PeerPort => $port );
-
- # Check that the connect succeeded for the remote server
- if ( $mail ) {
- if ( $mail->connected ) {
- # Wait 10 seconds for a response from the remote server and if
- # there isn't one then give up trying to connect
- my $selector = new IO::Select( $mail );
- last unless () = $selector->can_read($self->{configuration}->{configuration}{timeout});
-
- # Read the response from the real server and say OK
- my $buf = '';
- my $max_length = 8192;
- my $n = sysread( $mail, $buf, $max_length, length $buf );
-
- debug( $self, "Connection returned: $buf" );
- if ( !( $buf =~ /[\r\n]/ ) ) {
- for my $i ( 0..4 ) {
- flush_extra( $self, $mail, $client, 1 );
- }
- }
- return $mail;
- }
- }
-
- # Tell the client we failed
- tee( $self, $client, "554 Transaction failed failed to connect to $hostname:$port$eol" );
-
- return undef;
- }
-
- # ---------------------------------------------------------------------------------------------
- #
- # flush_extra - Read extra data from the mail server and send to client, this is to handle
- # POP servers that just send data when they shouldn't. I've seen one that sends
- # debug messages!
- #
- # $mail The handle of the real mail server
- # $client The mail client talking to us
- # $discard If 1 then the extra output is discarded
- #
- # ---------------------------------------------------------------------------------------------
- sub flush_extra
- {
- my ( $self, $mail, $client, $discard ) = @_;
-
- if ( $mail ) {
- if ( $mail->connected ) {
- my $selector = new IO::Select( $mail );
- my $buf = '';
- my $max_length = 8192;
-
- while( 1 ) {
- last unless () = $selector->can_read(0.01);
- last unless ( my $n = sysread( $mail, $buf, $max_length, length $buf ) );
-
- tee( $self, $client, $buf ) if ( $discard != 1 );
- }
- }
- }
}
--- 173,176 ----
|