From: schumack@pan.ssec.honeywell.com (Ken Schumack)
Subject: re: File-splitter for email
Posted-Date: Thu, 3 Sep 92 15: 29:36 -0500
Organization: Electrotechnical Laboratory, Tsukuba Science City
Distribution: fj
Date: Thu, 3 Sep 1992 20:29:36 GMT
Return-Path: <schumack@pan.ssec.honeywell.com>



> <<forwarded message>>
> 
> In article <1992Aug28.172903.27023@hns.com> rtaylor@hns.com (Randy Taylor) writes:
> >
> >A freind of mine is looking for a file splitter
> >for email.  He is transmitting 100k to 1 Meg
> >ASCII files and it seems that most mail programs
> >can handle a max "chuck" size of 50 k.
> >
> 
> Have a look at   split
> 
> It should do what you want.
> 
>    Andy
> 

For what it's worth you might also take a look at the following routine:
Example of use...
To send a directory/file(s) type:

mailsplit -l 3000 userSendingTo BigFileName

to recover type: 

mailjoin BigFileName

-------------------------------------------------------------------------------
Ken Schumack                              phone:612-541-2743
Honeywell(Solid State Electronics Center) fax  :612-541-2504
MN14-4B80                                 email:schumack@pan.ssec.honeywell.com
-------------------------------------------------------------------------------


#!/bin/sh
##############################################################################
# These commands and paths should be configured for your machine/site
BASENAME=/usr/bin/basename
TEST=/bin/test
CAT=/bin/cat
RM=/bin/rm
SPLIT=/usr/bin/split
SLEEP=/usr/bin/sleep         # Sleep command
TA=/bin/tar                  # Archive command (assumed here to be in search path!)
CO=/usr/ucb/compress         # Default compress command  (assumed to be in search path!)
MA=/usr/ucb/Mail             # Default Mail program
UU=/usr/bin/uuencode         # uuencode command (assumed here to be in search path!)
CB=16                        # Default number of bits to use in compress
CF="-b 16"                   # Default compress command line flag(s)
MS=Subj                      # Mailer Subject line flag
DE=0                         # Default delay time between sending pieces
TD=/tmp                      # Default temporary directory for storing temp files
DB=5                         # Default debugging level
##############################################################################
#
# mailsplit:  package, transmit, re-assemble unix directories via e-mail
#
# @(#)mailsplit.SH    2.6    88/08/20       M F Wyle
# Syntax corrections to joinr script  90/03/06
# Rev 2.7 90/11/16  K V Schumack
#   updated to work w/ Mentor send, added variable for test
# Rev 2.8  replaced joinr w/ mailjoin
##############################################################################
# You might want to change these, but it's not likely.

ME=`$BASENAME $0`   # Program (my) name
LI=700              # Default number of lines for split-up pieces
CM="$0 $*"          # Command line
VE="2.8"            # Version of this program
MF=""               # Default Mailer flags
IJ="true"           # Flag which signals if joinr script should be prepended
TM=false            # Default test Mode flag (If set, don't do anything)
T1=$TD/1sp$$        # Default temp file for output of tar, compress
T2=$TD/2sp$$        # Default temp file for uuencoded output
T3=$TD/3sp$$        # Default temp file prefix for split pieces
T4=$TD/4sp$$        # a copy of mailjoin
##############################################################################

# You do NOT want to change these variables or their initial values!

RA=all              # Default range of pieces to send
FC=0                # File Count
ne="FL=$FL' '"      # Next command in parser
SU="_default_"      # Default Subject is first file or dir sent
FL=""               # Initialize file list
TO=""               # Initialize recipient
umask 0             # Important for writing reading files created!

# Human Factors Law Number 4:  
# "Upon startup, thou shalt tell the user where he is and how to quit."
#           -Ben Schneiderman-

echo " " 1>&2
echo "$ME version $VE" 1>&2
echo "Original coding (C) 1988  M F Wyle" 1>&2
echo " " 1>&2

##############################################################################
# Read beyond here at your own risk; you've entered... The hacker zone...
# Parse the command line for recipient, options, flags, files, dirs:

