home *** CD-ROM | disk | FTP | other *** search
/ isnet Internet / Isnet Internet CD.iso / prog / hiz / 09 / 09.exe / adynware.exe / perl / lib / site / Net / NNTP.pm < prev    next >
Encoding:
Perl POD Document  |  1999-12-28  |  23.2 KB  |  1,005 lines

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