use FileHandle;
$usage =
- "usage: nntpid [ -v ] <message-id>\n" .
- " or: nntpid [ -v ] <newsgroup> <article-number>\n" .
+ "usage: nntpid [ -v ] [ -d ] <message-id>\n" .
+ " or: nntpid [ -v ] [ -d ] <newsgroup> <article-number>\n" .
"where: -v verbose (print interaction with news server)\n" .
+ " -d direct output (don't consider using PAGER)\n" .
" also: nntpid --version report version number\n" .
" nntpid --help display this help text\n" .
" nntpid --licence display (MIT) licence text\n";
"CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n" .
"SOFTWARE.\n";
+$pager = 1;
+$verbose = 0;
+
while ($ARGV[0] =~ /^-(.+)$/) {
shift @ARGV;
- $verbose=1, next if $1 eq "v";
+ $verbose = 1, next if $1 eq "v";
+ $pager = 0, next if $1 eq "d";
if ($1 eq "-help") {
print STDERR $usage;
exit 0;
# some servers require a GROUP before an ARTICLE command
&docmd("GROUP $group");
&docmd("ARTICLE $mid");
+$art = "";
while (1) {
&getline;
s/[\r\n]//g;
last if /^\.$/;
s/^\.//;
- print STDOUT "$_\n";
+ $art .= "$_\n";
}
&docmd("QUIT");
close S;
+if ($pager and -t STDOUT) {
+ $pagername = $ENV{"PAGER"};
+ $pagername = "more" unless defined $pagername;
+ open PAGER, "| $pagername";
+ print PAGER $art;
+ close PAGER;
+} else {
+ print $art;
+}
+
sub putline {
my ($line) = @_;
print STDERR ">>> $line\n" if $verbose;
\U SYNOPSIS
-\c nntpid [ -v ] message-id
-\e bbbbbb bb iiiiiiiiii
-\c nntpid [ -v ] newsgroup-name article-number
-\e bbbbbb bb iiiiiiiiiiiiii iiiiiiiiiiiiii
+\c nntpid [ -v ] [ -d ] message-id
+\e bbbbbb bb bb iiiiiiiiii
+\c nntpid [ -v ] [ -d ] newsgroup-name article-number
+\e bbbbbb bb bb iiiiiiiiiiiiii iiiiiiiiiiiiii
\U DESCRIPTION
news server, so they will be different on other servers carrying the
same group.
+By default, \cw{nntpid} will try to display the article using a
+pager (\cw{more}(1), unless you have specified an alternative in the
+environment variable \cw{PAGER}). This is partly for convenience,
+and partly a mild security measure: it gives you some protection
+against the news article potentially containing control sequences
+that cause unexpected behaviour in your terminal. If \cw{nntpid}
+detects that its standard output is not a terminal, however, it will
+bypass the pager and just write out the article directly.
+
\U ARGUMENTS
If you specify one argument, \cw{nntpid} assumes it is a Message-ID.
\dd Verbose mode. In this mode, \cw{nntpid} will log its entire
conversation with the news server on standard error.
+\dt \cw{-d}
+
+\dd Direct output. In this mode, \cw{nntpid} will write the article
+straight to standard output without bothering to try using a pager.
+
\U AUTHENTICATION
Currently, the only form of authentication supported by \cw{nntpid}