🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #71684

Re: simple Perl script needed

#71684
From: Szymon Sokół
Date: Tue, 24 May 2005 10:15
65 lines
3994 bytes
sebhoff2002@yahoo.com wrote:
> If I use a newsreader like MT-NewsWatcher, the XOVER headers are
> retrieved very quickly (thousands per minute). Your script on the other
> hand sends individual commands to retrieve headers one by one.
[----]
> I think the extension methods mentioned at
> http://search.cpan.org/~gbarr/libnet-1.19/Net/NNTP.pm would do the
> trick for me - xover (MESSAGE-SPEC) and overview_fmt () - but
> dereferencing the output is beyond me, I'm afraid. ;-)

I haven't thought of using xover, since not all servers handle NNTP
extensions (NEWNEWS, for example, is turned off on many server). 

Besides, I thought that you actually want ALL of the headers -  XOVER
returns only the headers that are put into the overview record, and overview
does not contain all headers, but only those listed in overview.fmt
(in the case of INN); typically those would be:
Subject: From: Date: Message-ID: References: Bytes: Lines: Xref:
but, for example, Path: or NNTP-Posting-Host: would not.

If you are sure that is OK for you, try this:

#!/usr/bin/perl -w
use Net::NNTP;
use strict;

# customize these lines according to your needs
my $output = "directory/";
my $nntpserver = "news.something.com";
my $user = "username";
my $pass = "password";
my @groups = ("news.software.nntp", "news.software.readers");

my $nntp = Net::NNTP->new($nntpserver);
$nntp->authinfo($user, $pass);
for my $group (@groups) {
  my $file;
  open $file, ">${output}/$group";
  my ($total, $first, $last) = $nntp->group($group);
  printf "Getting %d message headers from %s\n", $total, $group;
  my $xover = $nntp->xover([$first,$last]);
  my $fields = $nntp->overview_fmt();
  for my $msgid (keys %$xover) {
    my $hdrs = $xover->{$msgid};
    for my $fieldnum (0..$#$fields) {
      if($fields->[$fieldnum] =~ /:full$/o) {
        # some fields in overview include the field name...
        print $file $hdrs->[$fieldnum], "\n";
      } else {
        # ...but some do not
        print $file $fields->[$fieldnum], " ", $hdrs->[$fieldnum], "\n";
      }
    }
    print $file "\n"; # an empty line separates headers
  }
  close $file;
}


(yes, I have a terribly boring day at work ;-) )
-- 
Szymon Sokół (SS316-RIPE) -- Network Manager                                B
Computer Center, AGH - University of Science and Technology, Cracow, Poland O
http://home.agh.edu.pl/szymon/ PGP key id: RSA: 0x2ABE016B, DSS: 0xF9289982 F 
Free speech includes the right not to listen, if not interested -- Heinlein H
Technical Details
Message-ID: <d6uuse$q5g$1@galaxy.uci.agh.edu.pl>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.ams.giganews.com!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!newsfeed.pionier.net.pl!newsfeed.silweb.pl!agh.edu.pl!news.agh.edu.pl!not-for-mail
References: <1116840238.189967.41700@o13g2000cwo.googlegroups.com> <tskirvin.20050523173603$2bdd@cairo.ks.uiuc.edu> <1116917630.486426.100140@z14g2000cwz.googlegroups.com> <d6umac$o5g$1@galaxy.uci.agh.edu.pl> <1116926628.109152.169310@g43g2000cwa.googlegroups.com>

Show Full Headers
Complete Article Headers
Message-ID: <d6uuse$q5g$1@galaxy.uci.agh.edu.pl>
Subject: Re: simple Perl script needed
Date: Tue, 24 May 2005 10:15:42 +0000
From: Szymon Sokół <szymon@bastard.operator.from.hell.pl>
References: <1116840238.189967.41700@o13g2000cwo.googlegroups.com> <tskirvin.20050523173603$2bdd@cairo.ks.uiuc.edu> <1116917630.486426.100140@z14g2000cwz.googlegroups.com> <d6umac$o5g$1@galaxy.uci.agh.edu.pl> <1116926628.109152.169310@g43g2000cwa.googlegroups.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.20140818.mbox.gz!number1.nntp.ams.giganews.com!number1.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!newsfeed.pionier.net.pl!newsfeed.silweb.pl!agh.edu.pl!news.agh.edu.pl!not-for-mail
Newsgroups: news.software.nntp
Organization: University of Mining & Metallurgy
Lines: 65
Sender: Szymon Sokol <szymon@galaxy.uci.agh.edu.pl>
NNTP-Posting-Host: galaxy.uci.agh.edu.pl
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-2
Content-Transfer-Encoding: 8bit
X-Trace: galaxy.uci.agh.edu.pl 1116929742 26800 149.156.96.9 (24 May 2005
X-Complaints-To: usenet@uci.agh.edu.pl
NNTP-Posting-Date: Tue, 24 May 2005 10:15:42 +0000 (UTC)
User-Agent: tin/1.6.2-20030910 ("Pabbay") (UNIX) (SunOS/5.8 (sun4u))