summaryrefslogtreecommitdiff
path: root/img/lib/IM/Nntp.pm
diff options
context:
space:
mode:
Diffstat (limited to 'img/lib/IM/Nntp.pm')
-rw-r--r--img/lib/IM/Nntp.pm178
1 files changed, 102 insertions, 76 deletions
diff --git a/img/lib/IM/Nntp.pm b/img/lib/IM/Nntp.pm
index 49b50cd8..9751d9c5 100644
--- a/img/lib/IM/Nntp.pm
+++ b/img/lib/IM/Nntp.pm
@@ -5,10 +5,10 @@
###
### Author: Internet Message Group <img@mew.org>
### Created: Apr 23, 1997
-### Revised: Apr 14, 2000
+### Revised: Dec 7, 2002
###
-my $PM_VERSION = "IM::Nntp.pm version 20000414(IM141)";
+my $PM_VERSION = "IM::Nntp.pm version 20021207(IM142)";
package IM::Nntp;
require 5.003;
@@ -39,20 +39,6 @@ use vars qw(@ISA @EXPORT);
nntp_spec
);
-=head1 NAME
-
-NNTP - NNTP interface package
-
-=head1 SYNOPSIS
-
-$return_code = &nntp_transaction(server_list, newsgroups,
- part_current, part_total, authuser);
-$return_code = &nntp_close;
-
-=head1 DESCRIPTION
-
-=cut
-
use vars qw($Nntp_opened *NNTPd $NntpErrTitle);
##### NNTP SESSION OPENING #####
@@ -64,8 +50,8 @@ use vars qw($Nntp_opened *NNTPd $NntpErrTitle);
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub nntp_open ($$) {
- my ($servers, $logging) = @_;
+sub nntp_open($$) {
+ my($servers, $logging) = @_;
my $rc;
if ($Nntp_opened) {
@@ -79,7 +65,7 @@ sub nntp_open ($$) {
if ($rc = &tcp_command(\*NNTPd, '', '')) {
return $rc;
}
- my (@resp) = &command_response;
+ my(@resp) = &command_response;
if ($resp[0] =~ /InterNetNews server INN/) {
return 1 if (&tcp_command(\*NNTPd, 'MODE reader', ''));
}
@@ -95,7 +81,7 @@ sub nntp_open ($$) {
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub nntp_close () {
+sub nntp_close() {
return 0 unless ($Nntp_opened);
$Nntp_opened = 0;
im_notice("closing NNTP session.\n");
@@ -117,8 +103,8 @@ sub nntp_close () {
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub nntp_transaction ($$$$$$$) {
- my ($servers, $Header, $Body, $group, $part, $total, $authuser) = @_;
+sub nntp_transaction($$$$$$$) {
+ my($servers, $Header, $Body, $group, $part, $total, $authuser) = @_;
my $rc;
require IM::Log && import IM::Log;
@@ -126,7 +112,7 @@ sub nntp_transaction ($$$$$$$) {
&set_nntpauthuser($authuser);
do {
$rc = &nntp_transact_sub($servers, $Header, $Body, $part, $total);
- my (@resp) = &command_response;
+ my(@resp) = &command_response;
if ($rc) {
&im_warn($NntpErrTitle . join("\n", @resp) . "\n");
$NntpErrTitle = '';
@@ -153,8 +139,8 @@ sub nntp_transaction ($$$$$$$) {
# 1: recoverable error (should be retried)
# -1: unrecoverable error
#
-sub nntp_transact_sub ($$$$$) {
- my ($servers, $Header, $Body, $part, $total) = @_;
+sub nntp_transact_sub($$$$$) {
+ my($servers, $Header, $Body, $part, $total) = @_;
my $rc;
return $rc if ($rc = &nntp_open($servers, 1));
@@ -177,9 +163,9 @@ sub nntp_transact_sub ($$$$$) {
return 0;
}
-sub nntp_head_as_string ($) {
+sub nntp_head_as_string($) {
my $i = shift;
- my ($rc, $count) = ('', 0);
+ my($rc, $count) = ('', 0);
local $_;
im_notice("getting article $i.\n");
@@ -190,7 +176,7 @@ sub nntp_head_as_string ($) {
return -1;
}
$count++;
- my ($found, $f) = (0, '');
+ my($found, $f) = (0, '');
alarm(nntp_timeout()) unless win95p();
$! = 0;
while (<NNTPd>) {
@@ -211,8 +197,8 @@ sub nntp_head_as_string ($) {
return $f;
}
-sub nntp_head ($$) {
- my ($art_start, $art_end) = @_;
+sub nntp_head($$) {
+ my($art_start, $art_end) = @_;
local $_;
my $count = 0;
@@ -226,7 +212,7 @@ sub nntp_head ($$) {
return -1;
}
$count++;
- my ($found, $f) = (0, '');
+ my($found, $f) = (0, '');
alarm(nntp_timeout()) unless win95p();
$! = 0;
while (<NNTPd>) {
@@ -257,8 +243,8 @@ sub nntp_head ($$) {
return $count;
}
-sub nntp_xover ($$) {
- my ($art_start, $art_end) = @_;
+sub nntp_xover($$) {
+ my($art_start, $art_end) = @_;
my $rc = &tcp_command(\*NNTPd, "XOVER $art_start-$art_end", '');
if ($rc) {
@@ -266,7 +252,7 @@ sub nntp_xover ($$) {
return -1;
}
my $count = 0;
- my ($resp);
+ my($resp);
while (($resp = &next_response(\*NNTPd)) !~ /^\.$/) {
$count++;
my @overview = split('\t', $resp);
@@ -285,17 +271,17 @@ sub nntp_xover ($$) {
return $count;
}
-sub nntp_article ($) {
+sub nntp_article($) {
my $num = shift;
local $_;
-# local (@Article);
+# local(@Article);
im_debug("getting article $num.\n") if (&debug('nntp'));
my $rc = &tcp_command(\*NNTPd, "ARTICLE $num", '');
- return (1, '') if ($rc > 0);
+ return(1, '') if ($rc > 0);
if ($rc < 0) {
im_warn("ARTICLE command failed.\n");
- return (-1, '');
+ return(-1, '');
}
my @Article = ();
alarm(nntp_timeout()) unless win95p();
@@ -305,7 +291,7 @@ sub nntp_article ($) {
alarm(0);
if ($!) { # may be channel truoble
im_warn("lost connection for ARTICLE.\n");
- return (-1, '');
+ return(-1, '');
}
}
s/\r\n$/\n/;
@@ -315,12 +301,12 @@ sub nntp_article ($) {
im_debug($_) if (&debug('nntp'));
}
alarm(0) unless win95p();
- return (0, \@Article);
+ return(0, \@Article);
}
-sub nntp_articles ($$$$) {
- my ($art_start, $art_end, $dst, $limit) = @_;
- my ($rc, $article);
+sub nntp_articles($$$$) {
+ my($art_start, $art_end, $dst, $limit) = @_;
+ my($rc, $article);
my $count = 0;
my $last = 0;
@@ -343,10 +329,10 @@ sub nntp_articles ($$$$) {
last if ($limit && --$limit == 0);
}
&exec_getsbrfile($dst);
- return ($count, $last);
+ return($count, $last);
}
-sub nntp_list ($) {
+sub nntp_list($) {
my $group = shift;
local $_;
my $rc;
@@ -366,13 +352,13 @@ sub nntp_list ($) {
return $count;
}
-sub nntp_command ($) {
+sub nntp_command($) {
my $cmd = shift;
my $rc = &tcp_command(\*NNTPd, $cmd, '');
return -1 if ($rc < 0);
if ($rc > 0) {
- my ($res) = &command_response();
+ my($res) = &command_response();
if ($res =~ /^480/) {
require IM::GetPass && import IM::GetPass;
@@ -382,7 +368,7 @@ sub nntp_command ($) {
my $user = &nntpauthuser() ||
$ENV{'USER'} || $ENV{'LOGNAME'} || im_getlogin();
my $host = get_cur_server();
- my ($pass, $agtfound, $interact)
+ my($pass, $agtfound, $interact)
= getpass('nntp', 'PASS', $host, $user);
# authenticate for posting
@@ -398,29 +384,29 @@ sub nntp_command ($) {
return $rc;
}
-sub nntp_command_response () {
+sub nntp_command_response() {
return &command_response;
}
-sub nntp_next_response () {
+sub nntp_next_response() {
return &next_response(\*NNTPd);
}
-sub set_last_article_number ($$$) {
- my ($server, $group, $number) = @_;
- my ($pos, $last, $size) = (0, 0, 0);
+sub set_last_article_number($$$) {
+ my($server, $group, $number) = @_;
+ my($pos, $last, $size) = (0, 0, 0);
$server =~ s!\%\d+$!!;
$server =~ s!/\d+$!!;
my $nntphist = &nntphistoryfile() . '-' . $server;
- if ( -f $nntphist ) {
+ if (-f $nntphist) {
im_open(\*NEWSHIST, "+<$nntphist");
while ($pos = tell(NEWSHIST), $_ = <NEWSHIST>) {
/^([^:]+):\s*(\d+)/;
if ($group eq $1) {
$last = $2;
im_debug("$last articles in $group ($nntphist)\n")
- if(&debug('nntp'));
+ if (&debug('nntp'));
seek(NEWSHIST, $pos, 0);
$size = length($_) - length("$group: 0000000\n");
if ($size < 0) {
@@ -445,8 +431,8 @@ sub set_last_article_number ($$$) {
return $last;
}
-sub get_last_article_number ($$) {
- my ($server, $group) = @_;
+sub get_last_article_number($$) {
+ my($server, $group) = @_;
local $_;
my $number = 0;
@@ -467,33 +453,33 @@ sub get_last_article_number ($$) {
}
-sub nntp_get_message ($$) {
- my ($src, $msg) = @_;
- my ($rc, $art);
- my ($group, $srvs) = nntp_spec($src, nntpservers());
+sub nntp_get_message($$) {
+ my($src, $msg) = @_;
+ my($rc, $art);
+ my($group, $srvs) = nntp_spec($src, nntpservers());
my @servers = split(',', $srvs);
im_notice("accessing to $group on $srvs.\n");
do {
if (($rc = nntp_open(\@servers, 0)) < 0) {
- return (-1, "can not connect $srvs.\n");
+ return(-1, "can not connect $srvs.\n");
}
if (($group ne '') && ($rc = nntp_command("GROUP $group")) < 0) {
- return (-1, "can not access $group.\n");
+ return(-1, "can not access $group.\n");
}
} while (@servers > 0 && $rc > 0);
- return (-1, "can not access $group on $srvs.\n") if ($rc);
+ return(-1, "can not access $group on $srvs.\n") if ($rc);
($rc, $art) = nntp_article($msg);
nntp_close();
- return (-1, "no message $msg in -$group.\n") if ($rc);
- return (0, $art);
+ return(-1, "no message $msg in -$group.\n") if ($rc);
+ return(0, $art);
}
# returns number of got articles
# -1 if error
-sub nntp_get_msg ($$$$) {
- my ($src, $dst, $how, $limit) = @_;
- my ($rc, $group, $error, $art_start, $art_end);
- my ($servers, @servers);
+sub nntp_get_msg($$$$) {
+ my($src, $dst, $how, $limit) = @_;
+ my($rc, $group, $error, $art_start, $art_end);
+ my($servers, @servers);
if ($src =~ /^nntp:(.*)/i || $src =~ /^news:(.*)/i) {
($group, $servers) = &nntp_spec($1, nntpservers());
@@ -514,7 +500,7 @@ sub nntp_get_msg ($$$$) {
} while (@servers > 0 && $rc > 0);
return -1 if ($rc);
- my (@resp) = &command_response;
+ my(@resp) = &command_response;
$error = 0;
my $i;
for ($i = 0; $i <= $#resp; $i++) {
@@ -535,7 +521,7 @@ sub nntp_get_msg ($$$$) {
return -1;
}
- my ($art_last, $msgs);
+ my($art_last, $msgs);
$art_last = &get_last_article_number($servers, $group);
if ($art_end > $art_last) {
# new articles
@@ -587,7 +573,7 @@ sub nntp_get_msg ($$$$) {
}
if ($how eq 'get') {
- my ($last);
+ my($last);
if ($msgs > 0) {
im_info("Getting new messages from $group at $servers "
. "into $dst....\n");
@@ -609,8 +595,8 @@ sub nntp_get_msg ($$$$) {
}
# News group (-group[@server])
-sub nntp_spec ($$) {
- my ($spec, $server) = @_;
+sub nntp_spec($$) {
+ my($spec, $server) = @_;
my $group;
if ($spec =~ /^-(.*)/) {
@@ -621,11 +607,51 @@ sub nntp_spec ($$) {
} else {
$group = $spec;
}
- return ($group, $server);
+ return($group, $server);
}
1;
+__END__
+
+=head1 NAME
+
+IM::Nntp - NNTP hanlder
+
+=head1 SYNOPSIS
+
+ use IM::Nntp;
+
+ $return_code = &nntp_transaction(server_list, newsgroups,
+ part_current, part_total, authuser);
+ $return_code = &nntp_close;
+
+Other subroutines:
+nntp_open
+nntp_article
+nntp_list
+nntp_command
+nntp_command_response
+nntp_next_response
+nntp_get_message
+nntp_get_msg
+nntp_head_as_string
+nntp_spec
+
+=head1 DESCRIPTION
+
+The I<IM::Nntp> module handles NNTP.
+
+This modules is provided by IM (Internet Message).
+
+=head1 COPYRIGHT
+
+IM (Internet Message) is copyrighted by IM developing team.
+You can redistribute it and/or modify it under the modified BSD
+license. See the copyright file for more details.
+
+=cut
+
### Copyright (C) 1997, 1998, 1999 IM developing team
### All rights reserved.
###