🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Tom Grydeland Sun, 02 Aug 1992 17:35
post, a multipart archive poster part 00/00
#1
Author: Tom Grydeland
Date: Sun, 02 Aug 1992 17:35
238 lines
8889 bytes
Here is my post(TM) perl script for posting multipart
arcives on The Net. It has only been tested on the local system,
and I make NO GUARANTEES whatsoever that it will work anywhere else.
It needs inews(1) but could probably be modified to telnet directly to
the NNTPSERVER. Comments and bug reports appreciated.

NB! This script does NOT create the multipart archive, it merely
makes it easier to post them in a numbered sequence and apply the
appropriate header to each part with minimum effort.

If no <Header> file exists in cwd or the file does not contain the
Newsgroups: field, post will ask for the field(s). If no files have
been given, post will ask for them (although only once).

post [-help] [-s subject] [-h headerfile] [files]

#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 08/02/1992 17:24 UTC by tomg@lgserv0
# Source directory /users/disk1/tomg/tmp
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   5908 -rwxr-xr-x post
#
# ============= post ==============
if test -f 'post' -a X"$1" != X"-c"; then
	echo 'x - skipping post (File already exists)'
else
sed 's/^X//' << 'SHAR_EOF' > 'post' &&
#!/usr/bin/perl -- # -*-Perl-*-
X
# Post, a program for posting multifile archives on USENET
# (c) 1992 Tom Grydeland (tomg@stud.cs.uit.no) all rights reserved.
X
select STDERR;					# Default destination of print
$i = 0;							# Counter
$tempfile = "Article.$$.post";	# Temporary files
$header = "Header";				# Default header file
$subject = "";					# Default subject field
$total = 0;						# Number of parts
($me) = reverse(split(m!/!, $0)); # The script name
X					  
$SIG{'HUP'}	 = 'IGNORE';		# Ignore SIGHUP
$SIG{'ALRM'} = 'IGNORE';		# Ignore SIGALRM
$SIG{'INT'}	 = 'handler';		# Abort on SIGINT
$SIG{'QUIT'} = 'handler';		# Abort on SIGQUIT
$SIG{'TERM'} = 'handler';		# Abort on SIGTERM
X
X ARG:							# Loop over arguments
X	while ($ARGV[0] =~ /^-/) {	# Parse flags
X		if ($ARGV[0] =~ /^-h\b/) { # Header file specified
X			shift (ARGV);
X			$header = shift (ARGV); # $header contains name of header file
X			print "Setting header to $header\n";
X			next ARG;
X		} elsif ($ARGV[0] =~ /^-s\b/) { # Subject specified
X			shift (ARGV);
X			$subject = shift (ARGV); # $subject contains subject
X			print STDERR "Setting subject to $subject\n";
X			next ARG;
X		} elsif ($ARGV[0] =~ /^-help/) { # flag -help, print message
X			print
X				"This is $me, a friendly poster for multiple files using\n",
X				"inews and written in perl. It was ment to be a stopgap\n",
X				"solution, and is NOT guaranteed to be USER friendly.\n",
X				"Options include:\n\t-s <subject>\n",
X				"\t-h <header file (default Header)>\n\n",
X				"The program assumes you are specifying the files in correct\n",
X				"order, and will post them in the order you provide, and call\n",
X				"the first file part 00/(number of files - 1)\n";
X			exit (0);
X		} else {				# Unknown option
X			print "Unrecognized option $ARGV[0], please concentrate!\n";
X			exit (0);
X		}
X	}
X
unless (-r $header)	 {			# Is there a header file here?
X	$intr_header = 1;			# set flag
X	&get_header;				# Get it
}
X
unless (&Ngfield) {				# There has to be a Newsgroups: field
X	&getNgfield;
}
X
while (!$subject) {				# Be sure to get a Subject: field
X	print "Which subject do you want on your posting? :";
X	chop ($subject = <STDIN>);	# Discard newline
}
X
while (! ($total = @ARGV)) {	# No more arguments (no files)
X	print
X		"I cannot see that you've given me files to post,\n",
X		"please give me some : \n";
X
X	chop ($args = <STDIN>);
X	@ARGV = split(/ /, $args);	# All these args are filenames
}
X
$total--;						# Begin numbering at part 00
X
X FILE:
X	foreach $file (@ARGV) {		# Loop over files
X
X		# If we can't open the header file, there's no use continuing
X		open (HEADER, "<$header") || die ("Couldn't open $header $!\n");
X		
X		unless (open (OUTFILE, ">$tempfile")) {
X			warn ("Couldn't open $tempfile $!\n");
X			next FILE;			# If you'd rather die than missing a part
X								# change that here...
X		}
X		unless (open (PART, "<$file")) {
X			warn ("Couldn't open $file $!\n");
X			next FILE;			# ...and here.
X		}
X
X		while (<HEADER>) {		# Copy all non-blank lines from the header file
X			unless (/^\n/) {print OUTFILE;}
X		}
X
X		# Print the Subject: field as the last line of the header and
X		# add a blank line.
X		print OUTFILE sprintf ("Subject: %s part %02d/%02d\n\n",
X							   $subject, $i, $total);
X
X		while (<PART>) {
X			print OUTFILE;		# Copy the input file in full.
X		}
X		close OUTFILE;			# Or inews will not see the entire file
X		print "Done part $i\n";	# Just to inform the waiting audience
X		system ("inews -h $tempfile"); # Post this part
X		print "Posted part $i\n";
X
X		$i++;					# Advance to next part
X
X	} continue {
X
X		close OUTFILE;			# Close open files
X		close HEADER;
X		close PART;
X
X	}
X
if ($intr_header) {unlink $header;} # Remove interactively made header-file
unlink $tempfile;				# Remove temporary file
Xexit 0;							# Exit success
X
#####################################
# Subroutines to be called from main#
#####################################
X
sub handler {					# Cleaning up when catching a signal
X	local ($sig) = @_;
X	print "\nCaught a SIG$sig, cleaning up\n";
X	close OUTFILE;
X	close HEADER;
X	close PART;
X	unlink $tempfile;
X	if ($intr_header) {unlink $header;}
X	exit -1;					# Exit failure
}
X
sub get_header {					   # Get a header interactively
X	print
X		"Since you don't have a $header file and you didn't specify\n",
X		"another filename, I guess you'd like to make one now. If you don't,\n",
X		"please interrupt the program to get out.\n";
X	
X	$header = "Header.$$.post"; # Interactively made header-file
X	&getNgfield;				# Get the Newsgroups: field
X
X	# If we can't make a header, we might as well die.
X	open (HEADER, ">>$header") || die ("Couldn't open $header $!\n");
X
X	print
X		"It might also be an idea to include a line:\n",
X		"Followup-To: <group>\nif you are posting to a sources group or a\n",
X		"Distribution: <distr>\nif you are posting to a test group.\n",
X		"Some other lines will be included by inews\n",
X		"which also includes your .signature file (truncated to four lines)\n",
X		"Please type '.' on a line for itself when you are finished\n";
X
X	while (<STDIN>) {			# Get optional lines to header
X		if (/^\.\n/) {last;}	# '.' alone is last line
X		print HEADER;			# Echo to header file
X	}
X	close HEADER;
}
X
sub Ngfield {					# Make sure that there is a Newsgroups: field
X	$newsgroups = 0;			# This could probably be done more quickly
X	open (HEADER, "<$header") || die ("Couldn't open $header $!\n"); # 
X	while (<HEADER>) {
X		if (($newsgroups) = /^Newsgroups: (.*)/) {
X			close HEADER;
X			return 1;
X		}
X	}
X	close HEADER;
X	return 0;
}
X
sub getNgfield {				# Interactively get a Newsgroups: field
X	open (HEADER, ">>$header") || die ("Couldn't open $header $!\n");
X	do {
X		print
X			"You haven't provided a Newsgroups: field yet,\n",
X			"please do so right now\n\nNewsgroups: ";
X		chop ($newsgroups = <STDIN>);
X	} until ($newsgroups);
X	$newsgroups =~ s/Newsgroups: //;
X	$newsgroups =~ tr/ \t/,,/;
X	print HEADER "Newsgroups: $newsgroups\n";
X	close HEADER;
}
SHAR_EOF
chmod 0755 post ||
echo 'restore of post failed'
Wc_c="`wc -c < 'post'`"
test 5908 -eq "$Wc_c" ||
	echo 'post: original size 5908, current size' "$Wc_c"
fi
exit 0
//tomg@stud.cs.uit.no (Tom Grydeland)+47 8375164; Tunvn.29 B21,N-9018,Troms\o
"I quite agree with you," said the Dutchess; "and the moral of that is- `Be what
you would seem to to be'-or if you'd like to put it more simply- `Never imagine
yourself not to be otherwise than what it might appear to others that what you
were or might have been was not otherwise than what you had been would have
appeared to them to be otherwise'"  --The Dutchess `Alice in wonderland'
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads