#!/usr/bin/perl use News::Article; use Net::NNTP; use Getopt::Std; use strict; use vars qw ($nntpuser $server $nntpuser $nntppass $opt_h $whoami $miniinews $munge); ### Variables to set before using ######################################## $whoami = "/usr/ucb/whoami"; # The location of your 'whoami' binary. $server = "/etc/nntpserver"; # The name of the server (or a file to # load it from) $miniinews = 1; # Set this if you want this to act like # the nn mini-inews - adding headers, etc. $munge = 1; # Turn this off if you never want to mess # with the headers at all. ########################################################################## getopts('h'); # This is purely for compatibility. $server = $ENV{'NNTPSERVER'} if $ENV{'NNTPSERVER'}; # Load the server name out of the file $server if it started with a /. if ($server =~ m%^/%) { open (NNTPSERVER, "<$server") or die "Couldn't open $server!"; $server = ; chomp $server; close (NNTPSERVER); } # Load ~/.nntpauth if (-r "$ENV{'HOME'}/.nntpauth") { open (CONFIG, "<$ENV{'HOME'}/.nntpauth") or die "Couldn't open ~/.nntpauth"; while () { chomp; if (/^\s*(\S+)\s+(\S+)\s+(\S+)\s*$/) { my $serv = $1; my $user = $2; my $pass = $3; $nntpuser = $user if ($serv =~ /^$server$/i); $nntppass = $pass if ($serv =~ /^$server$/i); } } close(CONFIG); } # If no user is found in ~/.nntpauth, $nntpuser ||= (`$whoami`); chomp($nntpuser); my $article = new News::Article; if (@ARGV) { my $file = shift(@ARGV); die "Can't read file $file" unless (-r $file); $article->read($file); } else { $article->read(\*STDIN); } # Add heads and such if ($munge) { $article->drop_headers("date"); $article->add_date; $article->add_message_id ( "$nntpuser." ) ; } my $NNTP = Net::NNTP->new($server); exit "Couldn't connect to server $server" unless $NNTP; $NNTP->authinfo($nntpuser, $nntppass) if defined($nntppass); eval { $article->post($NNTP) }; die "Error in posting: $@" if $@;