qpsmtpd/plugins/spamassassin
Ask Bjørn Hansen 1e113721d0 spamassassin plugin
git-svn-id: https://svn.perl.org/qpsmtpd/branches/v010@39 958fd67b-6ff1-0310-b445-bb7760255be9
2002-08-06 12:27:35 +00:00

66 lines
1.6 KiB
Plaintext

#
# Requires the spamd patch attached to this spamassassin bug:
# http://bugzilla.spamassassin.org/show_bug.cgi?id=660
#
# ... or you can change YAREPORT to REPORT below; but the headers
# will be a bit different than you are used to.
#
#
use Socket qw(:DEFAULT :crlf);
use IO::Handle;
sub register {
my ($self, $qp) = @_;
$self->register_hook("data_post", "check_spam");
}
#my $rv = check_spam();
#die "failure!" unless defined $rv;
#print "rv: $rv\n";
sub check_spam {
my ($self, $transaction) = @_;
my $remote = 'localhost';
my $port = 783;
if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
die "No port" unless $port;
my $iaddr = inet_aton($remote) || die "no host: $remote";
my $paddr = sockaddr_in($port, $iaddr);
my $proto = getprotobyname('tcp');
socket(SPAMD, PF_INET, SOCK_STREAM, $proto) || die "socket: $!";
connect(SPAMD, $paddr) || warn "SA: connect: $!", return undef;
SPAMD->autoflush(1);
$transaction->body_resetpos;
print SPAMD "YAREPORT SPAMC/1.0" . CRLF;
# or CHECK or REPORT or SYMBOLS
while (my $line = $transaction->body_getline) {
chomp $line;
print SPAMD $line, CRLF;
}
print SPAMD CRLF;
shutdown(SPAMD, 1);
my $line0 = <SPAMD>; # get the first protocol lines out
if ($line0) {
$transaction->header->add("X-Spam-Check-By", $self->qp->config('me'));
}
while (<SPAMD>) {
warn "GOT FROM SPAMD1: $_";
next unless m/\S/;
s/\r?\n$/\n/;
my @h = split /: /, $_, 2;
$transaction->header->add(@h);
last if $h[0] eq "Spam" and $h[1] =~ m/^False/;
}
return (OK);
}