More adventures in Qpsmtpd.pm

Phred on 2006-10-20T16:18:34

So I've been getting mail forwarded to me from a previous job, the people there were kind enough to do that for me so that I could receive emails from an article I wrote at perl.com. This allowed me to give them some props while still responding to emails about the article.

Now the problem here has been that the volume of spam I get through that link has gotten out of control. I get about 100 spams from when I go to sleep and when I wake up.

So I wrote a short qpsmtpd plugin to take care of this problem.

sub hook_data_post {
  my ( $self, $transaction ) = @_;
  my $recipient = $transaction->header->get('To');
  chomp($recipient);
  my $addr = 'fmoyer@xxxxxxx.com';
  if (lc($recipient) eq $addr) {
    $self->log(LOGINFO, "$domain BLOCKED");
    return (DENY, "New address is fred at redhotpenguin dot com");
  }
  return DECLINED;
}

This stops the spam, but allows anyone legitimate who gets the bounce message to be informed of my new address. I had to use the hook _data_post callback instead of hook_rcpt since the rcpt hook picks up the address the mail was forwarded to. Another problem solved :)