On 2006-11-16 09:19:23 +0100, Kjetil Kjernsmo wrote:
> My little plugin isn't working as intended... :-( BTW, Peter, I looked 
> more carefully at yours, but I don't really have an aliases list... 

Yes, mine is probably a bit of overkill for just checking against a list
of recipients although you can do that by simply mapping each valid
address to itself:

[EMAIL PROTECTED]: [EMAIL PROTECTED]
[EMAIL PROTECTED]: [EMAIL PROTECTED]
[EMAIL PROTECTED]: [EMAIL PROTECTED]
...



> But I poked around a bit, and now my plugin looks like this:
> 
> sub hook_rcpt {
>   my ($self, $transaction, $recipient) = @_;
>   my @addresses = $self->qp->config('validaddresses') || return 
> DECLINED;
>   foreach my $ok (@addresses) {
>     $ok =~ s/^\s*(\S+).*/$1/;
>     return DECLINED if (lc($recipient->user) eq lc($ok)); # That's a 
> valid address
>   }
>   $transaction->notes('rcptlist', "Sorry, this address was not on my 
> list of valid addresses"); # Then it doesn't exist
>   return DENY;
> }
> 
> This rejects everything... :-(
[...]
> How do I debug something like this?

Usually, when I'm looking for a bug in a plugin, I just add lots of log
messages:

sub hook_rcpt {
  my ($self, $transaction, $recipient) = @_;
  my @addresses = $self->qp->config('validaddresses') || return DECLINED;
  $self->log(LOGDEBUG, "going to check " . scalar(@addresses) . " addresses");
  foreach my $ok (@addresses) {
    $ok =~ s/^\s*(\S+).*/$1/;
    $self->log(LOGDEBUG, "checking " . lc($recipient->user) . " against " . 
lc($ok));
    if (lc($recipient->user) eq lc($ok)) {
      # That's a valid address
      $self->log(LOGDEBUG, "matched");
      return DECLINED;
    }
  }
  $self->log(LOGDEBUG, "no match found");
  $transaction->notes('rcptlist', "Sorry, this address was not on my list of 
valid addresses"); # Then it doesn't exist
  return DENY;
}

And then start the server with loglevel LOGDEBUG.

If I'm really desperate I run qpsmtpd (not -forkserver) in the perl debugger:

export TCPREMOTEIP=127.0.0.1 (to make qpsmtpd believe it has been started from 
tcpserver)
perl -Tw -d qpsmtpd

I also should really, really take a look at Test::Qpsmtpd. I find that I
spend much less time debugging if I get into the habit of writing test
cases first. Unfortunately I haven't got that habit with qpsmtpd yet.

        hp

-- 
   _  | Peter J. Holzer    | Schlagfertigkeit ist das, was einem
|_|_) | Sysadmin WSR       | auf dem Nachhauseweg einfällt.
| |   | [EMAIL PROTECTED]         |    -- Lars 'Cebewee' Noschinski in dasr.
__/   | http://www.hjp.at/ |

Attachment: signature.asc
Description: Digital signature

Reply via email to