diff options
author | Nicholas Clark <nick@ccl4.org> | 2009-10-02 11:34:29 +0100 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2009-10-02 11:34:29 +0100 |
commit | 55c474ba7687e845183c20351357b0cf4f16fdef (patch) | |
tree | e5c7275dde88675ec850f489f96fb3d7d4aa1976 /cpan/libnet/demos/nntp.mirror | |
parent | 90964b6e3255899e4d0c1570d3fbede4b450fa6d (diff) | |
download | perl-55c474ba7687e845183c20351357b0cf4f16fdef.tar.gz |
Move libnet from ext/ to cpan/
Diffstat (limited to 'cpan/libnet/demos/nntp.mirror')
-rw-r--r-- | cpan/libnet/demos/nntp.mirror | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/cpan/libnet/demos/nntp.mirror b/cpan/libnet/demos/nntp.mirror new file mode 100644 index 0000000000..8a43c3262a --- /dev/null +++ b/cpan/libnet/demos/nntp.mirror @@ -0,0 +1,86 @@ +#!/usr/bin/perl5 + +### Subject: Re: Fuller example of Net::NNTP? +### Date: Tue, 4 Feb 1997 10:37:58 -0800 +### From: "Paul E. Hoffman" <phoffman@imc.org> +### To: Graham Barr <gbarr@ti.com> +### +### Thanks for your reply. After looking at the examples, I realized that +### you're not doing what I want, which is to store the messages on the local +### hard disk with the same message number as what was on the remote. So, I +### rolled my own program, although I haven't finished it yet (I have a hook +### for expiring, but haven't done it yet). +### +### You are welcome to use this in the Net:: distribution if you think it is +### useful. +### +### NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE NOTE +### +### This script is included as-is, I give no guarantee that it will +### work on every system +### + +use Net::NNTP; + +$BaseDir = '/usr/usenet'; +chdir($BaseDir) or die "Could not cd to $BaseDir\n"; + +# Format of grouplist is: +# groupname<tab>expirationdays +# expirationdays is the number of days to leave the articles around; +# set it to 0 if you want the articles to stay forever +# If the groupname starts with a #, it is skipped +open(GROUPLIST, 'grouplist.txt') or die "Could not open grouplist.txt\n"; +while(<GROUPLIST>) { + $Line = $_; chomp($Line); + if($Line eq '') { next }; # Skip blank lines + if(substr($Line, 0, 1) eq '#') { next }; # Skip comments + push(@Groups, $Line) +} + +$NntpPtr = Net::NNTP->new('news.server.com'); + +foreach $GroupLine (@Groups) { + ($GroupName, $GroupExp) = split(/\s/, $GroupLine, 2); + # Process the expiration first (still to be done...) + + # See if this is a new group + unless(-e "$BaseDir/$GroupName") { + unless(mkdir("$BaseDir/$GroupName", 0755)) + { die "Could not make $BaseDir/$GroupName\n" } + } + chdir("$BaseDir/$GroupName") or die "Couldn't chdir to $GroupName\n"; + # Find the last article in the directory + @AllInDir = <*>; @RevSortedAllInDir = reverse(sort(@AllInDir)); + $LenArr = @RevSortedAllInDir; + if($LenArr > 0) { $NumLastInDir = $RevSortedAllInDir[0] } + else { $NumLastInDir = 0 } + ($NumArt, $NumFirst, $NumLast, $XGroupName) = +$NntpPtr->group($GroupName); + + if($NumLast == $NumLastInDir) { next } # No new articles + if($NumLast < $NumLastInDir) + { die "In $GroupName, the last number was $NumLast, but the " . + " last number in the directory was $NumLastInDir\n" } + # Figure out which article to start from + if($NumLastInDir == 0) { $GetArtNum = $NumFirst } + else { $GetArtNum = $NumLastInDir + 1 } + + # Now read each of the new articles + while(1) { # Loop until "last" is called + $ArtRef = $NntpPtr->article($GetArtNum); + @ArtArr = @$ArtRef; $ArtArrLen = @ArtArr; + if($ArtArrLen > 0 ) { # Skip article numbers that had 0 len + open(OUT, ">$GetArtNum") or + die "Could not create $GroupName/$GetArtNum\n"; + print OUT @$ArtRef; close(OUT); + } + + # Check if we're at the end + if($GetArtNum == $NumLast) { last } + $GetArtNum += 1; # Increment the article number to get + } +} + +$NntpPtr->quit; +exit; |