Article View: news.software.nntp
Article #34115Re: inews-like program for non-local server?
From: Fluffy
Date: Mon, 28 Dec 1998 00:00
Date: Mon, 28 Dec 1998 00:00
125 lines
3978 bytes
3978 bytes
Adam Bailey <adamb@tezcat.com> wrote:
> I'm trying to find something that works along the lines of inews,
> but will connect to any server given on the command line. Does
> something like this exist?
Here's toy-inews which can do it. Needs Perl5 and the libnet bundle.
Careful with the -D option. Unlike the INN inews, it does actually
attempt to post.
I'm assuming you're looking for a shell thingy, not a Mac thingy;
this will probably break on the latter.
#! /usr/local/bin/perl -w
#
# Usage:
#
# Unlike "real" inews programs, -h is always assumed, and you have
# to supply your own From: header.
#
# toy-inews -snews.example.com .article # posts to news.foo.com
# toy-inews -snews.example.com:username:password .article # with authinfo
# toy-inews -D .article # display the transaction for debugging
# toy-inews -S .article # append $HOME/.signature to article
require 5.004;
use Net::NNTP;
use strict;
### Plug in your domain (for message here. ###
my $domain = "meow.invalid";
### This is the default, override with -s ###
my $nntpserver = "news";
my $debug = 0;
my $signature = 0;
my ($nntp, $infile, @article, $msgid, $idhdr, $result, $mod,
$username, $password,
);
for (@ARGV) {
if (not /^-/) {
$infile = $_;
} elsif (/^-D/) {
$debug = 1;
} elsif (/^-S/) {
$signature = 1;
} elsif (/^-s/) {
s/^-s//;
($nntpserver, $username, $password) = split /:/, $_;
}
}
if ($infile) { open(STDIN, $infile) or die "can't open $infile, stopped" }
# Get message ID if present
HDRLINE: while (<STDIN>) {
last HDRLINE if (/^$/);
push @article, $_;
chomp;
$msgid = $1 if /^Message-ID:\s+(.+)/i;
}
# Generate a message ID if needed.
if (!$msgid) {
$msgid = innid($domain);
$idhdr = "Message-ID: " . $msgid . "\n";
}
# Write the article.
push @article, ($idhdr) if $idhdr;
push @article, "\n";
# the chomp then add back \n is to fix up files missing stuff.
while (<STDIN>) {
chomp;
push @article, $_ . "\n";
}
if ($signature) {
if (-s "$ENV{HOME}/.signature") {
push @article, "-- \n";
open(SIG, "$ENV{HOME}/.signature");
while (<SIG>) {
chomp;
push @article, $_ . "\n";
}
}
}
$nntp = Net::NNTP->new($nntpserver, "Debug", $debug);
if ($username && $password) {
die ("Authinfo failed") unless $nntp->authinfo($username, $password);
}
$result = $nntp->post(@article);
die "Posting failed :-( " unless $result;
exit 0;
# fin
# intcode: Convert an integer to an arbitrary character set
# $tm: integer to encode $alfa: character set string
sub intcode {
my $tm = shift;
my $alfa = shift;
my $id = "";
my $radix = length($alfa);
while (1 < $tm) {
$mod = $tm % $radix;
$id = substr($alfa, $mod, 1) . $id;
$tm = $tm / $radix;
}
return $id;
}
sub innid ($host) {
my $host = shift;
my $alphabet = "0123456789abcdefghijklmnopqrstuv";
return("<" . intcode(time - 673416000, $alphabet) . "\$" .
intcode($$, $alphabet) . "\@" . $host .">");
}
--
"FEAST!"
--Alice
Technical Details
Message-ID:
<766mnm$kml@meow.invalid>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<766g26$f6h$1@tepe.tezcat.com>Show Full Headers
Complete Article Headers
Message-ID: <766mnm$kml@meow.invalid> Subject: Re: inews-like program for non-local server? Date: Mon, 28 Dec 1998 00:00:00 +0000 From: meowing@banet.net (Fluffy) References: <766g26$f6h$1@tepe.tezcat.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 426302131 Mail-Copies-To: never X-Notice: should be reported to postmaster@ibm.net X-Complaints-To: postmaster@ibm.net X-Trace: 28 Dec 1998 01:26:20 GMT, 129.37.108.102 Organization: Alternative Pinwheel Iceland The Manitoba X-URL: http://members.tripod.com/~gerglery/ X-P-Meow: Meow Cancel-Lock: sha1:rcwDAuVUpUb+swqpfbw4ZSbuYkg= Newsgroups: news.software.nntp