#!/usr/bin/perl -w =head1 NAME blackpattern - Simple pattern-based SMTP rejector $Id$ =head1 DESCRIPTION This is a simple plugin to auto-reject any mail whose content matches one of a configured set of patterns. Useful for manual intervention to deal with flood incidents, or to check for a few high-confidence kill patterns in a lightweight fashion (leaving the more rigorous, statistical patterns to heavier plugins communicating w/ spamassassin et al). =head1 CONFIGURATION To enable the plugin, add it to I<~qpsmtpd/config/plugins>. The list of patterns should be placed in I in the config directory (typically I<~qpsmtpd/config>). The I file should contain a series of non-extended perl patterns, one per line. Blank lines and lines beginning with I<#> are ignored. These patterns will be checked against both the header and the body. =cut use strict; use warnings; sub register { my ($self, $qp, %args) = @_; $self->{action} = $args{action} || 'add-header'; my @patterns = $self->qp->config('black_patterns'); for (@patterns) { chomp; next if !$_ or /^\s*#/; push @{$self->{patterns}}, $_; } if (!@{$self->{patterns}}) { $self->log(LOGWARN, "No patterns configured"); return 0; } $self->register_hook('data_post', 'data_handler'); 1; } sub data_handler { my ($self, $txn) = @_; my $l; $txn->body_resetpos; while ($l = $txn->body_getline) { chomp $l; next if !$l; for my $pat (@{$self->{patterns}}) { if ($l =~ /$pat/) { $self->log(LOGWARN, "Matched blackpattern /$pat/"); return (DENY, 'Mail resembles spam'); #return (DECLINED); } } } return (DECLINED); }