#!/usr/bin/perl
# Two names for this script:
#   uumult [file]...
#   uupack [file]...
#
# This little program reads one or more files, and looks for  uuencode
# headers.  When they are found, the data is fed to uudecode. The main
# purpose is to uudecode the multi-file (emailable) postings that  are
# used to send uuencoded pictures.  The standard uudecode can't handle
# input that is broken into chunks;  this  is  a  wrapper  that  takes
# multiple chunks and feeds them to uudecode as a single chunk.

for $f (@ARGV) {
	if (open(F,"<$f")) {
		for (<F>) {
			if (/^BEGIN\b/)  {
#				print "BEGIN: $_";
				$data = 1;	# We're now in a uuencoded-data section.
			} elsif (/^begin\s+\d+\s/)  {
				print "begin  : $_";
				print U "$_";
				$data = 1;	# We're now in a uuencoded-data section.
			} elsif (/^END\b/)  {
#				print "END  : $_";
				$data = 0;
			} elsif (/^section\b/)  {
				print "section: $_";
#				print U "$_";
				$data = 0;
			} elsif ($data) {
				if (/^begin\b/)  {
					print U "end\n" if $open;
#					print "Bgin: $_";
					open(U,"|uudecode") 
						|| die "$0: Can't exec uudecode [$!]\n";
					$open = 1;
				}
				print U;	# Send one line to uudecode.
#			} else {
#				print "Drop: $_";
			}
		}
	} else {
		print STDERR "$0: Can't read \"$f\"\n";
	}
}
print U "end\n" if $open;
