On Sun, 31 Dec 2006 01:40:47 +0100
Joe Knall <[EMAIL PROTECTED]> wrote:
> On Sat, 2006-12-2006 09:17 Hanno Hecker wrote:
> > sub hook_rcpt {
> > my ($self, $transaction, $recipient, %param) = @_;
> > my $sender = $transaction->sender;
> >
> > Both ($sender, $recipient) are Qpsmtpd::Address objects.
>
> Thanks a lot, this does exactly what it should :)
>
> Next question: where to initialize the connection to my database?
> I think the init-method should be the correct place, isn't it?
> And should it be stored in $connection->notes?
You don't have to put this in a connection note if you're not
using this from outside (i.e. from another plugin), just use
$self->{_dbh} = $dbh;
> Is there maybe a better place?
>
> looks like this:
> my $dbh;
> eval {
> $dbh = DBI->connect(
> $dbConfig{dsn},
> $dbConfig{user},
> $dbConfig{password},
> {'RaiseError' => 1}
> )
> };
> die ("Can't connect to db:[EMAIL PROTECTED]") if $@;
This one is a bit tricky and depends on what flavour of qpsmtpd you are
running. A connection fh to the database created in init() cannot be
used in -forkserver and -prefork, as the DB will be confused if
multiple queries arrive at the same fh/connection (from the DB's point
of view) at the same time. In both of these flavours the forking is
done after loading the plugins.
I don't know about -async, but I guess you will either make this
one really slow (all other smtp connections wait until the query is
done) or have the same problems with multiple queries to the same fh.
If you're not going to read data from the DB which is needed before
hook_connect(), this should be a good place for -forkserver and
-prefork.
The best thing[tm] would be a uniform Qpsmtpd::DBI module, which
handles all flavours of qpsmtpd. I can do this for -forkserver and
-prefork, but I will need help for Apache::Qpsmtpd and -async.
Hanno