mhonarc-users

Re: how to archive news

1998-07-07 10:05:16
Hello,

I have just installed MHonarc on my system because I would like to archive a
few news groups ( comp.unix.solaris, comp.mail.sendmail,
comp.dcom.lans.ethernet, and a few others ).  From what I can tell, MHonarc
needs these news messages in a file or group of files.  The only news access
I have is via NNTP.  Do I need to get another program to transfer these
files to my local system? (If so, which program). Or will MHonarc read these
groups straight from NNTP?

I made a small script which reads news articles and feed them to MHonArc
one by one.  It is not perfect, but it may show you some ideas.

-- 
Koichi Nakatani
Graphic Arts Center, Konica Corporation

--------------------------------------------------------------------------
#! /usr/bin/perl

# news2web.pl
#

use Net::NNTP;

### begin of configuration part ###
$mhonarc_path = "/usr/local/bin";
$newsserver = '@@@News Server@@@';

# path of 'pointer' file
# <newsgroup name>:<destination directory path>:<article number>
# for each line.
$news_pointer_fname = "/usr/local/etc/news/webgw/news2web.pointer";

### end of configuration part ###

sub prepare_directory {local($ng_root, $year) = @_;
        if (length($year) < 4) {
                if ($year >= 90) {
                        $year += 1900;
                } else {
                        $year += 2000;
                }
        }
        unless (-d "$ng_root" && -w "$ng_root") {
                die "$ng_root does not exist.\n";
        }
        unless (-d "$ng_root/$year") {
                `mkdir $ng_root/$year`;
        }
        "$ng_root/$year";
}

sub readgroup {my ($nntp, $group, $destination, $old_num) = @_;
        my ($num, $num_begin, $num_end) = $nntp->group($group);

        return $old_num if ($old_num >= $num_end);
        foreach $num ($old_num+1 .. $num_end) {
                @headers = @headers2 = ();
                *headers = $nntp->head($num);
                next if @headers == ();
                foreach $header (@headers) {
                        if ($header =~ s/^\s+/ /) {
                                chomp($headers2[$#headers2]);
                                $headers2[$#headers2] .= $header;
                        } else {
                                push(@headers2, $header);
                        }
                }
                my($from) = grep(/^From:\s/i, @headers2);
                ($date) = grep(/^Date:\s/i, @headers2);
                $date =~ s/^Date:\s+//i;
                my($year) = $date =~ /\d+ [A-Za-z]+ (\d+) \d+:\d+:\d+ \S+/;
                my $dir = &prepare_directory($destination, $year);
                open(OUT, "| $mhonarc_path/mhonarc -add -outdir $dir -rcfile 
/usr/local/lib/MHonArc/rcfiles/$group.rc");
                print OUT @headers2;
                print OUT "\n";
                @body = ();
                *body = $nntp->body($num);
                print OUT @body;
                close(OUT);
                sleep(1);
        }
        return $num_end;
}

#
# main
#
open(IN, $news_pointer_fname) || die $!;
@pointer = <IN>;
close(IN);

$nntp = Net::NNTP->new($newsserver);

print STDERR "$nntp\n";

@pointer_new = ();
foreach $line (@pointer) {
        if ($line =~ /^\s*#/) {
                push(@pointer_new, $line);
                next;
        }
        if ($line !~ /^([^:]+):([^:]+):([0-9]+)\n/) {
                push(@pointer_new, $line);
                next;
        }
        $group       = $1;
        $destination = $2;
        $old_num     = $3;
        $num_end = &readgroup($nntp, $group, $destination, $old_num);
        push(@pointer_new, "$group:$destination:$num_end\n");
}

$nntp->quit;
open(OUT, "> $news_pointer_fname") || die $!;
print OUT @pointer_new;
close(OUT);

<Prev in Thread] Current Thread [Next in Thread>