2006-05-31 22:54:03 +02:00
|
|
|
package Qpsmtpd::TcpServer::Prefork;
|
|
|
|
use Qpsmtpd::TcpServer;
|
|
|
|
use Qpsmtpd::SMTP::Prefork;
|
2006-11-22 17:30:37 +01:00
|
|
|
use Qpsmtpd::Constants;
|
2006-05-31 22:54:03 +02:00
|
|
|
|
|
|
|
@ISA = qw(Qpsmtpd::SMTP::Prefork Qpsmtpd::TcpServer);
|
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
my $first_0;
|
2006-05-31 22:54:03 +02:00
|
|
|
|
|
|
|
sub start_connection {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
#reset info
|
2013-04-21 06:08:43 +02:00
|
|
|
$self->{_connection} = Qpsmtpd::Connection->new(); #reset connection
|
2007-08-28 20:42:01 +02:00
|
|
|
$self->reset_transaction;
|
2006-11-22 17:30:37 +01:00
|
|
|
$self->SUPER::start_connection(@_);
|
2006-05-31 22:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub read_input {
|
2013-04-21 06:08:43 +02:00
|
|
|
my $self = shift;
|
2006-05-31 22:54:03 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
my $timeout = $self->config('timeoutsmtpd') # qmail smtpd control file
|
|
|
|
|| $self->config('timeout') # qpsmtpd control file
|
|
|
|
|| 1200; # default value
|
2006-05-31 22:54:03 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
alarm $timeout;
|
|
|
|
eval {
|
|
|
|
while (<STDIN>) {
|
|
|
|
alarm 0;
|
|
|
|
$_ =~ s/\r?\n$//s; # advanced chomp
|
|
|
|
$self->log(LOGINFO, "dispatching $_");
|
|
|
|
$self->connection->notes('original_string', $_);
|
|
|
|
defined $self->dispatch(split / +/, $_, 2)
|
|
|
|
or $self->respond(502, "command unrecognized: '$_'");
|
|
|
|
alarm $timeout;
|
|
|
|
}
|
|
|
|
unless ($self->connection->notes('disconnected')) {
|
|
|
|
$self->reset_transaction;
|
|
|
|
$self->run_hooks('disconnect');
|
|
|
|
$self->connection->notes(disconnected => 1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if ($@ =~ /^disconnect_tcpserver/) {
|
|
|
|
die "disconnect_tcpserver";
|
2006-05-31 22:54:03 +02:00
|
|
|
}
|
2013-04-21 06:08:43 +02:00
|
|
|
else {
|
|
|
|
$self->run_hooks("post-connection");
|
|
|
|
$self->connection->reset;
|
|
|
|
die "died while reading from STDIN (probably broken sender) - $@";
|
2009-02-28 08:13:46 +01:00
|
|
|
}
|
2013-04-21 06:08:43 +02:00
|
|
|
alarm(0);
|
2006-05-31 22:54:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub respond {
|
2013-04-21 06:08:43 +02:00
|
|
|
my ($self, $code, @messages) = @_;
|
2008-09-26 19:40:04 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
if (!$self->check_socket()) {
|
|
|
|
$self->log(LOGERROR,
|
|
|
|
"Lost connection to client, cannot send response.");
|
2014-09-18 03:28:51 +02:00
|
|
|
return 0;
|
2013-04-21 06:08:43 +02:00
|
|
|
}
|
2008-09-26 19:40:04 +02:00
|
|
|
|
2013-04-21 06:08:43 +02:00
|
|
|
while (my $msg = shift @messages) {
|
|
|
|
my $line = $code . (@messages ? "-" : " ") . $msg;
|
|
|
|
$self->log(LOGINFO, $line);
|
|
|
|
print "$line\r\n"
|
|
|
|
or ($self->log(LOGERROR, "Could not print [$line]: $!"), return 0);
|
|
|
|
}
|
|
|
|
return 1;
|
2006-05-31 22:54:03 +02:00
|
|
|
}
|
|
|
|
|
2006-11-22 17:30:37 +01:00
|
|
|
sub disconnect {
|
2013-04-21 06:08:43 +02:00
|
|
|
my $self = shift;
|
|
|
|
$self->log(LOGINFO, "click, disconnecting");
|
|
|
|
$self->SUPER::disconnect(@_);
|
|
|
|
$self->run_hooks("post-connection");
|
|
|
|
$self->connection->reset;
|
|
|
|
die "disconnect_tcpserver";
|
2006-11-22 17:30:37 +01:00
|
|
|
}
|
|
|
|
|
2006-05-31 22:54:03 +02:00
|
|
|
1;
|