qpsmtpd Wiki


You are here: start » plugins » spam » spamtrap


You are currently not logged in! Enter your authentication credentials below to log in. You need to have cookies enabled to log in.


You don't have an account yet? Just get one: Register

Forgotten your password? Get a new one: Set new password

Plug-in Summary

Plug-in name: spamtrap
Info: A spam trap
Author: tyskjohan
Email: Won't say
Compatibility: all
Download: here


I just put this up quickly because someone asked a question related to this on the mailing list.

=head1 NAME

spamtrap - handle spamtrap addresses





=head1 AUTHOR

Written by Johan Almqvist


use Mail::Address;

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

  if (@args > 0) {
    $self->{_spamtrap} = $args[0];
    if (@args > 1) {
      $self->log(LOGWARN, "WARNING: Ignoring additional arguments.");
    $self->register_hook("rcpt", "rcpt_handler");
    $self->register_hook("data_post", "data_handler");
  else {
    $self->log(LOGWARN, "WARNING: No spamtrap address provided");  

sub rcpt_handler {
	my ($self, $transaction, $rcpt) = @_;

	my $addr = lc $rcpt->address or return DECLINED;
	my $host = lc $rcpt->host or return DECLINED;
	my $user = lc $rcpt->user or return DECLINED;

	for my $h ($self->qp->config('spamtraps')) {
		next unless $h;
		$h = lc $h;

		if ($addr eq $h or $host eq $h) {
			$transaction->notes('whitelist', 1);
			$transaction->notes('denysoft_greylist', 0);
			$transaction->notes('spamtrap', 1);
			$self->log(2,"Recipient $addr is a spamtrap");
			return (OK, 'User is a spam trap. May you burn in hell.');

sub data_handler {
	my ($self, $transaction) = @_;

	my @spamtrap = Mail::Address->parse($self->{_spamtrap});
	if ($transaction->notes('spamtrap')) {
		return OK;
	return DECLINED;