home *** CD-ROM | disk | FTP | other *** search
/ CLIX - Fazer Clix Custa Nix / CLIX-CD.cdr / mac / lib / Net / NNTP.pm < prev    next >
Text File  |  1997-11-18  |  23KB  |  1,023 lines

  1. # Net::NNTP.pm
  2. #
  3. # Copyright (c) 1995-1997 Graham Barr <gbarr@ti.com>. All rights reserved.
  4. # This program is free software; you can redistribute it and/or
  5. # modify it under the same terms as Perl itself.
  6.  
  7. package Net::NNTP;
  8.  
  9. use strict;
  10. use vars qw(@ISA $VERSION $debug);
  11. use IO::Socket;
  12. use Net::Cmd;
  13. use Carp;
  14. use Time::Local;
  15. use Net::Config;
  16.  
  17. $VERSION = do { my @r=(q$Revision: 1.1 $=~/\d+/g); sprintf "%d."."%02d"x$#r,@r};
  18. @ISA     = qw(Net::Cmd IO::Socket::INET);
  19.  
  20. sub new
  21. {
  22.  my $self = shift;
  23.  my $type = ref($self) || $self;
  24.  my $host = shift if @_ % 2;
  25.  my %arg  = @_;
  26.  my $obj;
  27.  
  28.  $host ||= $ENV{NNTPSERVER} || $ENV{NEWSHOST};
  29.  
  30.  my $hosts = defined $host ? [ $host ] : $NetConfig{nntp_hosts};
  31.  
  32.  @{$hosts} = qw(news)
  33.     unless @{$hosts};
  34.  
  35.  my $h;
  36.  foreach $h (@{$hosts})
  37.   {
  38.    $obj = $type->SUPER::new(PeerAddr => ($host = $h), 
  39.                 PeerPort => $arg{Port} || 'nntp(119)',
  40.                 Proto    => 'tcp',
  41.                 Timeout  => defined $arg{Timeout}
  42.                         ? $arg{Timeout}
  43.                         : 120
  44.                ) and last;
  45.   }
  46.  
  47.  return undef
  48.     unless defined $obj;
  49.  
  50.  ${*$obj}{'net_nntp_host'} = $host;
  51.  
  52.  $obj->autoflush(1);
  53.  $obj->debug(exists $arg{Debug} ? $arg{Debug} : undef);
  54.  
  55.  unless ($obj->response() == CMD_OK)
  56.   {
  57.    $obj->close;
  58.    return undef;
  59.   }
  60.  
  61.  my $c = $obj->code;
  62.  ${*$obj}{'net_nntp_post'} = $c >= 200 && $c <= 209 ? 1 : 0;
  63.  
  64.  $obj;
  65. }
  66.  
  67. sub debug_text
  68. {
  69.  my $nntp = shift;
  70.  my $inout = shift;
  71.  my $text = shift;
  72.  
  73.  if(($nntp->code == 350 && $text =~ /^(\S+)/)
  74.     || ($text =~ /^(authinfo\s+pass)/io)) 
  75.   {
  76.    $text = "$1 ....\n"
  77.   }
  78.  
  79.  $text;
  80. }
  81.  
  82. sub postok
  83. {
  84.  @_ == 1 or croak 'usage: $nntp->postok()';
  85.  my $nntp = shift;
  86.  ${*$nntp}{'net_nntp_post'} || 0;
  87. }
  88.  
  89. sub article
  90. {
  91.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->article( MSGID )';
  92.  my $nntp = shift;
  93.  
  94.  $nntp->_ARTICLE(@_)
  95.     ? $nntp->read_until_dot()
  96.     : undef;
  97. }
  98.  
  99. sub authinfo
  100. {
  101.  @_ == 3 or croak 'usage: $nntp->authinfo( USER, PASS )';
  102.  my($nntp,$user,$pass) = @_;
  103.  
  104.  $nntp->_AUTHINFO("USER",$user) == CMD_MORE 
  105.     && $nntp->_AUTHINFO("PASS",$pass) == CMD_OK;
  106. }
  107.  
  108. sub authinfo_simple
  109. {
  110.  @_ == 3 or croak 'usage: $nntp->authinfo( USER, PASS )';
  111.  my($nntp,$user,$pass) = @_;
  112.  
  113.  $nntp->_AUTHINFO('SIMPLE') == CMD_MORE 
  114.     && $nntp->command($user,$pass)->response == CMD_OK;
  115. }
  116.  
  117. sub body
  118. {
  119.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->body( [ MSGID ] )';
  120.  my $nntp = shift;
  121.  
  122.  $nntp->_BODY(@_)
  123.     ? $nntp->read_until_dot()
  124.     : undef;
  125. }
  126.  
  127. sub head
  128. {
  129.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->head( [ MSGID ] )';
  130.  my $nntp = shift;
  131.  
  132.  $nntp->_HEAD(@_)
  133.     ? $nntp->read_until_dot()
  134.     : undef;
  135. }
  136.  
  137. sub nntpstat
  138. {
  139.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->nntpstat( [ MSGID ] )';
  140.  my $nntp = shift;
  141.  
  142.  $nntp->_STAT(@_) && $nntp->message =~ /(<[^>]+>)/o
  143.     ? $1
  144.     : undef;
  145. }
  146.  
  147.  
  148. sub group
  149. {
  150.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->group( [ GROUP ] )';
  151.  my $nntp = shift;
  152.  my $grp = ${*$nntp}{'net_nntp_group'} || undef;
  153.  
  154.  return $grp
  155.     unless(@_ || wantarray);
  156.  
  157.  my $newgrp = shift;
  158.  
  159.  return wantarray ? () : undef
  160.     unless $nntp->_GROUP($newgrp || $grp || "")
  161.         && $nntp->message =~ /(\d+)\s+(\d+)\s+(\d+)\s+(\S+)/;
  162.  
  163.  my($count,$first,$last,$group) = ($1,$2,$3,$4);
  164.  
  165.  # group may be replied as '(current group)'
  166.  $group = ${*$nntp}{'net_nntp_group'}
  167.     if $group =~ /\(/;
  168.  
  169.  ${*$nntp}{'net_nntp_group'} = $group;
  170.  
  171.  wantarray
  172.     ? ($count,$first,$last,$group)
  173.     : $group;
  174. }
  175.  
  176. sub help
  177. {
  178.  @_ == 1 or croak 'usage: $nntp->help()';
  179.  my $nntp = shift;
  180.  
  181.  $nntp->_HELP
  182.     ? $nntp->read_until_dot
  183.     : undef;
  184. }
  185.  
  186. sub ihave
  187. {
  188.  @_ >= 2 or croak 'usage: $nntp->ihave( MESSAGE-ID [, MESSAGE ])';
  189.  my $nntp = shift;
  190.  my $mid = shift;
  191.  
  192.  $nntp->_IHAVE($mid) && $nntp->datasend(@_)
  193.     ? @_ == 0 || $nntp->dataend
  194.     : undef;
  195. }
  196.  
  197. sub last
  198. {
  199.  @_ == 1 or croak 'usage: $nntp->last()';
  200.  my $nntp = shift;
  201.  
  202.  $nntp->_LAST && $nntp->message =~ /(<[^>]+>)/o
  203.     ? $1
  204.     : undef;
  205. }
  206.  
  207. sub list
  208. {
  209.  @_ == 1 or croak 'usage: $nntp->list()';
  210.  my $nntp = shift;
  211.  
  212.  $nntp->_LIST
  213.     ? $nntp->_grouplist
  214.     : undef;
  215. }
  216.  
  217. sub newgroups
  218. {
  219.  @_ >= 2 or croak 'usage: $nntp->newgroups( SINCE [, DISTRIBUTIONS ])';
  220.  my $nntp = shift;
  221.  my $time = _timestr(shift);
  222.  my $dist = shift || "";
  223.  
  224.  $dist = join(",", @{$dist})
  225.     if ref($dist);
  226.  
  227.  $nntp->_NEWGROUPS($time,$dist)
  228.     ? $nntp->_grouplist
  229.     : undef;
  230. }
  231.  
  232. sub newnews
  233. {
  234.  @_ >= 2 && @_ <= 4 or
  235.     croak 'usage: $nntp->newnews( SINCE [, GROUPS [, DISTRIBUTIONS ]])';
  236.  my $nntp = shift;
  237.  my $time = _timestr(shift);
  238.  my $grp  = @_ ? shift : $nntp->group;
  239.  my $dist = shift || "";
  240.  
  241.  $grp ||= "*";
  242.  $grp = join(",", @{$grp})
  243.     if ref($grp);
  244.  
  245.  $dist = join(",", @{$dist})
  246.     if ref($dist);
  247.  
  248.  $nntp->_NEWNEWS($grp,$time,$dist)
  249.     ? $nntp->_articlelist
  250.     : undef;
  251. }
  252.  
  253. sub next
  254. {
  255.  @_ == 1 or croak 'usage: $nntp->next()';
  256.  my $nntp = shift;
  257.  
  258.  $nntp->_NEXT && $nntp->message =~ /(<[^>]+>)/o
  259.     ? $1
  260.     : undef;
  261. }
  262.  
  263. sub post
  264. {
  265.  @_ >= 1 or croak 'usage: $nntp->post( [ MESSAGE ] )';
  266.  my $nntp = shift;
  267.  
  268.  $nntp->_POST() && $nntp->datasend(@_)
  269.     ? @_ == 0 || $nntp->dataend
  270.     : undef;
  271. }
  272.  
  273. sub quit
  274. {
  275.  @_ == 1 or croak 'usage: $nntp->quit()';
  276.  my $nntp = shift;
  277.  
  278.  $nntp->_QUIT
  279.     && $nntp->close;
  280. }
  281.  
  282. sub slave
  283. {
  284.  @_ == 1 or croak 'usage: $nntp->slave()';
  285.  my $nntp = shift;
  286.  
  287.  $nntp->_SLAVE;
  288. }
  289.  
  290. ##
  291. ## The following methods are not implemented by all servers
  292. ##
  293.  
  294. sub active
  295. {
  296.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->active( [ PATTERN ] )';
  297.  my $nntp = shift;
  298.  
  299.  $nntp->_LIST('ACTIVE',@_)
  300.     ? $nntp->_grouplist
  301.     : undef;
  302. }
  303.  
  304. sub active_times
  305. {
  306.  @_ == 1 or croak 'usage: $nntp->active_times()';
  307.  my $nntp = shift;
  308.  
  309.  $nntp->_LIST('ACTIVE.TIMES')
  310.     ? $nntp->_grouplist
  311.     : undef;
  312. }
  313.  
  314. sub distributions
  315. {
  316.  @_ == 1 or croak 'usage: $nntp->distributions()';
  317.  my $nntp = shift;
  318.  
  319.  $nntp->_LIST('DISTRIBUTIONS')
  320.     ? $nntp->_description
  321.     : undef;
  322. }
  323.  
  324. sub distribution_patterns
  325. {
  326.  @_ == 1 or croak 'usage: $nntp->distributions()';
  327.  my $nntp = shift;
  328.  
  329.  my $arr;
  330.  local $_;
  331.  
  332.  $nntp->_LIST('DISTRIB.PATS') && ($arr = $nntp->read_until_dot)
  333.     ? [grep { /^\d/ && (chomp, $_ = [ split /:/ ]) } @$arr]
  334.     : undef;
  335. }
  336.  
  337. sub newsgroups
  338. {
  339.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->newsgroups( [ PATTERN ] )';
  340.  my $nntp = shift;
  341.  
  342.  $nntp->_LIST('NEWSGROUPS',@_)
  343.     ? $nntp->_description
  344.     : undef;
  345. }
  346.  
  347. sub overview_fmt
  348. {
  349.  @_ == 1 or croak 'usage: $nntp->overview_fmt()';
  350.  my $nntp = shift;
  351.  
  352.  $nntp->_LIST('OVERVIEW.FMT')
  353.      ? $nntp->_articlelist
  354.      : undef;
  355. }
  356.  
  357. sub subscriptions
  358. {
  359.  @_ == 1 or croak 'usage: $nntp->subscriptions()';
  360.  my $nntp = shift;
  361.  
  362.  $nntp->_LIST('SUBSCRIPTIONS')
  363.     ? $nntp->_articlelist
  364.     : undef;
  365. }
  366.  
  367. sub listgroup
  368. {
  369.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->listgroup( [ GROUP ] )';
  370.  my $nntp = shift;
  371.  
  372.  $nntp->_LISTGROUP(@_)
  373.     ? $nntp->_articlelist
  374.     : undef;
  375. }
  376.  
  377. sub reader
  378. {
  379.  @_ == 1 or croak 'usage: $nntp->reader()';
  380.  my $nntp = shift;
  381.  
  382.  $nntp->_MODE('READER');
  383. }
  384.  
  385. sub xgtitle
  386. {
  387.  @_ == 1 || @_ == 2 or croak 'usage: $nntp->xgtitle( [ PATTERN ] )';
  388.  my $nntp = shift;
  389.  
  390.  $nntp->_XGTITLE(@_)
  391.     ? $nntp->_description
  392.     : undef;
  393. }
  394.  
  395. sub xhdr
  396. {
  397.  @_ >= 2 && @_ <= 4 or croak 'usage: $nntp->xhdr( HEADER, [ MESSAGE-SPEC ] )';
  398.  my $nntp = shift;
  399.  my $hdr = shift;
  400.  my $arg = _msg_arg(@_);
  401.  
  402.  $nntp->_XHDR($hdr, $arg)
  403.     ? $nntp->_description
  404.     : undef;
  405. }
  406.  
  407. sub xover
  408. {
  409.  @_ == 2 || @_ == 3 or croak 'usage: $nntp->xover( MESSAGE-SPEC )';
  410.  my $nntp = shift;
  411.  my $arg = _msg_arg(@_);
  412.  
  413.  $nntp->_XOVER($arg)
  414.     ? $nntp->_fieldlist
  415.     : undef;
  416. }
  417.  
  418. sub xpat
  419. {
  420.  @_ == 4 || @_ == 5 or croak '$nntp->xpat( HEADER, PATTERN, MESSAGE-SPEC )';
  421.  my $nntp = shift;
  422.  my $hdr = shift;
  423.  my $pat = shift;
  424.  my $arg = _msg_arg(@_);
  425.  
  426.  $pat = join(" ", @$pat)
  427.     if ref($pat);
  428.  
  429.  $nntp->_XPAT($hdr,$arg,$pat)
  430.     ? $nntp->_description
  431.     : undef;
  432. }
  433.  
  434. sub xpath
  435. {
  436.  @_ == 2 or croak 'usage: $nntp->xpath( MESSAGE-ID )';
  437.  my($nntp,$mid) = @_;
  438.  
  439.  return undef
  440.     unless $nntp->_XPATH($mid);
  441.  
  442.  my $m; ($m = $nntp->message) =~ s/^\d+\s+//o;
  443.  my @p = split /\s+/, $m;
  444.  
  445.  wantarray ? @p : $p[0];
  446. }
  447.  
  448. sub xrover
  449. {
  450.  @_ == 2 || @_ == 3 or croak 'usage: $nntp->xrover( MESSAGE-SPEC )';
  451.  my $nntp = shift;
  452.  my $arg = _msg_arg(@_);
  453.  
  454.  $nntp->_XROVER($arg)
  455.     ? $nntp->_description
  456.     : undef;
  457. }
  458.  
  459. sub date
  460. {
  461.  @_ == 1 or croak 'usage: $nntp->date()';
  462.  my $nntp = shift;
  463.  
  464.  $nntp->_DATE && $nntp->message =~ /(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/
  465.     ? timegm($6,$5,$4,$3,$2-1,$1 - 1900)
  466.     : undef;
  467. }
  468.  
  469.  
  470. ##
  471. ## Private subroutines
  472. ##
  473.  
  474. sub _msg_arg
  475. {
  476.  my $spec = shift;
  477.  my $arg = "";
  478.  
  479.  if(@_)
  480.   {
  481.    carp "Depriciated passing of two message numbers, "
  482.       . "pass a reference"
  483.     if $^W;
  484.    $spec = [ $spec, $_[0] ];
  485.   }
  486.  
  487.  if(defined $spec)
  488.   {
  489.    if(ref($spec))
  490.     {
  491.      $arg = $spec->[0] . "-";
  492.      $arg .= $spec->[1]
  493.     if defined $spec->[1] && $spec->[1] > $spec->[0];
  494.     }
  495.    else
  496.     {
  497.      $arg = $spec;
  498.     }
  499.   }
  500.  
  501.  $arg;
  502. }
  503.  
  504. sub _timestr
  505. {
  506.  my $time = shift;
  507.  my @g = reverse((gmtime($time))[0..5]);
  508.  $g[1] += 1;
  509.  $g[0] %= 100;
  510.  sprintf "%02d%02d%02d %02d%02d%02d GMT", @g;
  511. }
  512.  
  513. sub _grouplist
  514. {
  515.  my $nntp = shift;
  516.  my $arr = $nntp->read_until_dot or
  517.     return undef;
  518.  
  519.  my $hash = {};
  520.  my $ln;
  521.  
  522.  foreach $ln (@$arr)
  523.   {
  524.    my @a = split(/[\s\n]+/,$ln);
  525.    $hash->{$a[0]} = [ @a[1,2,3] ];
  526.   }
  527.  
  528.  $hash;
  529. }
  530.  
  531. sub _fieldlist
  532. {
  533.  my $nntp = shift;
  534.  my $arr = $nntp->read_until_dot or
  535.     return undef;
  536.  
  537.  my $hash = {};
  538.  my $ln;
  539.  
  540.  foreach $ln (@$arr)
  541.   {
  542.    my @a = split(/[\t\n]/,$ln);
  543.    my $m = shift @a;
  544.    $hash->{$m} = [ @a ];
  545.   }
  546.  
  547.  $hash;
  548. }
  549.  
  550. sub _articlelist
  551. {
  552.  my $nntp = shift;
  553.  my $arr = $nntp->read_until_dot;
  554.  
  555.  chomp(@$arr)
  556.     if $arr;
  557.  
  558.  $arr;
  559. }
  560.  
  561. sub _description
  562. {
  563.  my $nntp = shift;
  564.  my $arr = $nntp->read_until_dot or
  565.     return undef;
  566.  
  567.  my $hash = {};
  568.  my $ln;
  569.  
  570.  foreach $ln (@$arr)
  571.   {
  572.    chomp($ln);
  573.  
  574.    $hash->{$1} = $ln
  575.     if $ln =~ s/^\s*(\S+)\s*//o;
  576.   }
  577.  
  578.  $hash;
  579.  
  580. }
  581.  
  582. ##
  583. ## The commands
  584. ##
  585.  
  586. sub _ARTICLE   { shift->command('ARTICLE',@_)->response == CMD_OK }
  587. sub _AUTHINFO  { shift->command('AUTHINFO',@_)->response }
  588. sub _BODY      { shift->command('BODY',@_)->response == CMD_OK }
  589. sub _DATE      { shift->command('DATE')->response == CMD_INFO }
  590. sub _GROUP     { shift->command('GROUP',@_)->response == CMD_OK }
  591. sub _HEAD      { shift->command('HEAD',@_)->response == CMD_OK }
  592. sub _HELP      { shift->command('HELP',@_)->response == CMD_INFO }
  593. sub _IHAVE     { shift->command('IHAVE',@_)->response == CMD_MORE }
  594. sub _LAST      { shift->command('LAST')->response == CMD_OK }
  595. sub _LIST      { shift->command('LIST',@_)->response == CMD_OK }
  596. sub _LISTGROUP { shift->command('LISTGROUP',@_)->response == CMD_OK }
  597. sub _NEWGROUPS { shift->command('NEWGROUPS',@_)->response == CMD_OK }
  598. sub _NEWNEWS   { shift->command('NEWNEWS',@_)->response == CMD_OK }
  599. sub _NEXT      { shift->command('NEXT')->response == CMD_OK }
  600. sub _POST      { shift->command('POST',@_)->response == CMD_MORE }
  601. sub _QUIT      { shift->command('QUIT',@_)->response == CMD_OK }
  602. sub _SLAVE     { shift->command('SLAVE',@_)->response == CMD_OK }
  603. sub _STAT      { shift->command('STAT',@_)->response == CMD_OK }
  604. sub _MODE      { shift->command('MODE',@_)->response == CMD_OK }
  605. sub _XGTITLE   { shift->command('XGTITLE',@_)->response == CMD_OK }
  606. sub _XHDR      { shift->command('XHDR',@_)->response == CMD_OK }
  607. sub _XPAT      { shift->command('XPAT',@_)->response == CMD_OK }
  608. sub _XPATH     { shift->command('XPATH',@_)->response == CMD_OK }
  609. sub _XOVER     { shift->command('XOVER',@_)->response == CMD_OK }
  610. sub _XROVER    { shift->command('XROVER',@_)->response == CMD_OK }
  611. sub _XTHREAD   { shift->unsupported }
  612. sub _XSEARCH   { shift->unsupported }
  613. sub _XINDEX    { shift->unsupported }
  614.  
  615. ##
  616. ## IO/perl methods
  617. ##
  618.  
  619. sub close
  620. {
  621.  my $nntp = shift;
  622.  
  623.  ref($nntp) 
  624.     && defined fileno($nntp)
  625.     && $nntp->SUPER::close;
  626. }
  627.  
  628. sub DESTROY { shift->close }
  629.  
  630.  
  631. 1;
  632.  
  633. __END__
  634.  
  635. =head1 NAME
  636.  
  637. Net::NNTP - NNTP Client class
  638.  
  639. =head1 SYNOPSIS
  640.  
  641.     use Net::NNTP;
  642.     
  643.     $nntp = Net::NNTP->new("some.host.name");
  644.     $nntp->quit;
  645.  
  646. =head1 DESCRIPTION
  647.  
  648. C<Net::NNTP> is a class implementing a simple NNTP client in Perl as described
  649. in RFC977. C<Net::NNTP> inherits its communication methods from C<Net::Cmd>
  650.  
  651. =head1 CONSTRUCTOR
  652.  
  653. =over 4
  654.  
  655. =item new ( [ HOST ] [, OPTIONS ])
  656.  
  657. This is the constructor for a new Net::NNTP object. C<HOST> is the
  658. name of the remote host to which a NNTP connection is required. If not
  659. given two environment variables are checked, first C<NNTPSERVER> then
  660. C<NEWSHOST>, then C<Net::Config> is checked, and if a host is not found
  661. then C<news> is used.
  662.  
  663. C<OPTIONS> are passed in a hash like fashion, using key and value pairs.
  664. Possible options are:
  665.  
  666. B<Timeout> - Maximum time, in seconds, to wait for a response from the
  667. NNTP server, a value of zero will cause all IO operations to block.
  668. (default: 120)
  669.  
  670. B<Debug> - Enable the printing of debugging information to STDERR
  671.  
  672. =back
  673.  
  674. =head1 METHODS
  675.  
  676. Unless otherwise stated all methods return either a I<true> or I<false>
  677. value, with I<true> meaning that the operation was a success. When a method
  678. states that it returns a value, failure will be returned as I<undef> or an
  679. empty list.
  680.  
  681. =over 4
  682.  
  683. =item article ( [ MSGID|MSGNUM ] )
  684.  
  685. Retrieve the header, a blank line, then the body (text) of the
  686. specified article. 
  687.  
  688. If no arguments are passed then the current article in the current
  689. newsgroup is returned.
  690.  
  691. C<MSGNUM> is a numeric id of an article in the
  692. current newsgroup, and will change the current article pointer.
  693. C<MSGID> is the message id of an article as
  694. shown in that article's header.  It is anticipated that the client
  695. will obtain the C<MSGID> from a list provided by the C<newnews>
  696. command, from references contained within another article, or from
  697. the message-id provided in the response to some other commands.
  698.  
  699. Returns a reference to an array containing the article.
  700.  
  701. =item body ( [ MSGID|MSGNUM ] )
  702.  
  703. Retrieve the body (text) of the specified article. 
  704.  
  705. Takes the same arguments as C<article>
  706.  
  707. Returns a reference to an array containing the body of the article.
  708.  
  709. =item head ( [ MSGID|MSGNUM ] )
  710.  
  711. Retrieve the header of the specified article. 
  712.  
  713. Takes the same arguments as C<article>
  714.  
  715. Returns a reference to an array containing the header of the article.
  716.  
  717. =item nntpstat ( [ MSGID|MSGNUM ] )
  718.  
  719. The C<nntpstat> command is similar to the C<article> command except that no
  720. text is returned.  When selecting by message number within a group,
  721. the C<nntpstat> command serves to set the "current article pointer" without
  722. sending text.
  723.  
  724. Using the C<nntpstat> command to
  725. select by message-id is valid but of questionable value, since a
  726. selection by message-id does B<not> alter the "current article pointer".
  727.  
  728. Returns the message-id of the "current article".
  729.  
  730. =item group ( [ GROUP ] )
  731.  
  732. Set and/or get the current group. If C<GROUP> is not given then information
  733. is returned on the current group.
  734.  
  735. In a scalar context it returns the group name.
  736.  
  737. In an array context the return value is a list containing, the number
  738. of articles in the group, the number of the first article, the number
  739. of the last article and the group name.
  740.  
  741. =item ihave ( MSGID [, MESSAGE ])
  742.  
  743. The C<ihave> command informs the server that the client has an article
  744. whose id is C<MSGID>.  If the server desires a copy of that
  745. article, and C<MESSAGE> has been given the it will be sent.
  746.  
  747. Returns I<true> if the server desires the article and C<MESSAGE> was
  748. successfully sent,if specified.
  749.  
  750. If C<MESSAGE> is not specified then the message must be sent using the
  751. C<datasend> and C<dataend> methods from L<Net::Cmd>
  752.  
  753. C<MESSAGE> can be either an array of lines or a reference to an array.
  754.  
  755. =item last ()
  756.  
  757. Set the "current article pointer" to the previous article in the current
  758. newsgroup.
  759.  
  760. Returns the message-id of the article.
  761.  
  762. =item date ()
  763.  
  764. Returns the date on the remote server. This date will be in a UNIX time
  765. format (seconds since 1970)
  766.  
  767. =item postok ()
  768.  
  769. C<postok> will return I<true> if the servers initial response indicated
  770. that it will allow posting.
  771.  
  772. =item authinfo ( USER, PASS )
  773.  
  774. =item list ()
  775.  
  776. Obtain information about all the active newsgroups. The results is a reference
  777. to a hash where the key is a group name and each value is a reference to an
  778. array. The elements in this array are:- the first article number in the group,
  779. the last article number in the group and any information flags about the group.
  780.  
  781. =item newgroups ( SINCE [, DISTRIBUTIONS ])
  782.  
  783. C<SINCE> is a time value and C<DISTRIBUTIONS> is either a distribution
  784. pattern or a reference to a list of distribution patterns.
  785. The result is the same as C<list>, but the
  786. groups return will be limited to those created after C<SINCE> and, if
  787. specified, in one of the distribution areas in C<DISTRIBUTIONS>. 
  788.  
  789. =item newnews ( SINCE [, GROUPS [, DISTRIBUTIONS ]])
  790.  
  791. C<SINCE> is a time value. C<GROUPS> is either a group pattern or a reference
  792. to a list of group patterns. C<DISTRIBUTIONS> is either a distribution
  793. pattern or a reference to a list of distribution patterns.
  794.  
  795. Returns a reference to a list which contains the message-ids of all news posted
  796. after C<SINCE>, that are in a groups which matched C<GROUPS> and a
  797. distribution which matches C<DISTRIBUTIONS>.
  798.  
  799. =item next ()
  800.  
  801. Set the "current article pointer" to the next article in the current
  802. newsgroup.
  803.  
  804. Returns the message-id of the article.
  805.  
  806. =item post ( [ MESSAGE ] )
  807.  
  808. Post a new article to the news server. If C<MESSAGE> is specified and posting
  809. is allowed then the message will be sent.
  810.  
  811. If C<MESSAGE> is not specified then the message must be sent using the
  812. C<datasend> and C<dataend> methods from L<Net::Cmd>
  813.  
  814. C<MESSAGE> can be either an array of lines or a reference to an array.
  815.  
  816. =item slave ()
  817.  
  818. Tell the remote server that I am not a user client, but probably another
  819. news server.
  820.  
  821. =item quit ()
  822.  
  823. Quit the remote server and close the socket connection.
  824.  
  825. =back
  826.  
  827. =head2 Extension methods
  828.  
  829. These methods use commands that are not part of the RFC977 documentation. Some
  830. servers may not support all of them.
  831.  
  832. =over 4
  833.  
  834. =item newsgroups ( [ PATTERN ] )
  835.  
  836. Returns a reference to a hash where the keys are all the group names which
  837. match C<PATTERN>, or all of the groups if no pattern is specified, and
  838. each value contains the description text for the group.
  839.  
  840. =item distributions ()
  841.  
  842. Returns a reference to a hash where the keys are all the possible
  843. distribution names and the values are the distribution descriptions.
  844.  
  845. =item subscriptions ()
  846.  
  847. Returns a reference to a list which contains a list of groups which
  848. are recommended for a new user to subscribe to.
  849.  
  850. =item overview_fmt ()
  851.  
  852. Returns a reference to an array which contain the names of the fields returned
  853. by C<xover>.
  854.  
  855. =item active_times ()
  856.  
  857. Returns a reference to a hash where the keys are the group names and each
  858. value is a reference to an array containing the time the groups was created
  859. and an identifier, possibly an Email address, of the creator.
  860.  
  861. =item active ( [ PATTERN ] )
  862.  
  863. Similar to C<list> but only active groups that match the pattern are returned.
  864. C<PATTERN> can be a group pattern.
  865.  
  866. =item xgtitle ( PATTERN )
  867.  
  868. Returns a reference to a hash where the keys are all the group names which
  869. match C<PATTERN> and each value is the description text for the group.
  870.  
  871. =item xhdr ( HEADER, MESSAGE-SPEC )
  872.  
  873. Obtain the header field C<HEADER> for all the messages specified. 
  874.  
  875. The return value will be a reference
  876. to a hash where the keys are the message numbers and each value contains
  877. the text of the requested header for that message.
  878.  
  879. =item xover ( MESSAGE-SPEC )
  880.  
  881. The return value will be a reference
  882. to a hash where the keys are the message numbers and each value contains
  883. a reference to an array which contains the overview fields for that
  884. message.
  885.  
  886. The names of the fields can be obtained by calling C<overview_fmt>.
  887.  
  888. =item xpath ( MESSAGE-ID )
  889.  
  890. Returns the path name to the file on the server which contains the specified
  891. message.
  892.  
  893. =item xpat ( HEADER, PATTERN, MESSAGE-SPEC)
  894.  
  895. The result is the same as C<xhdr> except the is will be restricted to
  896. headers where the text of the header matches C<PATTERN>
  897.  
  898. =item xrover
  899.  
  900. The XROVER command returns reference information for the article(s)
  901. specified.
  902.  
  903. Returns a reference to a HASH where the keys are the message numbers and the
  904. values are the References: lines from the articles
  905.  
  906. =item listgroup
  907.  
  908. =item reader
  909.  
  910. =back
  911.  
  912. =head1 UNSUPPORTED
  913.  
  914. The following NNTP command are unsupported by the package, and there are
  915. no plans to do so.
  916.  
  917.     AUTHINFO GENERIC
  918.     XTHREAD
  919.     XSEARCH
  920.     XINDEX
  921.  
  922. =head1 DEFINITIONS
  923.  
  924. =over 4
  925.  
  926. =item MESSAGE-SPEC
  927.  
  928. C<MESSAGE-SPEC> is either a single message-id, a single message number, or
  929. a reference to a list of two message numbers.
  930.  
  931. If C<MESSAGE-SPEC> is a reference to a list of two message numbers and the
  932. second number in a range is less than or equal to the first then the range
  933. represents all messages in the group after the first message number.
  934.  
  935. B<NOTE> For compatibility reasons only with earlier versions of Net::NNTP
  936. a message spec can be passed as a list of two numbers, this is depreciated
  937. and a reference to the list should now be passed
  938.  
  939. =item PATTERN
  940.  
  941. The C<NNTP> protocol uses the C<WILDMAT> format for patterns.
  942. The WILDMAT format was first developed by Rich Salz based on
  943. the format used in the UNIX "find" command to articulate
  944. file names. It was developed to provide a uniform mechanism
  945. for matching patterns in the same manner that the UNIX shell
  946. matches filenames.
  947.  
  948. Patterns are implicitly anchored at the
  949. beginning and end of each string when testing for a match.
  950.  
  951. There are five pattern matching operations other than a strict
  952. one-to-one match between the pattern and the source to be
  953. checked for a match.
  954.  
  955. The first is an asterisk C<*> to match any sequence of zero or more
  956. characters.
  957.  
  958. The second is a question mark C<?> to match any single character. The
  959. third specifies a specific set of characters.
  960.  
  961. The set is specified as a list of characters, or as a range of characters
  962. where the beginning and end of the range are separated by a minus (or dash)
  963. character, or as any combination of lists and ranges. The dash can
  964. also be included in the set as a character it if is the beginning
  965. or end of the set. This set is enclosed in square brackets. The
  966. close square bracket C<]> may be used in a set if it is the first
  967. character in the set.
  968.  
  969. The fourth operation is the same as the
  970. logical not of the third operation and is specified the same
  971. way as the third with the addition of a caret character C<^> at
  972. the beginning of the test string just inside the open square
  973. bracket.
  974.  
  975. The final operation uses the backslash character to
  976. invalidate the special meaning of the a open square bracket C<[>,
  977. the asterisk, backslash or the question mark. Two backslashes in
  978. sequence will result in the evaluation of the backslash as a
  979. character with no special meaning.
  980.  
  981. =over 4
  982.  
  983. =item Examples
  984.  
  985. =item C<[^]-]>
  986.  
  987. matches any single character other than a close square
  988. bracket or a minus sign/dash.
  989.  
  990. =item C<*bdc>
  991.  
  992. matches any string that ends with the string "bdc"
  993. including the string "bdc" (without quotes).
  994.  
  995. =item C<[0-9a-zA-Z]>
  996.  
  997. matches any single printable alphanumeric ASCII character.
  998.  
  999. =item C<a??d>
  1000.  
  1001. matches any four character string which begins
  1002. with a and ends with d.
  1003.  
  1004. =back
  1005.  
  1006. =back
  1007.  
  1008. =head1 SEE ALSO
  1009.  
  1010. L<Net::Cmd>
  1011.  
  1012. =head1 AUTHOR
  1013.  
  1014. Graham Barr <gbarr@ti.com>
  1015.  
  1016. =head1 COPYRIGHT
  1017.  
  1018. Copyright (c) 1995-1997 Graham Barr. All rights reserved.
  1019. This program is free software; you can redistribute it and/or modify
  1020. it under the same terms as Perl itself.
  1021.  
  1022. =cut
  1023.