#!/usr/bin/perl -w
use strict;

## Copyright (c) 2000 Alex LaHurreau.
##
## Based on an example script from the News::Scan distribution
## Copyright (c) 1997 Greg Bacon
##
## This program is free software; you can distribute and/or modify it under
## the same terms as Perl itself.

use News::Scan;		# This module is also required by GroupSTAT.

use Getopt::Long;	# This is a standard module.
my %opt; 
GetOptions(\%opt, 'group=s', 'spool=s', 'server=s', 'help');

# If the user wants help, or forgets an option, display
# a list of options.
if($opt{'help'} || !($opt{'group'} && $opt{'spool'} && $opt{'server'})) {
	print STDERR <<"HELP";
This program downloads an entire newsgroup into the directory of
your choice.  All of the following options are mandatory:
	--group		The name of the group you want to download.
	--spool		The directory you want to save the files in.
			It MUST already exist before you run this program.
	--server	The news server to get the articles from.

To download 'misc.test' into /tmp/test from news.example.com, do this:
$0 --group='misc.test' --spool='/tmp/test' --server='news.example.com'
HELP
	exit 1;
}

my $scan = new News::Scan Group      => $opt{'group'},
                          Spool      => $opt{'spool'},
                          From       => 'nntp',
                          NNTPServer => $opt{'server'};

if (not defined $scan) {
    die "Failed to create News::Group object\n";
}
elsif ($scan->error) {
    die "Error: " . $scan->error . "\n";
}

print STDERR "Getting articles from $opt{server}...";
$scan->collect;
if ($scan->error) {
    die "\nError: " . $scan->error . "\n";
}
print STDERR "done!\n";

