1 |
From 5c3bd220aaccd49ebbcbfb4324ac4c789d116273 Mon Sep 17 00:00:00 2001 |
2 |
From: jaredj <jaredj@nmgi.com> |
3 |
Date: Sat, 28 Feb 2009 15:13:46 +0800 |
4 |
Subject: Run hook_reset_transaction after all connections |
5 |
|
6 |
This makes hook_reset_transaction a bit more useful by running it on |
7 |
disconnections. It also ensures that hook_disconnect runs when the |
8 |
client disconnects without QUITing. |
9 |
--- |
10 |
lib/Qpsmtpd/SMTP.pm | 1 + |
11 |
lib/Qpsmtpd/TcpServer.pm | 4 ++++ |
12 |
lib/Qpsmtpd/TcpServer/Prefork.pm | 5 +++++ |
13 |
3 files changed, 10 insertions(+), 0 deletions(-) |
14 |
|
15 |
diff --git a/lib/Qpsmtpd/SMTP.pm b/lib/Qpsmtpd/SMTP.pm |
16 |
index f669055..0735f0c 100644 |
17 |
--- a/lib/Qpsmtpd/SMTP.pm |
18 |
+++ b/lib/Qpsmtpd/SMTP.pm |
19 |
@@ -576,6 +576,7 @@ sub quit_respond { |
20 |
sub disconnect { |
21 |
my $self = shift; |
22 |
$self->run_hooks("disconnect"); |
23 |
+ $self->connection->notes(disconnected => 1); |
24 |
$self->reset_transaction; |
25 |
} |
26 |
|
27 |
diff --git a/lib/Qpsmtpd/TcpServer.pm b/lib/Qpsmtpd/TcpServer.pm |
28 |
index 07d8d16..de3504f 100644 |
29 |
--- a/lib/Qpsmtpd/TcpServer.pm |
30 |
+++ b/lib/Qpsmtpd/TcpServer.pm |
31 |
@@ -115,6 +115,10 @@ sub read_input { |
32 |
alarm $timeout; |
33 |
} |
34 |
alarm(0); |
35 |
+ return if $self->connection->notes('disconnected'); |
36 |
+ $self->reset_transaction; |
37 |
+ $self->run_hooks('disconnect'); |
38 |
+ $self->connection->notes(disconnected => 1); |
39 |
} |
40 |
|
41 |
sub respond { |
42 |
diff --git a/lib/Qpsmtpd/TcpServer/Prefork.pm b/lib/Qpsmtpd/TcpServer/Prefork.pm |
43 |
index 28f60dc..2728cea 100644 |
44 |
--- a/lib/Qpsmtpd/TcpServer/Prefork.pm |
45 |
+++ b/lib/Qpsmtpd/TcpServer/Prefork.pm |
46 |
@@ -35,6 +35,11 @@ sub read_input { |
47 |
or $self->respond(502, "command unrecognized: '$_'"); |
48 |
alarm $timeout; |
49 |
} |
50 |
+ unless ($self->connection->notes('disconnected')) { |
51 |
+ $self->reset_transaction; |
52 |
+ $self->run_hooks('disconnect'); |
53 |
+ $self->connection->notes(disconnected => 1); |
54 |
+ } |
55 |
}; |
56 |
if ($@ =~ /^disconnect_tcpserver/) { |
57 |
die "disconnect_tcpserver"; |
58 |
-- |
59 |
1.7.2.2 |
60 |
|