Article 3610 of comp.lang.perl:
Xref: feenix.metronet.com comp.lang.perl:3610
Newsgroups: comp.lang.perl
Path: feenix.metronet.com!news.ecn.bgu.edu!anaxagoras.ils.nwu.edu!news.acns.nwu.edu!math.ohio-state.edu!howland.reston.ans.net!noc.near.net!lynx!tmetro
From: tmetro@lynx.dac.northeastern.edu (Tom Metro)
Subject: Results: Perl NNTP client
Message-ID: <1993Jun22.024350.7275@lynx.dac.northeastern.edu>
Reply-To: tmetro@vl.ci.net
Organization: Venture Logic, Newton, MA, USA
Date: Tue, 22 Jun 1993 02:43:50 GMT
Lines: 168

Following up as promised on my original message:
 
> Are there any perl NNTP clients (i.e. news readers) floating around?
 
I received the following replies:
 
From: Jerry LeVan <levan@eagle.eku.edu>
> I am using a slightly hacked version of pgnews to grab stuff from
> a nearby NNTP server to which I have access. I then use ELM to step
> through the resulting directories and read/reply to the messages.
> [...]
> #** SOURCE NAME | pgnews, (Perl Get News)
> #**             | 
> #**    SYNOPSIS | pgnews [-h hostname]
> #**             | 
> #** DESCRIPTION | pgnews goes to a specified NNTP server
> #**             | and retrieves news articles by newsgroup
> #**             | and saves them to a specified file in
> #**             | mailbox format.
> #**             | Please see the NOTES section.
> [...]
 
Uses its own .pgnews file to store newsgroup info.
Good choice if you want news dumped into mailbox files.
The NNTP access is direct through sockets as opposed to using one of 
the perl libraries.
 
From: cameron@cs.unsw.oz.au
> I plan on building something of the sort on the code appended below.
> If you get nothing better this may get you off the ground.
 
Here are some "highlights" from the NNTP portion of the code he sent 
me:
> package nntp;
> 
> # This package is written from the point of view that the caller supplies:
> #     $'FROM, $NNTP'TO        NNTP connection.
> # and uses local() to control the context.
> 
> # connect to server, return (FROM,TO,canpost) or undef
> # sets $nntp'FROM, $nntp'TO.
> sub connect   # (nntpserver) -> undef=failure or canpost (0=no-posting, 1=posting-ok)
>       { local($NNTPSERVER)=@_;
> [...]
> sub disconnect
> [...]
> # collect reply from  server, skipping info replies
> sub reply     # void -> (code,text) or undef on EOF
> [...]
> # collect a text response from the  server
> sub text      # (void) -> @lines
> [...]
> # post a complete article contained in a file
> sub post      # articlefile -> ok
> [...]
> # select news group
> sub group     # group -> ($low,$high) or undef
> [...]
 
He also included a few supporting packages:
open.pl
pathname.pl
rfc822.pl
tcp.pl
 
These have little to no documentation, but the NNTP stuff looks like 
it could be useful.
 
From: Matthew Hannigan <matth@extro.ucc.su.OZ.AU>
> ...a small perl program for checking for new arrivals in a 
> newsgroup.  It might be the start of a fuller client...
> Here it is ..  it's from Ian.Collier@prg.ox.ac.uk
 
It was a short script using 'chat2.pl' to grab articles from a 
specific newsgroup. OK example of the basics, but not generalized.
 
From: Chris Sherman <sherman@unx.sas.com>
> There is a really, really, good one that comes with wafe.  It is 
> X-based, and seems to work just fine.
> 
> ftp.wu-wien.ac.at:pub/src/X11/wafe/wafe-0.94.tar.Z, though there is
> probably a newer version.
> 
> ...wafe comes with the following file, nntp.pl, which seemed to 
> have all the juicy bits...
 
aadt!mikee@uunet.UU.NET (Mike Eggleston) also suggested WAFE.
 
This appears to be the best documented of the bunch. It covers 
.newsrc I/O which none of the others address. I didn't see 
anything for posting articles, but that's probably handled with 
files and inews (or the equivalent).
 
Here are some of the interesting function headers:
 
> # File: nntp.pl - utility functions to talk to an NNTP server
> # This file is part of Randall's NNTP grep-n'-fetch-it utilites.
> [...]
> #
> # extended, made more robust, substantial speedup:
> # Gustaf Neumann
> #
> # NOTE: the modified version is NOT backward compatible with
> # the original one!!!
> [...]
> # $hndl = &nntp'connect($server);
> #
> #   attempt a connection to the nntp server.
> [...]
> #***********************************************************************
> # $perl_pattern = &nntp'grouppat($generic_pattern)
> #
> #   try to be smart about whether the user is smart.  changes input
> #   patterns of the form 'comp.all' to 'comp\..*'
> #***********************************************************************
> [...]
> #***********************************************************************
> # &nntp'getgroups
> #
> #   @groups is the list of groups known by the nntp server.
> #   %groups is an associative array of the max articles numbers
> #   used for quick lookup.  These variables are private to the
> #   nntp package.
> #***********************************************************************
> [...]
> #***********************************************************************
> # @matching_groups = &nntp'list($conn, $group_pattern)
> #
> #   return a list of the groups which match the group pattern.
> #***********************************************************************
> [...]
> # return the article contents in a (potentially large) string.
> #
> # $msg = &msgtext($conn, $num-or-id, "article" | "body" | "head")
> #
> [...]
> # return the list of already-read articles in the user's newsrc file for
> # the specified news group.
> sub newsrc_get
> [...]
> # replace or create a newsrc entry
> sub newsrc_put
> [...]
> # tests whether an article is included in a given rangelist
> sub inRangelist
> [...]
 
From: clay@cool.vortech.com (Clay Luther)
> I have a perl-nntp program that you could modify, if you'd like.  It 
> gates news onto a mailing list.
 
Not appropriate for me, but it might be of interest to someone else.
 
 
If anyone is interested in the full text of any code mentioned 
above, let me know and I'll mail you a copy. The best choice, 
nntp.pl that comes with WAFE seems to be readily available from ftp 
sites. pgnews is probably also available from ftp. If anyone wants, 
and the authors don't object, I will place the other code examples
on an ftp site.
 
Thanks to everyone who sent suggestions and code!
 -Tom
 
-- 
Tom Metro                                         tmetro@lynx.neu.edu
Venture Logic                                     tmetro@vl.ci.net
Newton, MA, USA


