#!/afs/athena/contrib/perl/perl

push (@INC, "/afs/sipb.mit.edu/contrib/perl/nntp");

$newsgroup = $ARGV[0];
$article = $ARGV[1];

require "nntp.pl";

$default_timeout = 200;
$cr = '\r?\n';

sub my_setgroup
{
    local($conn) = $_[0];
    local($ng) = $_[1];
    local($artcls);

    &chat'print($conn, "group $ng\n");
    ($artcls = &chat'expect($conn, $default_timeout,
                            "^211 .*$cr", '$&',
                            "^4.. .*$cr", '()',
                            "TIMEOUT", 'die "Server timeout\n"',
                            "EOF", 'die "I/O error\n"')) || return ();
    (split(/ /, $artcls))[1..3];
}

$server = &nntp'connect;

&my_setgroup ($server, $newsgroup);

$text = &nntp'article ($server, $article);

print "$text\n";

&chat'print ($server, "quit\n");
