From 5c3bd220aaccd49ebbcbfb4324ac4c789d116273 Mon Sep 17 00:00:00 2001 From: jaredj Date: Sat, 28 Feb 2009 15:13:46 +0800 Subject: Run hook_reset_transaction after all connections This makes hook_reset_transaction a bit more useful by running it on disconnections. It also ensures that hook_disconnect runs when the client disconnects without QUITing. --- lib/Qpsmtpd/SMTP.pm | 1 + lib/Qpsmtpd/TcpServer.pm | 4 ++++ lib/Qpsmtpd/TcpServer/Prefork.pm | 5 +++++ 3 files changed, 10 insertions(+), 0 deletions(-) diff --git a/lib/Qpsmtpd/SMTP.pm b/lib/Qpsmtpd/SMTP.pm index f669055..0735f0c 100644 --- a/lib/Qpsmtpd/SMTP.pm +++ b/lib/Qpsmtpd/SMTP.pm @@ -576,6 +576,7 @@ sub quit_respond { sub disconnect { my $self = shift; $self->run_hooks("disconnect"); + $self->connection->notes(disconnected => 1); $self->reset_transaction; } diff --git a/lib/Qpsmtpd/TcpServer.pm b/lib/Qpsmtpd/TcpServer.pm index 07d8d16..de3504f 100644 --- a/lib/Qpsmtpd/TcpServer.pm +++ b/lib/Qpsmtpd/TcpServer.pm @@ -115,6 +115,10 @@ sub read_input { alarm $timeout; } alarm(0); + return if $self->connection->notes('disconnected'); + $self->reset_transaction; + $self->run_hooks('disconnect'); + $self->connection->notes(disconnected => 1); } sub respond { diff --git a/lib/Qpsmtpd/TcpServer/Prefork.pm b/lib/Qpsmtpd/TcpServer/Prefork.pm index 28f60dc..2728cea 100644 --- a/lib/Qpsmtpd/TcpServer/Prefork.pm +++ b/lib/Qpsmtpd/TcpServer/Prefork.pm @@ -35,6 +35,11 @@ sub read_input { 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"; -- 1.7.2.2