chiark / gitweb /
--passive is a bit pointless for HTTP!
[bin.git] / archive-news.pl
1 #! /usr/bin/perl -w
2 use diagnostics;
3 use strict;
4
5 use Net::NNTP;
6
7 my $nntp;
8
9 sub usage ()
10 {
11     print STDERR <<"EOF";
12 Usage: $0 hostname newsgroup-name archive-directory
13 EOF
14     exit 1;
15 }
16
17 sub bail ($)
18 {
19     my $msg = shift;
20     $nntp->quit;
21     print STDERR "$msg\n";
22     exit 1;
23 }
24
25 my $host = shift or usage;
26 my $group = shift or usage;
27 my $archive = shift or usage;
28 -d $archive or usage;
29
30 opendir ARCHIVE, $archive or die "can't opendir $archive: $!";
31 my @list = grep m/^\d+$/, readdir ARCHIVE;
32 closedir ARCHIVE;
33
34 @list = sort { $a <=> $b } @list;
35 my $start = scalar @list ? $list[$#list] + 1 : 0;
36
37 $nntp = Net::NNTP->new($host);
38 # Bah, password in clear, oh well, it's only passworded to keep the
39 # howling masses out anyway ...
40 #$nntp->authinfo('afe', 'MyTest');
41
42 my ($narticles, $first, $last, $name) = $nntp->group($group);
43 (defined $first and defined $last) or bail "Couldn't set group to $group";
44
45 exit if $last <= $start;
46 $start = $first if $first > $start;
47
48 for my $index ($start..$last)
49 {
50     my $article = $nntp->article($index);
51     if (defined $article)
52     {
53         open ARTICLE, ">$archive/$index"
54             or die "can't open $archive/$index for writing: $!";
55         print ARTICLE join '', @$article;
56         close ARTICLE;
57     }
58     #print STDERR "$group $index\n";
59 }
60
61 $nntp->quit;
62