home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Connectivity / PPP / Docs / NeXTPPP_HTML / scripts / next-mail < prev    next >
Encoding:
Text File  |  1997-09-18  |  5.1 KB  |  218 lines

  1. #!/bin/sh
  2. #
  3. # E-mail files and folders from the command line or a non-NeXT computer.
  4. #
  5. # File description and history are at the end of this script (for speed).
  6. #
  7. PROG="`basename $0`"
  8. PATH=/usr/local/bin:/usr/ucb:/usr/bin:/bin
  9. export PATH
  10.  
  11. AWK=awk
  12. CAT=cat
  13. MAIL="/usr/ucb/Mail"
  14. TAR="tar chf -"
  15. UUENCODE=uuencode
  16.  
  17. TMPDIR=/tmp/${PROG}$$.dir
  18. TARFILE=${PROG}$$
  19. ATTACH=${TMPDIR}/${TARFILE}.attach
  20. INDEX=${TMPDIR}/index.rtf
  21. TMPFILE=/tmp/${PROG}$$
  22. USAGE="${PROG} [-] [-s subject] [-f from] [-bulk] [-rt] [-RR] {files|folders|folders/files} [recipients...]"
  23. PROMPT="echo -n"
  24. VERBOSE=
  25. RR="Received: by NeXT Mailer (1.63)"
  26. SUBJECT="[NeXT-MAIL]"
  27.  
  28. #
  29. # Destroy temporary files and folders.
  30. #
  31. trap "/bin/rm -rf ${TMPDIR} ${TMPFILE} ; exit" 0 1 2 3 4 5 6 13 15
  32.  
  33. #
  34. # Create temporary directory to work in.
  35. #
  36. mkdir ${TMPDIR}
  37.  
  38. #
  39. # Cycle through command-line arguments.
  40. #
  41. while test $# != 0 ; do
  42.   case "$1" in
  43.     - ) # Take a message.
  44.       echo "${PROG}: Enter mail message, terminated with single '.':"
  45.       while test 1 = 1 ; do
  46.     ${PROMPT} "> "
  47.         read INPUT
  48.     if test "${INPUT}" = '.' ; then
  49.       break
  50.     fi
  51.         MAILMESSAGE="${MAILMESSAGE}${INPUT} "
  52.       done
  53.       ;;
  54.     -s ) # set subject:
  55.         OVERRIDE_SUBJECT="$2"
  56.         shift
  57.        ;;
  58.     -f ) # Set From: address.
  59.       FROM=-f${2:-`whoami`}
  60.       shift
  61.       ;;
  62.     -v ) # set verbose mail output.
  63.        VERBOSE=-v
  64.        ;;
  65.     -bulk | -BULK ) # Set Precedence:
  66.       BULK=YES
  67.       ;;
  68.     -r | -rt | -RT ) # set reply-to:
  69.       REPLYTO="$2"
  70.       shift
  71.       ;;
  72.     -R | -RR | -rr ) # set read-receipt
  73.      RR="Received: by NeXT Mailer (1.63.RR)"
  74.        ;;
  75.     -* ) # Unknown argument.
  76.       echo "${PROG}: Unknown argument $1."
  77.       ;;
  78.     /* | ./* | ../* ) # Can't handle full or relative pathnames.
  79.     ln -s $1 ${TMPDIR}/`basename $1`
  80.     TARGET1="${TARGET1} `basename $1`"
  81.       ;;
  82.     *.rtf ) # RTF files.
  83.       if test -r "$1" ; then
  84.     RTF="${RTF} $1"
  85.       fi
  86.       ;;
  87.     * )    # File or addressee.
  88.       if test -r "$1" ; then
  89. #    ln -s $1 ${TMPDIR}/`basename $1`
  90.     TARGET="${TARGET} $1"
  91.     SUBJECT="${SUBJECT} $1"
  92.       else
  93.     ADDRESSEE="${ADDRESSEE} $1"
  94.       fi
  95.       ;;
  96.   esac
  97.   shift
  98. done
  99.  
  100. if test -n "${OVERRIDE_SUBJECT}" ; then
  101.   SUBJECT="${OVERRIDE_SUBJECT}"
  102. fi
  103. #
  104. # Quit if no addressee specified on command line.
  105. #
  106. if test -z "${ADDRESSEE}" ; then
  107.   echo "${PROG}: No recipient." >&2
  108.   echo "${USAGE}" >&2
  109.   exit 1  
  110. fi
  111.  
  112.  
  113. #
  114. # Create index.rtf file that includes MAILMESSAGE text.
  115. #
  116.  
  117. if test -z "${RTF}" ; then
  118.   cat << EOF >> ${INDEX}
  119. {\rtf0\ansi{\fonttbl\f0\fswiss Helvetica;}
  120. \margl120
  121. \margr120
  122. \pard\tx533\tx1067\tx1601\tx2135\tx2668\tx3202\tx3736\tx4270\tx4803\tx5337\f0\b0\i0\ul0\fs24
  123. ${MAILMESSAGE}
  124. EOF
  125. else
  126.   echo -n '' > ${INDEX}
  127.   for x in ${RTF} ; do
  128.     cat $x >> ${INDEX}
  129.   done
  130. fi
  131.  
  132. #
  133. # Cycle through TARGET list and append attachment lines to index.rtf file.
  134. #
  135. for x in ${TARGET} ${TARGET1}; do
  136.   case $x in
  137.     * )
  138.       echo "{{\attachment0 $x" >> ${INDEX}
  139.       echo "}" >> ${INDEX}
  140.     ;;
  141.   esac
  142. done
  143.  
  144. echo "" >> ${INDEX}
  145.  
  146. #
  147. # Print an informative status message on stderr.
  148. #
  149. echo ${PROG}: Bundling ${TARGET:-message} for shipment via NeXTmail to ${ADDRESSEE}. >&2
  150.  
  151. #
  152. # Create a tar'ed | compressed .attach file.
  153. #
  154. ${TAR} ${TARGET} -C ${TMPDIR} index.rtf ${TARGET1} | compress > ${ATTACH}
  155.  
  156. #
  157. # Go into the temporary folder.
  158. #
  159. cd ${TMPDIR}
  160.  
  161. #
  162. # Uuencode .attach file and give it a .tar.nnnn. prefix.
  163. #
  164. ${UUENCODE} ${ATTACH} .tar.$$.${TARFILE} > ${TMPFILE}
  165.  
  166. #
  167. # Add the Next-Attachment keyword.
  168. #
  169.  
  170. echo "Next-Attachment: .tar.$$.${TARFILE}, `wc -c ${ATTACH} | ${AWK} '{print $1}'`, 1/1, 9999, 0" > ${ATTACH}
  171. echo "${RR}" >> ${ATTACH}
  172. echo "Subject: ${SUBJECT}" >> ${ATTACH}
  173. if test -n "${REPLYTO}" ; then
  174.   echo "Reply-to: ${REPLYTO}" >> ${ATTACH}
  175. fi
  176. if test -n "${BULK}" ; then
  177.   echo "Precedence: bulk" >> ${ATTACH}
  178. fi
  179. echo "" >> ${ATTACH}
  180.  
  181. #
  182. # Append the uuencoded file.
  183. #
  184. ${CAT} ${TMPFILE} >> ${ATTACH}
  185.  
  186. #
  187. # Deliver the mail via e-mail.
  188. #
  189. # ${MAIL} ${VERBOSE} -s "${SUBJECT}" ${ADDRESSEE} < ${ATTACH}
  190. cat ${ATTACH} | /usr/lib/sendmail ${VERBOSE} -odb -oi ${FROM} ${ADDRESSEE}
  191.  
  192. exit $?
  193.  
  194. # $Header: /Net/friday/Users/Source/Next/RCS/next-mail,v 1.7 1993/08/22 19:23:56 treed Exp $
  195. # Locker: $Locker:  $
  196. # Author and Modification Date: $Author: treed $ $Date: 1993/08/22 19:23:56 $
  197. # File name and Description: 
  198. # Send NeXTmail(tm) from the command line.  This script can be used from a Next or
  199. # non-Next computer.  You may specify files and folders to send and recipients
  200. # to receive the e-mail; if the thing on the command line is not a folder or file,
  201. # then next-mail assumes that it is a recipient.  You may also specify a '-' and
  202. # type accompanying e-mail text when prompted.
  203. #
  204. # Feel free to distribute this script, just don't charge money for it.
  205. # Timothy Reed <treed@gun.com>
  206. #
  207. # Copyright (c) 1991 Timothy Reed.  All rights reserved.
  208. # WARNING: You may use and distribute this software, but you use it at your own risk.
  209. #
  210. # This program is free software; you can redistribute it and/or modify it under the
  211. # terms of the GNU General Public License as published by the Free Software Foundation.
  212. # This software comes with ABSOLUTELY NO WARRANTY.
  213. #
  214. # Stephen Perkins - 4/13/96 
  215. #    Modified to accept relative and absolute pathnames
  216. #
  217.