Hi,

I've written a custom Qpsmtpd plugin. I'm having some problems with
values I put in $self. In my register sub I parse some files and put the
resulting data structures into $self. Then in my hook_connect sub I
check whether the files have been modified and if so I reparse the files
and update the values in $self.

The problem is that the updated values seem to be forgotten as soon as
my hook_connect sub ends. The next time hook_connect is called the old
values are still in $self and the files are parsed again.

Here are the relevant pieces of my code:

sub get_file_ts {
  my ($file) = @_;
  my $mtime = (stat($file))[9] or die "Could not stat file $file: $!";
  return $mtime;
}

sub read_files_if_needed {
  my ($self) = @_;

  my $tts = get_file_ts($self->{_transport_file});
  my $rts = get_file_ts($self->{_recipients_file});
  my $ats = get_file_ts($self->{_aliases_file});

  if ($self->{_tts} < $tts or $self->{_rts} < $rts or $self->{_ats} <
$ats) {
    my ($transports, $forwarded, $filtered, $aliases) = read_files
$self->{_transport_file},
                $self->{_recipients_file}, $self->{_aliases_file};
    $self->{_transports} = $transports;
    $self->{_forwarded} = $forwarded;
    $self->{_filtered} = $filtered;
    $self->{_aliases} = $aliases;
    $self->{_tts} = $tts;
    $self->{_rts} = $rts;
    $self->{_ats} = $ats;
  }
}

sub register {
  my ($self, $qp, @args) = @_;

  if (@args > 2) {
    $self->{_transport_file} = $args[0];
    $self->{_recipients_file} = $args[1];
    $self->{_aliases_file} = $args[2];
    $self->log(LOGWARN, "WARNING: Ignoring additional arguments.") if
(@args > 3);
  } else {
    die("No transport file, no recipients and/or no aliases file
specified in config");
  }

  $self->{_tts} = $self->{_rts} = $self->{_ats} = 0;

  read_files_if_needed $self;
}

sub hook_connect {
  my ($self,$transaction) = @_;
  read_files_if_needed $self;
  # If I print $self->{_tts} here it will have the updated value.
  return (DECLINED);
}

I have verified that the timestamps in $self have the updated values
after the call to read_files_if_needed in hook_connect. But the next
time hook_connect is called the values are back to what they were before
the first call to hook_connect. Can anyone tell me what I am doing
wrong? Maybe Qpsmtpd doesn't allow changing the values in $self after
register has been called? Or maybe I have made a trivial mistake in my
code (I'm a Perl newbie)?

I'm using qpsmtpd 0.32 on Debian Etch. Thanks for any help.

-- 
Niklas Therning
www.spamdrain.net

Reply via email to