for AR in $* ; do
  case $AR in
    -C  ) ne="CO=" ;;
    -D  ) ne="TD=" ;;
    -M  ) ne="MF=" ;;
    -N  ) IJ="false" ;;
    -T  ) ne="TA=" ;;
    -V  ) DB=9     ;;
    -b  ) ne="CB=" ;;
    -d  ) ne="DE=" ;;
    -l  ) ne="LI=" ;;
    -m  ) ne="MA=" ;;
    -n  ) TM=true  ;;
    -r  ) ne="RA=" ;;
    -s  ) ne="SU=" ;;
    -t  ) TM=true ;;
    -v  ) echo "$ME version $VE" ;  exit 0 ;;
    -x* ) DB=`echo $AR | cut -c3` ; DB=${DB:-0} ;;
    -u  ) ne="UU=" ;;
    -*  ) echo " " ; echo "Bad flag for $ME": $AR
          echo "Usage:    $ME  [<options>] <mailpath> <file(s)>"
          echo "Example:  $ME  werner@utastro.uucp ./casetool"
          echo " "
          exit 0  ;;
    *   ) eval $ne"$AR" ; ne='FL=$FL" "' ;;
  esac
done
case $# in
  0 | 1 )
    echo " "
    echo "Usage:    $ME  [<options>] <mailpath> <file(s)>"
    echo "Example:  $ME  werner@utastro.uucp CaseTool"
    echo " "
    exit 0  ;;
esac
set $FL
TO=$1
case $SU in
  _default_ ) SU=$2 ;;
esac

case $DB in
  8|9) set -x ;;
esac

# create a copy of mailjoin in /tmp:
cat >$T4 <<'MAILJOIN!END'
----------------- start cut here for mailjoin routine ---------------------------
#!/bin/csh -f
#
# mailjoin - Extract and glue together mailsplit transmissions (c)KSchumack
# 1.0 : 05/05/92 : K.Schumack  needs /usr/ucb; schumack@pan.ssec.honeywell.com
# 1.1 : 05/06/92 : K.Schumack  modified nawk script to run faster, and
#                              only take the 1st complete object it finds
# 1.2 : 05/07/92 : K.Schumack  cat the mentor mail msgs in reverse order
#                              to get only the latest object. Added "V" variable
# 1.3 : 09/02/92 : K.Schumack  make educated guesses for mail type and nawk option
# 
############################################################################
# These commands and paths should be configured for your machine/site
#
set path=(/usr/ucb /usr/bin /bin $path)
##
#set MAILS=~/mail  # "~/mail" for Mentor mail; "/usr/spool/mail/$user" for UNIX mail
#make educated guess at to what type of mail is used...
if (-d ~/mail) then
    set MAILS=~/mail  # "~/mail" for Mentor mail
else
    set MAILS="/usr/spool/mail/$user" # for UNIX mail
endif
##
#set V             #!! use this line if your nawk uses "var=value" (check man page)
#set V="-v"        #!! use this line if your nawk uses "-v var=value" (check man page)
#some awks use -v look into man page to see which to use...
set V=`man nawk | nawk 'BEGIN{a=""} {if($0~"-v ")a="-v"} END{print a}'` 
#
############################################################################
set REV="1.3 09/03/92 (c) K.Schumack"
set DatE=`/bin/date` 
set TimE=$DatE[4]
set tempFile1=/tmp/{$TimE}.mailjoin1.tmp 
set tempcatFile=/tmp/{$TimE}.mailjoin.cat.tmp 
set tempuncompressFile=/tmp/{$TimE}.mailjoin.uncompress.tmp 
set nawkFile=/tmp/{$TimE}.mailjoin.nawk.tmp 
set haveObject=0
onintr interrupted

echo " ** mailjoin version $REV  **"
#
### command line
#
foreach String ($argv)
    if ( "$String" == "-help" || "$String" == "-h" ) then
        echo "Purpose:"
        echo "  provide a standard means of recovering mailsplit objects"
        echo ""
        echo "Usage:"
        echo "  mailjoin [object]"
        echo ""
        echo "Note:"
        echo "  An objects name is given on the subject line of the mail message"
        echo "  e.g."
        echo "     subj:  everest.gif - part 1 of 14"
        echo "  Here the object is everest.gif"
        echo ""
        exit(0)
    else if ( ! $haveObject ) then
            set object=$String
            set haveObject=1
            echo " "
            echo "Choose object $object on command line"
    else
            echo "WARNING *** unrecognized option '$String' on command line." 
    endif
