From: M.T.Hamilton@loughborough.ac.uk ("[*] M.T.Hamilton")
Newsgroups: comp.infosystems.gopher
Subject: Improved(?) g2nntp
Date: 20 Dec 92 20:36:36 GMT
Distribution: comp
Original-To: gopher-news@boombox.micro.umn.edu
Mime-Version: 1.0
Content-Type: MULTIPART/MIXED; BOUNDARY="1461776719-1787128242-724888690:#29412"

--1461776719-1787128242-724888690:#29412
Content-Type: TEXT/PLAIN; charset=US-ASCII

Hello everybody!  

I just got hold of go4gw to try out an experiment, and seem to have
enhanced the Usenet module, g2nntp, without really meaning to.  I was
using it to read the news as a check that the software had installed
properly, and got to wondering how difficult it might be to add extra info
to the listing of articles in a newsfroup. 

I re-wrote the 'list_group' routine (attached) to interrogate the server
for not only the subject line of the article (as before), but also the
number of lines and the author's name.  It makes the gateway a lot more
useful IMHO, but has the drawback of requiring another 2 XHDR requests for
each article in the group.

Users see something like this: 

     2.  CAFFEINE AND SLEEP                     [  41] Wesley HRJ Gaus     
     3.  Re: Dying in dreams                    [  26] Darren Gower        
     4.  Re: caffeine myths                     [   9] Steve Dyer          
     5.  DREAM'92 UPDATE -- EXTENSION.  PARTICI [  30] Allen Chen          

Anybody who finds this code useful is more than welcome to use it.  And
I'm a Perl novice, so there's undoubtedly much scope for improvement!! 
Like caching, perhaps? 

Martin
--
M.T.Hamilton@lut.ac.uk | cp141@freenet.cleveland.edu | mhamilto@nyx.cs.du.edu
Dept of Computer Studies, Loughborough University of Technology, LE11 3TU, UK
+44.(0)509.224151       "Merry Christmas you giant beetle, you!" - m lippert.

--1461776719-1787128242-724888690:#29412
Content-Type: APPLICATION/octet-stream; name=zzz
Content-ID: <Pine.3.05.9212202109.O29412@genie.lut.ac.uk>
Content-Description: Perl hacks for g2nntp

sub list_group {
  local($group,$type,$range) = @_;

  &Gsend("GROUP $group");
  $_ = &Grecv;
  &Gabort($_) if !/^211/;

  ($n,$f,$l) = /211\s+(\d+)\s+(\d+)\s+(\d+)/;

  if ($range =~ /^(\S+):(\S+)$/) {
      $low = $1; $high = $2;
      $low =~ s/first/\$f/g;
      $low =~ s/last/\$l/g;
      $high =~ s/first/\$f/g;
      $high =~ s/last/\$l/g;
      $low  = int(eval($low));
      $high = int(eval($high));
      if ($low > $l) { $low = $l; }
      elsif ($low < $f) {$low = $f; }
      if ($high > $l) { $high = $l; }
      elsif ($high < $f) {$high = $f; }

      if ($high < $low)  {  $f = $high; $l = $low;  $nntp_reverse=1; }
      if ($low <= $high) {  $f = $low; $l = $high;  $nntp_reverse=0; }
        
  }
  elsif ($range ne '') {
       $range =~ s/first/\$f/g;
       $range =~ s/last/\$l/g;
       $range = int(eval($range));
       if ($range >0 && $range < $n) {  $f = $l - $range + 1; }
  }

  &Gsend("XHDR Subject $f-$l");
  $_ = &Grecv;
  &Gabort($_) if !/^221/;
 
  while(<GSERVER>) {
    chop; chop;
    last if /^\.$/;
    ($article,$subject) = /^(\d+)\s+(.*)/;
    $subject =~ s/\t/ /g; # just in case!
    push(@martin_subject, $subject);
    push(@marticle, $article);
  }

  &Gsend("XHDR Lines $f-$l");
  $_ = &Grecv;
  &Gabort($_) if !/^221/;

  $i=0;
  while(<GSERVER>) {
    chop; chop;
    last if /^\.$/;
    ($lines) = /^\d+\s+(.*)/;
    $lines =~ s/\t/ /g; # just in case!
    $lines =~ s/\((.*)\)/$1/;
    $martin_subject[$i] = 
      sprintf("%-38.38s [%4.4s]", $martin_subject[$i], $lines);
    $i++;
  }

  &Gsend("XHDR From $f-$l");
  $_ = &Grecv;
  &Gabort($_) if !/^221/;

  $i=0;
  while(<GSERVER>) {
    chop; chop;
    last if /^\.$/;
    ($from) = /^\d+\s+(.*)/;
    $from =~ s/\t/ /g; # just in case!
    $from =~ s/<.*>\s(.*)/$1/;
    $from =~ s/(.*)\s<.*>/$1/;
    $from =~ s/.*\((.*)\).*/$1/;

    $martin_subject[$i] = sprintf("%s %-20.20s", $martin_subject[$i], $from);

    if ($nntp_reverse) {
      push(@reply, "0$martin_subject[$i]\t$Ggw $atype $group $marticle[$i]\t$Ghost\t$Gport");
    } else {
      &Greply("0$martin_subject[$i]\t$Ggw $atype $group $marticle[$i]\t$Ghost\t$Gport");
    }

    $i++;
  }

  if ($nntp_reverse) {
    for ($i=$#reply; $i!= -1; $i--) { &Greply($reply[$i]); } 
  }

  &Greply(".");
  &close_nntp;
  exit;
}

--1461776719-1787128242-724888690:#29412--