1N/A#!/usr/bin/perl5
1N/A
1N/A### Subject: Re: Fuller example of Net::NNTP?
1N/A### Date: Tue, 4 Feb 1997 10:37:58 -0800
1N/A### From: "Paul E. Hoffman" <phoffman@imc.org>
1N/A### To: Graham Barr <gbarr@ti.com>
1N/A###
1N/A### Thanks for your reply. After looking at the examples, I realized that
1N/A### you're not doing what I want, which is to store the messages on the local
1N/A### hard disk with the same message number as what was on the remote. So, I
1N/A### rolled my own program, although I haven't finished it yet (I have a hook
1N/A### for expiring, but haven't done it yet).
1N/A###
1N/A### You are welcome to use this in the Net:: distribution if you think it is
1N/A### useful.
1N/A###
1N/A### NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE
1N/A###
1N/A### This script is included as-is, I give no guarantee that it will
1N/A### work on every system
1N/A###
1N/A
1N/Ause Net::NNTP;
1N/A
1N/A$BaseDir = '/usr/usenet';
1N/Achdir($BaseDir) or die "Could not cd to $BaseDir\n";
1N/A
1N/A# Format of grouplist is:
1N/A# groupname<tab>expirationdays
1N/A# expirationdays is the number of days to leave the articles around;
1N/A# set it to 0 if you want the articles to stay forever
1N/A# If the groupname starts with a #, it is skipped
1N/Aopen(GROUPLIST, 'grouplist.txt') or die "Could not open grouplist.txt\n";
1N/Awhile(<GROUPLIST>) {
1N/A $Line = $_; chomp($Line);
1N/A if($Line eq '') { next }; # Skip blank lines
1N/A if(substr($Line, 0, 1) eq '#') { next }; # Skip comments
1N/A push(@Groups, $Line)
1N/A}
1N/A
1N/A$NntpPtr = Net::NNTP->new('news.server.com');
1N/A
1N/Aforeach $GroupLine (@Groups) {
1N/A ($GroupName, $GroupExp) = split(/\s/, $GroupLine, 2);
1N/A # Process the expiration first (still to be done...)
1N/A
1N/A # See if this is a new group
1N/A unless(-e "$BaseDir/$GroupName") {
1N/A unless(mkdir("$BaseDir/$GroupName", 0755))
1N/A { die "Could not make $BaseDir/$GroupName\n" }
1N/A }
1N/A chdir("$BaseDir/$GroupName") or die "Couldn't chdir to $GroupName\n";
1N/A # Find the last article in the directory
1N/A @AllInDir = <*>; @RevSortedAllInDir = reverse(sort(@AllInDir));
1N/A $LenArr = @RevSortedAllInDir;
1N/A if($LenArr > 0) { $NumLastInDir = $RevSortedAllInDir[0] }
1N/A else { $NumLastInDir = 0 }
1N/A ($NumArt, $NumFirst, $NumLast, $XGroupName) =
1N/A$NntpPtr->group($GroupName);
1N/A
1N/A if($NumLast == $NumLastInDir) { next } # No new articles
1N/A if($NumLast < $NumLastInDir)
1N/A { die "In $GroupName, the last number was $NumLast, but the " .
1N/A " last number in the directory was $NumLastInDir\n" }
1N/A # Figure out which article to start from
1N/A if($NumLastInDir == 0) { $GetArtNum = $NumFirst }
1N/A else { $GetArtNum = $NumLastInDir + 1 }
1N/A
1N/A # Now read each of the new articles
1N/A while(1) { # Loop until "last" is called
1N/A $ArtRef = $NntpPtr->article($GetArtNum);
1N/A @ArtArr = @$ArtRef; $ArtArrLen = @ArtArr;
1N/A if($ArtArrLen > 0 ) { # Skip article numbers that had 0 len
1N/A open(OUT, ">$GetArtNum") or
1N/A die "Could not create $GroupName/$GetArtNum\n";
1N/A print OUT @$ArtRef; close(OUT);
1N/A }
1N/A
1N/A # Check if we're at the end
1N/A if($GetArtNum == $NumLast) { last }
1N/A $GetArtNum += 1; # Increment the article number to get
1N/A }
1N/A}
1N/A
1N/A$NntpPtr->quit;
1N/Aexit;