end

while ( ! $haveObject )
    echo -n "Object: "
    set object=$<
    if ( "$object" !~ "" ) then
        set haveObject=1
    endif
end 

echo " "
if ( -d $MAILS ) then
    echo "Using Mentor mail recovery routine."
    set mailFile=$tempFile1
    echo "Gathering all $MAILS/m*.msg files ..."
    set saveDir=`pwd`
    cd $MAILS         # go to mail directory.
    cat `ls -1 m*.msg | sed 's|[msg.]||g' | sort -nr | nawk '{printf("m%s.msg ",$1)}'` > $mailFile 
    chdir $saveDir
else
    echo "Using UNIX mail recovery routine."
    set mailFile=$MAILS
    echo "Using $mailFile file ..."
endif
 
cat > $nawkFile <<!
BEGIN {
    error = 0
    first = 1
    printLine = 0
    process = 1
}
{
    if (process) {
        if (\$0 ~ /^--- start of .* part ([0-9]*) of ([0-9]*)\$/) {
            if (\$4 == object) {
                if (first) {
                    first = 0
                    totalNum = \$NF
                    for (i=1; i<=totalNum; i++) found[i] = 0
                }
                else {
                    process = 0
                    for (i=1; i<=totalNum; i++) if (found[i] == 0) process = 1
                }
                thisOne = \$6
                found[thisOne] = 1
                printLine = 1
                tempFile = sprintf("%s%d", temp, thisOne)
            }
        }
        else if ( NF == 0 ) printLine = 0
        else if (( NF == 1 ) && (length(\$1) == 1) && ( \$1 ~ /\`/ )) printLine = 0
        else if (\$0 ~ /^--- end of .* part ([0-9]*) of ([0-9]*)\$/) printLine = 0
        else if ((thisOne == totalNum) && (\$0 ~ /^end\$/)) printLine = 0
        else if (printLine) print \$0 >> tempFile
    }
}
END {
    for (i=1; i<=totalNum; i++) {
        if ( ! found[i]) {
            print "ERROR *** part " i " of " totalNum " not found."
            error = 1
        }
    }
    if (error) exit 1
    tempFile = sprintf("%s%d", temp, totalNum)
    printf("\`\nend\n") >> tempFile
    for (i=1; i<=totalNum; i++) command = sprintf("cat %s%d", temp, i)
    system(command " > " catfile)
    print "... found all " totalNum " pieces of " object " ..."
}
!

echo ""
echo "... extracting pieces of $object object ..."
nawk -f $nawkFile $V object=$object $V temp=$tempFile1 $V catfile=$tempcatFile  $mailFile 
if ($status) then
    echo "Problems .... aborting."
    goto errorExit
endif
rm -f ${tempFile1}* $nawkFile

echo ""
echo "... finished extraction, starting uudecode ..."
set tempuncompressFile=`head -100 $tempcatFile | grep begin | sed 's/.* .* //'`
set saveDir=`pwd`
chdir /tmp
touch $tempcatFile
chmod -f 777 $tempcatFile
uudecode $tempcatFile
if ($status) then
    echo "Problems .... aborting."
    goto errorExit
endif
rm -f $tempcatFile
chmod 777 $tempuncompressFile
mv $tempuncompressFile ${tempuncompressFile}.Z

echo ""
echo "... finished uudecode, starting uncompress ..."
uncompress `basename ${tempuncompressFile}.Z`
mv $tempuncompressFile $saveDir
chdir $saveDir

echo ""
echo "... finished uncompress, starting tar extraction ..."
tar -xvf `basename $tempuncompressFile`

exit(0)
interrupted:
echo "**** interrupted ****"
errorExit:
/bin/rm -f ${tempFile1}* $tempcatFile $nawkFile $tempuncompressFile
exit(1)
#----------------- end cut here for mailjoin routine ---------------------------
MAILJOIN!END

case $RA in               # hacked from usenet commentary; will
  all) ;;                 # be replaced by an awk script RSN
  *  )
    SIFS="$IFS"
    IFS=","
    for i in $RA ; do
      R=$R" "$i
    done
    RA=$R
    IFS=$SIFS
    R=""
    for tok in $RA ; do
      case $tok in 
      *-*)
        SIFS="$IFS"
        IFS='-'
        set $tok
        IFS="$SIFS"
        i=$1
        max=${2:-99}
        while $TEST $i -le $max ; do
          R=$R" "$i
          i=`expr $i + 1`    # only exec in the entire parse
        done ;;
      *) R=$R" "$tok ;;
      esac
      RA=$R
    done ;;
esac

case $DB in
  5|6|7|8|9) echo "...beginning tar and compress..." ;;
esac
set $FL ; shift
for i in $* ; do
  if $TEST -s $i ; then       # Test existence of each file to send
    FC=`expr $FC + 1`         # Increment file counter
  fi
done
if $TEST $FC -gt 0 ; then     # Is there something to send?
  case $DB in                 # Yup. continue
    1|2|3|4) 
      case $TM in
        true )
          echo "would have issued command:"
          echo "$TA cvf - $* 2> /dev/null | $CO $CF >$T1" ;;
        false)  $TA cvf - $* 2> /dev/null | $CO $CF  >$T1 ;;
        *    ) echo "Sigh... Programmer error in $ME at line 93." ;;
      esac ;;
    *) 
      case $TM in
       true )
         echo "would have issued command:"
         echo "$TA cvf - $* | $CO $CF >$T1" ;;
       false) $TA cvf - $* | $CO $CF >$T1 ;;
       *    ) echo "Sigh... Programmer error in $ME at line 153." ;;
      esac ;;
  esac
else                          # Nope, nothing to send
  case $DB in
    [5-9] ) echo "...whoops!  Nothing to send!  Punting..." 1>&2 ;;
  esac
  exit 1
fi
case $DB in
  5|6|7|8|9) echo "...finished tar, compress, starting uuencode..."
esac
case $TM in
  true )
    echo "would have issued command:"
    echo "$UU $T1 $T1 > $T2 " ;;
  false) $UU $T1 $T1 > $T2 ; ;;
  *    ) echo "Sigh... Programmer error in $ME at line 170." ;;
esac
case $DB in
  5|6|7|8|9) echo "...finished uuencode, starting split..." ;;
esac
case $TM in 
  true )
    echo "would have issued command:" 
    echo "$SPLIT -$LI $T2 $T3" ;; 
  false)  $SPLIT -$LI $T2 $T3 ; ;; 
  *    ) echo "Sigh... Programmer error in $ME at line 128." ;;
esac 
case $TM in
  true )
    echo "would have issued commands:"
    echo "$MA -s "$SU - part n of m" $TO" 
    echo "with n ranging from 1 to m; m cannot be determined."
    echo "without running for real."
    exit 0 ;;
esac 

n=1
set $T3*
for f  do
  SE=false
  case $RA in
    all)  SE=true ;;
    *  )
      for p in $RA ; do
        case $p in
          $n ) SE=true ;;
        esac
      done ;;
  esac
  case $SE in
    true)
    {
    echo " "
    case $n in
    1)
      if $TEST ! -s $f ; then
        case $DB in 
          [5-9]) echo "...whoops!  $SPLIT failed!   Punting..." 1>&2 ;;
        esac 
        exit 1 ;
      fi
      case $IJ in
        true) cat $T4 ;;
      esac
      echo " " ;;
    esac
    echo " "
    echo "This file was packed by mailsplit version:"
    echo $VE
    echo with command:
    echo "$CM"
    echo "on: `date`"
    echo " "
    echo "--- start of $SU part $n of $#"
    $CAT $f
    echo "--- end of $SU part $n of $#"
    echo " "
    echo " "
    } | 
    case $MS in
      Subj)  $MA $MF -s "$SU - part $n of $#" $TO ;;
      *)     $MA $MF $TO ;;
    esac
    case $DB in
      [5-9])   echo "...sent part $n of $# to $MA..." ;;
    esac
    case $DB in
      5|6|7|8|9) echo "...sleeping $DE seconds (waiting for mailer) ..." ;;
    esac
    $SLEEP $DE ;;
  esac
  n=`expr $n + 1`
done
$RM -f $T1 $T2 $T3* $T4
Newsgroups: fj.mail-lists.apollo