I noticed the previous iteration of this patch would allow cached global
config values to override per-recipient config values. The attached
patch adds the following change to avoid this:
--- lib/Qpsmtpd.pm (revision 967)
+++ lib/Qpsmtpd.pm (working copy)
@@ -142,7 +142,7 @@
my ($self, $c, $type) = @_;
#my $timer = $SAMPLER->("config", undef, 1);
- if ($_config_cache->{$c}) {
+ if ($_config_cache->{$c} and ref $type ne 'Qpsmtpd::Address') {
return wantarray ? @{$_config_cache->{$c}} :
$_config_cache->{$c}->[0];
}
I don't know if it would be useful/advisable to try to cache per-recip
config results keyed to the address or something -- I think that would
probably be potentially unsafe. rcpt_config plugins can always do their
own caching if they want.
-Jared
Jared Johnson wrote:
Adding a config method for Qpsmtpd::Address objects turned out to be
relatively straightforward. I was reluctant to subclass Qpsmtpd, but
this actually seems like it could be useful in the future; at any rate,
it gets the job done pretty nicely. This patch will only be useful for
people who define 'rcpt_config' plugins, but if anyone shares my
sentiments then there will be folks chomping at the bit like I am to
write these. Feedback is welcome...
-Jared
Index: lib/Qpsmtpd.pm
===================================================================
--- lib/Qpsmtpd.pm (revision 967)
+++ lib/Qpsmtpd.pm (working copy)
@@ -142,7 +142,7 @@
my ($self, $c, $type) = @_;
#my $timer = $SAMPLER->("config", undef, 1);
- if ($_config_cache->{$c}) {
+ if ($_config_cache->{$c} and ref $type ne 'Qpsmtpd::Address') {
return wantarray ? @{$_config_cache->{$c}} : $_config_cache->{$c}->[0];
}
@@ -150,7 +150,8 @@
#warn "SELF->config($c) ", ref $self;
- my ($rc, @config) = $self->run_hooks_no_respond("config", $c);
+ my $hook = ref $type eq 'Qpsmtpd::Address' ? 'rcpt_config' : 'config';
+ my ($rc, @config) = $self->run_hooks_no_respond($hook, $c);
@config = () unless $rc == OK;
if (wantarray) {
Index: lib/Qpsmtpd/Address.pm
===================================================================
--- lib/Qpsmtpd/Address.pm (revision 967)
+++ lib/Qpsmtpd/Address.pm (working copy)
@@ -1,6 +1,8 @@
-#!/usr/bin/perl -w
package Qpsmtpd::Address;
use strict;
+use warnings;
+use Qpsmtpd;
+our @ISA = qw(Qpsmtpd);
=head1 NAME
@@ -317,6 +319,18 @@
return $self->{_host};
}
+=head2 config($value)
+
+Looks up a configuration directive based on this recipient, using any plugins that utilize
+hook_rcpt_config
+
+=cut
+
+sub config {
+ my ($self,$key) = @_;
+ $self->SUPER::config($key,$self);
+}
+
sub _addr_cmp {
require UNIVERSAL;
my ($left, $right, $swap) = @_;
Index: lib/Qpsmtpd/Plugin.pm
===================================================================
--- lib/Qpsmtpd/Plugin.pm (revision 967)
+++ lib/Qpsmtpd/Plugin.pm (working copy)
@@ -4,7 +4,7 @@
# more or less in the order they will fire
our @hooks = qw(
- logging config post-fork pre-connection connect ehlo_parse ehlo
+ logging config rcpt_config post-fork pre-connection connect ehlo_parse ehlo
helo_parse helo auth_parse auth auth-plain auth-login auth-cram-md5
rcpt_parse rcpt_pre rcpt mail_parse mail mail_pre
data data_post queue_pre queue queue_post vrfy noop