Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1060 lines
25 KiB

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