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