🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nn
Article #3290

Re: Pack/unpack utilities to work with Usenet

#3290
From: Bill Wohler
Date: Mon, 30 Nov 1992 11:17
194 lines
5293 bytes
> 2)  At a UNIX prompt, take a filename, remove everything from it up
> to and including the header.  Then uudecode it, uncompress it, and untar it.

  i posted this script to accomplish exactly this a while ago to
  comp.mail.mh, but not to these.  this script automatically extracts
  encoded source in multiple mail messages from ftpmail@decwrl.dec.com,
  archive-server@Germany.EU.net and ftp-mailer@ftp.informatik.tu-muenchen.de
  to name a few.

  things i'd like to do is to get people to use btoa instead of
  uuencode, but failing that, automatically extract the uudecoded
  file.  this script could also be easily converted so that it doesn't
  depend on mh.  it's also unfortunately customized to my
  environment.  please send me diffs if you improve upon it.

  instructions are in the header.  if you use this, please let me know
  so i can add you to my "mailing list."

						--bw


#! /bin/sh
#
# $Header: main.sh,v 1.2 89/03/22 15:06:00 wohler Exp $
#
# NAME
#   untarftps - extract sources, etc. from mail servers
#
# SYNOPSIS
#   untarftps [-b] [-c] [-ns] [-t] [-s] [-u] maildir [output-file]
#
# DESCRIPTION
#   Put back together multi-part mail messages into their original
#   form.  These messages may be listings, tars or shars that have
#   compressed and asciified.  Simply specify which processes have
#   been applied to the messages and the they will be reversed in the
#   right order.
#
#   The messages are found in the MH mail folder "maildir"; a
#   directory of the same name will be created in the current
#   directory and the original contents in the original form will be
#   placed there.
#
# OPTIONS
#   -b	has been asciified with btoa.
#   -u  has been asciified with uuencode.
#   -c  has been compressed.
#   -t  has been tarred.
#   -s  has been sharred.
#   -ns don't sort messages
#
# RETURNS
#   Exits with status 1 upon error (bad arguments, can't create files,
#   and so on); otherwise 0.
#
# AUTHOR
#   Bill Wohler		SAP AG		8 Nov 1991

#
# Set variables
#
mail=$HOME/usr/spool/mail
startdir=`pwd`
outf=/tmp/ut1$$
tmp=/tmp/ut2$$
cmd=`basename $0`
btoa=0
compressed=0
uuencoded=0
untar=0
unshar=0
sort=1

#
# Process arguments
#
while [ $# != 0 ]; do
	case "$1" in
	-v)	print=1;;
	-b)
		btoa=1
		;;
	-c)
		compressed=1
		;;
	-ns)
		sort=0
		;;
	-u)
		uuencoded=1
		;;
	-t)
		untar=1
		;;
	-s)
		unshar=1
		;;
	-*)
		echo "Usage: $cmd [-b] [-c] [-t] [-s] [-u] maildir"
		echo "       -b   input is btoa'd"
		echo "       -c   input is compressed"
		echo "       -u   input is uuencoded"
		echo "       -t   untar output"
		echo "       -s   unshar output"
		exit 1
		;;
	*)	break;;
	esac
	shift
done
file=$1
if [ $# -gt 1 ]; then
	output=$2
else
	output=$1.out
fi

#
# Check arguments.
#
if [ $btoa = 1 -a $uuencoded = 1 ]; then
	echo "$cmd: a file can't be both btoa'd and uuencoded."
	exit 1
fi
if [ $untar = 1 -a $unshar = 1 ]; then
	echo "$cmd: so, is it tarred or sharred?"
	exit 1
fi
if [ "$file" = "" ]; then 
	cat << EOF
Usage: $cmd [-b] [-c] [-ns] [-t] [-s] [-u] maildir [output-file]
       -b   input is btoa'd
       -c   input is compressed
       -u   input is uuencoded
       -t   untar output
       -s   unshar output
       -ns  don't sort messages
EOF
	exit 1
fi

#
# Sort messages
#
if [ $sort = 1 ]; then
	echo "Sorting."
	sortm +$file || exit 1
fi

#
# Remove the headers from each file.
#
cd $mail/$file
for i in [1-9] [1-9][0-9]; do
	if [ ! -f $i ]; then
		continue
	fi
	echo "Editing $i."
	if `grep -sl "^BEGIN -----" $i > /dev/null`; then
		# Muenchen mail server
		sed -e '1,/^BEGIN -----/d' -e '/^END -----/,$d' $i >> $outf
	elif `grep -sl "^------ begin" $i > /dev/null`; then
		# Dortmund mail server
		sed -e '1,/^------ begin/d' -e '/^------ end/,$d' $i >> $outf
	else
		sed '1,/^$/d' $i >> $outf
	fi
done

#
# Extract the files.
#
cd $startdir
if [ ! -d $file ]; then
	mkdir $file
fi
cd $file || exit 1

[ $btoa = 1 ]       && (btoa -a < $outf > $tmp || exit; mv $tmp $outf)
[ $uuencoded = 1 ]  && (uudecode < $outf || exit)
[ $compressed = 1 ] && (uncompress < $outf > $tmp || exit; mv $tmp $outf)
[ $untar = 1 ]      && (tar xvf $outf || exit)
[ $unshar = 1 ]     && (unshar -n $outf || exit)

# If the file hasn't been "processed" by tar or shar, then we have to
# move it manually..
if [ $uuencoded = 0 -a $untar = 0 -a $unshar = 0 ]; then
	mv $outf $output
fi
rm -f $outf

Bill Wohler <wohler@sap-ag.de> <sapwdf!wohler>
Heidelberg Red Barons Ultimate Frisbee Team
Technical Details
Message-ID: <4133@sapwdf.UUCP>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.mail.uucp.mbox.zip!sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!sapwdf!wohler

Show Full Headers
Complete Article Headers
Message-ID: <4133@sapwdf.UUCP>
Subject: Re: Pack/unpack utilities to work with Usenet
Date: Mon, 30 Nov 1992 11:17:41 +0000
From: wohler@sapwdf.UUCP (Bill Wohler)
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-comp.mail.uucp.mbox.zip!sparky!uunet!math.fu-berlin.de!mailgzrz.TU-Berlin.DE!news.netmbx.de!Germany.EU.net!sapwdf!wohler
Newsgroups: comp.mail.uucp,news.software.nn,news.software.readers
Summary: a script to answer richard's 2nd question
Reply-To: Bill Wohler <wohler@sap-ag.de>
Organization: SAP AG, Walldorf, Germany
Lines: 193