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

use strict;
use IO::Socket;

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

$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";


my $resp = <$sock>;
$resp=substr($resp, 0, 5);
my $ret = ($resp eq "* OK " ? 0 : 1);
$sock->shutdown(1) or die "shutdown error: $!\n";
while (<$sock>) { print }

exit $ret;

