#!/usr/bin/perl -w
# Copyright (C) 2005 McAfee Inc. All rights reserved.

use strict;
use IO::Socket;

my $port = $ARGV[0] || 783;

$SIG{PIPE} = sub { die "caught SIGPIPE\n" };

my $sock = IO::Socket::INET->new(
		PeerHost => "127.0.0.1",
		PeerPort => $port,
		Proto => "tcp",
		Timeout => 60,
		)
		or die "can't connect to localhost:$port: $!\n";

$sock->syswrite("CHECK SPAMC/1.1\r\n\r\n") or die "syswrite error: $!\n";
$sock->shutdown(1) or die "shutdown error: $!\n";

my $resp = <$sock>;
my $ret = ($resp eq "SPAMD/1.1 0 EX_OK\r\n" ? 0 : 1);
print $resp;
while (<$sock>) { print }

exit $ret;

