#!/bin/sh
# "tarmailchunky" takes a file or list of files and creates a "tar file" it
# then compresses this data (using compress) and converts it to an ascii
# form (using btoa). If it is "too large" to fit into typical mail
# transport systems (some uucp sites break at 64K bytes), it will split
# the image into multiple parts and send them using the standard "mail"
# command.
if test $# -lt 3; then
  echo "Usage:  tarmailchunky mailpath \"subject-string\" directory-or-file(s)"
  echo
  echo "tarmailchunky is a shell script that uses tar, compress, btoa, and split"
  echo "to send arbitrary hierarchies by mail.  It sends things as one or"
  echo "more < 64K pieces.  (see shell script to change this size)."
  exit
else
  mailpath=$1
  echo "mailpath = $mailpath"
  shift
  subject="$1"
  echo "subject-string = $subject"
  shift
  echo files = $*
  tar cvf - $* | compress | btoa | split -750 - /tmp/tm$$
  n=1
  set /tmp/tm$$*
  for f do
    {
	echo '---start beef'
	cat $f
	echo '---end beef'
    } | Mail -s "$subject - part $n of $#" $mailpath
    echo "part $n of $# sent (" `wc -c < $f` "bytes)"
    n=`expr $n + 1`
  done
  rm /tmp/tm$$*
fi
