# a 480 response from the news server; if your news server isn't paranoid
# then the script will never need to look at NNTPAUTH.
-# Copyright 2000 Simon Tatham. All rights reserved.
-# FIXME: put in a licence notice.
+# Copyright 2000,2004 Simon Tatham. All rights reserved.
require 5.002;
use Socket;
$ns=$ENV{'NNTPSERVER'};
if (!defined $ns or !length $ns) {
$ns = `cat /etc/nntpserver`;
+ chomp $ns;
}
$port = (getservbyname("nntp", "tcp"))[2];
$ns = inet_aton($ns);
sub docmd {
my ($cmd) = @_;
- while (1) {
+ # We go at most twice round the following loop. If the first attempt
+ # to fetch the article fails with a 480 response, we try again
+ # having authenticated first; but if the second attempt also fails
+ # with 480, then the authentication didn't work, so we should give
+ # up rather than try it pointlessly again.
+ for my $n (0,1) {
&putline($cmd);
$line = &getline;
if ($code eq "480") { &auth; } else { last; }