Avoid passing Qpsmtpd object refs around

Use an instantiator in Qpsmtpd.pm for creating Qpsmtpd::Address objects instead
This commit is contained in:
Jared Johnson 2014-09-15 15:14:32 -05:00
parent 1253e73a4d
commit e9c56dc268
3 changed files with 16 additions and 7 deletions

View File

@ -648,6 +648,13 @@ sub auth_mechanism {
return (defined $self->{_auth_mechanism} ? $self->{_auth_mechanism} : "");
}
sub address {
my $self = shift;
my $addr = Qpsmtpd::Address->new(@_);
$addr->{qp} = $self;
return $addr;
}
1;
__END__

View File

@ -345,9 +345,14 @@ hook_user_config
=cut
sub qp {
my ($self) = @_;
return $self->{qp};
}
sub config {
my ($self,$key) = @_;
my $qp = $self->notes('qp_obj') or return;
my $qp = $self->qp or return;
return $qp->config($key,$self);
}

View File

@ -15,7 +15,6 @@ use Qpsmtpd::Transaction;
use Qpsmtpd::Plugin;
use Qpsmtpd::Constants;
use Qpsmtpd::Auth;
use Qpsmtpd::Address ();
use Qpsmtpd::Command;
my %auth_mechanisms = ();
@ -389,14 +388,13 @@ sub mail_pre_respond {
unless $from =~ /^<.*>$/;
if ($from eq "<>" or $from =~ m/\[undefined\]/ or $from eq "<#@[]>") {
$from = Qpsmtpd::Address->new("<>");
$from = $self->address("<>");
}
else {
$from = (Qpsmtpd::Address->parse($from))[0];
$from = $self->address($from);
}
return $self->respond(501, "could not parse your mail from command")
unless $from;
$from->notes('qp_obj',$self);
$self->run_hooks("mail", $from, %$param);
}
@ -481,12 +479,11 @@ sub rcpt_pre_respond {
return $self->respond(501, "could not parse recipient")
unless $rcpt =~ /^<.*>$/;
$rcpt = (Qpsmtpd::Address->parse($rcpt))[0];
$rcpt = $self->address($rcpt);
return $self->respond(501, "could not parse recipient")
if (!$rcpt or ($rcpt->format eq '<>'));
$rcpt->notes('qp_obj',$self);
$self->run_hooks("rcpt", $rcpt, %$param);
}