home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl_ste.zip / Net / NNTP.pm < prev    next >
Text File  |  1997-11-17  |  24KB  |  1,047 lines

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