diff --git a/lib/Qpsmtpd.pm b/lib/Qpsmtpd.pm index 1afef1a..f0222fd 100644 --- a/lib/Qpsmtpd.pm +++ b/lib/Qpsmtpd.pm @@ -369,11 +369,9 @@ sub run_continuation { sub hook_responder { my ($self, $hook, $msg, $args) = @_; - my $code = shift @$msg; - my $responder = $hook . '_respond'; - if (my $meth = $self->can($responder)) { + if (my $meth = $self->can($hook . '_respond')) { return $meth->($self, $code, $msg, $args); } return $code, @$msg; diff --git a/t/qpsmtpd.t b/t/qpsmtpd.t index b18a6a5..fddee2d 100644 --- a/t/qpsmtpd.t +++ b/t/qpsmtpd.t @@ -24,6 +24,9 @@ __hooks_none(); ok(my ($smtpd, $conn) = Test::Qpsmtpd->new_conn(), "get new connection"); __hooks(); +__register_hook(); +__hook_responder(); + __temp_file(); __temp_dir(); __size_threshold(); @@ -61,6 +64,35 @@ sub __hooks_none { is_deeply($r, [], 'hooks, empty, specified'); } +sub __hook_responder { + # my ($self, $hook, $msg, $args) = @_; + my ($code, $msg) = $qp->hook_responder('test-hook', ['test code','test mesg'], ['test-arg']); + is($code, 'test code', "hook_responder, code"); + is($msg, 'test mesg', "hook_responder, test msg"); + + ($code, $msg) = $smtpd->hook_responder('connect', ['test code','test mesg'], ['test-arg']); + is($code->[0], 220, "hook_responder, code"); + ok($code->[1] =~ /ESMTP qpsmtpd/, "hook_responder, message: ". $code->[1]); + + my $rej_msg = 'Your father smells of elderberries'; + #($smtpd, $conn) = Test::Qpsmtpd->new_conn(); + ($code, $msg) = $smtpd->hook_responder('connect', [DENY, $rej_msg]); +# warn Data::Dumper::Dumper($code); +# warn Data::Dumper::Dumper($msg); +# is($code, undef, "hook_responder, disconnected yields undef code"); + is($msg, undef, "hook_responder, disconnected yields undef msg"); + + #warn Data::Dumper::Dumper($msg); +} + +sub __register_hook { + my $hook = 'test'; + is( $Qpsmtpd::hooks->{'test'}, undef, "_register_hook, test hook is undefined"); + + $smtpd->_register_hook('test', 'fake-code-ref'); + is_deeply( $Qpsmtpd::hooks->{'test'}, ['fake-code-ref'], "test hook is registered"); +} + sub __log { my $warned = ''; local $SIG{__WARN__} = sub {