home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / unix / armlinux / alpha / PARTITIONS / USR_GZ / usr / bin / Rnmail < prev    next >
Encoding:
Text File  |  1995-05-14  |  6.0 KB  |  316 lines

  1. #!/bin/sh
  2. # $Id: Rnmail.SH,v 3.0 1992/02/23 21:25:39 davison Trn $
  3. # This software is Copyright 1991 by Stan Barber. 
  4. #
  5. # Permission is hereby granted to copy, reproduce, redistribute or otherwise
  6. # use this software as long as: there is no monetary profit gained
  7. # specifically from the use or reproduction of this software, it is not
  8. # sold, rented, traded or otherwise marketed, and this copyright notice is
  9. # included prominently in any copy made. 
  10. #
  11. # The author make no claims as to the fitness or correctness of this software
  12. # for any use whatsoever, and it is provided as is. Any use of this software
  13. # is at the user's own risk. 
  14. #
  15. #
  16. # syntax: Rnmail -h headerfile [oldart]        or
  17. #         Rnmail destination-list         or just
  18. #         Rnmail
  19.  
  20. export PATH || (echo "OOPS, this isn't sh.  Desperation time.  I will feed myself to sh."; sh $0; kill $$)
  21.  
  22. # System dependencies
  23.  
  24. mailer="${RNMAILER-/usr/sbin/sendmail}"
  25. # if you change this to something that does signatures, take out signature code
  26.  
  27. # your organization name
  28. orgname="/etc/origanization"
  29. # what pager you use--if you have kernal paging use cat
  30. pager="${PAGER-/bin/more}"
  31. # how you derive full names, bsd, usg, or other
  32. nametype="bsd"
  33. # default editor
  34. defeditor="/usr/bin/ue"
  35. # where the non-publics are
  36. case undef in
  37. define)  rnlib=`/usr/lib/trn/filexp /usr/lib/trn` ;;
  38. undef)   rnlib="/usr/lib/trn" ;;
  39. esac
  40. # how not to do a newline with echo
  41. n=""
  42. c="\c"
  43.  
  44. test=test
  45. sed=/usr/bin/sed
  46. echo=/bin/echo
  47. cat=/bin/cat
  48. grep=/usr/bin/grep
  49. rm=/bin/rm
  50. sleep=/usr/bin/sleep
  51. who=
  52.  
  53. orgname=${NEWSORG-${ORGANIZATION-$orgname}}
  54. dotdir=${DOTDIR-${HOME-$LOGDIR}}
  55. tmpart=$dotdir/.letter
  56. speller=$rnlib/Speller
  57. mail_sig=${MAILSIGNATURE-$dotdir/.mail_sig}
  58.  
  59. headerfile=""
  60. case $# in
  61. 0) ;;
  62. *)  case $1 in
  63.     -h)
  64.     headerfile="$2"
  65.     case $# in
  66.     3) oldart=$3 ;;
  67.     esac
  68.     ;;
  69.     esac
  70.     ;;
  71. esac
  72.  
  73. case $headerfile in
  74. '')
  75.     case $# in
  76.     0)
  77.     to=h
  78.     while $test "X$to" = Xh ; do
  79.         $echo ""
  80.         $echo $n "To: $c"
  81.         read to
  82.         case $to in
  83.         h)
  84.         $cat <<'EOH'
  85.  
  86. Type the net address of those people to whom you wish the message sent.
  87. Additional recipients may be added on the Cc: line when you edit.
  88.  
  89. Separate multiple addresses with spaces.
  90.  
  91. EOH
  92.         ;;
  93.         esac
  94.     done
  95.     ;;
  96.     *)
  97.     to="$*"
  98.     ;;
  99.     esac
  100.     to=`$echo "$to" | $sed 's/  */ /g'`
  101.  
  102.     title=h
  103.     while $test "X$title" = Xh ; do
  104.     $echo ""
  105.     $echo $n "Title/Subject: $c"
  106.     read title
  107.     case $title in
  108.     h)
  109.         $cat <<'EOH'
  110.  
  111. Type the title for your message.  
  112. EOH
  113.         ;;
  114.     esac
  115.     done
  116.  
  117. # now build a file with a header for them to edit
  118.     
  119.     case $orgname in
  120.     /*) orgname=`$cat $orgname` ;;
  121.     esac
  122.  
  123.     $sed -e '/^Reply-To: $/d' > $tmpart <<EOHeader
  124. To: $to
  125. Subject: $title
  126. Organization: $orgname
  127. Reply-To: $REPLYTO
  128. Cc:
  129. Bcc:
  130.  
  131. EOHeader
  132.  
  133.     ;;
  134. *)
  135.     $cat < $headerfile  > $tmpart
  136.     ;;
  137. esac
  138.  
  139.  
  140. file=h
  141. while $test X$file = Xh ; do
  142.     $echo ""
  143.     $echo $n "Prepared file to include [none]: $c"
  144.     read file
  145.     case $file in
  146.     h)
  147.     $cat <<'EOH'
  148.  
  149. If you have already produced the body of your message, type the filename
  150. for it here.  If you just want to proceed directly to the editor, type a
  151. RETURN.  In any event, you will be allowed to edit as many times as you
  152. want before you send off the message.
  153. EOH
  154.     ;;
  155.     '')
  156.     $echo "" >> $tmpart
  157.     state=edit
  158.     ;;
  159.     *)
  160.     $cat $file >>$tmpart
  161.     state=ask
  162.     ;;
  163.     esac
  164. done
  165.  
  166. $echo ""
  167.  
  168. if $test -r $mail_sig; then
  169.     $echo "-- " >> $tmpart
  170.     $cat $mail_sig >> $tmpart
  171. fi
  172.  
  173. while : ; do
  174.     case $state in
  175.     edit)
  176.     rescue="$sleep 1; $cat $tmpart >>${HOME-$LOGDIR}/dead.letter ; $echo Message appended to ${HOME-$LOGDIR}/dead.letter ; exit"
  177.     trap "$rescue" 1
  178.     trap : 2
  179.     case "${VISUAL-${EDITOR-}}" in
  180.     '')
  181.         tmp=h
  182.         ;;
  183.     *)
  184.         tmp=''
  185.         ;;
  186.     esac
  187.     while $test "X$tmp" = Xh ; do
  188.         $echo $n "Editor [${VISUAL-${EDITOR-$defeditor}}]: $c"
  189.         read tmp
  190.         case $tmp in
  191.         h)
  192.         $cat <<'EOH'
  193.  
  194. Type a return to get the default editor, or type the name of the editor you
  195. prefer.  The default editor depends on the VISUAL and EDITOR environment
  196. variables.
  197.  
  198. EOH
  199.         ;;
  200.         '')
  201.         ;;
  202.         *)
  203.         VISUAL=$tmp
  204.         export VISUAL
  205.         ;;
  206.         esac
  207.     done
  208.     ${VISUAL-${EDITOR-$defeditor}} $tmpart $oldart
  209.     trap "$rescue" 2
  210.     state=ask
  211.     ;;
  212.     
  213.     ask)
  214.     $echo ""
  215.     $echo $n "Check spelling, Send, Abort, Edit, or List? $c"
  216.     read ans
  217.  
  218.     case $ans in
  219.     [aA]*)
  220.         state=rescue
  221.         ;;
  222.     [eE]*)
  223.         set $ans
  224.         case $# in
  225.         2)  VISUAL="$2" ;;
  226.         esac
  227.         state=edit
  228.         ;;
  229.     [lL]*)
  230.         $pager $tmpart
  231.         state=ask
  232.         ;;
  233.     [cC]*|[sS][pP]*)
  234.         $speller $tmpart
  235.         state=ask
  236.         ;;
  237.     [sS]*)
  238.         state=send
  239.         ;;
  240.     [hH]*)
  241.         $cat <<'EOH'
  242.  
  243. Type c to check the message's spelling, s to send the message, a to abort
  244. and append the message to dead.letter, e to edit the message again, or l
  245. to list the message with your pager.
  246.  
  247. To invoke an alternate editor, type 'e editor'.
  248. EOH
  249.     esac
  250.     ;;
  251.     
  252.     send)
  253.     if $test -f $dotdir/.signature; then
  254.         $echo $n "Append .signature file? [y] $c"
  255.         read ans
  256.         case $ans in
  257.         ''|y*)
  258.         $echo "-- " >> $tmpart
  259.         cat $dotdir/.signature >> $tmpart
  260.         ;;
  261.         esac
  262.     fi
  263.     case $mailer in
  264.     *sendmail)
  265.         $mailer -t <$tmpart
  266.         ;;
  267. # but recmail does not know about Bcc, alas
  268.     *recmail)
  269.         $mailer <$tmpart
  270.         ;;
  271.     *)
  272.         set X `$sed <$tmpart -n -e '/^To:/{' -e 's/To: *//p' -e q -e '}'`
  273.         shift
  274.         set X "$@" `$sed <$tmpart -n -e '/^Cc:/{' -e 's/Cc: *//p' -e q -e '}'`
  275.         shift
  276.         set X "$@" `$sed <$tmpart -n -e '/^Bcc:/{' -e 's/Bcc: *//p' -e q -e '}'`
  277.         shift
  278.         $grep -v "^Bcc:"  <$tmpart | $mailer "$@"
  279.         ;;
  280.     esac
  281.     case $? in
  282.     0)
  283.         state=cleanup
  284.         ;;
  285.     *)
  286.         state=rescue
  287.         ;;
  288.     esac
  289.     ;;
  290.     rescue)
  291.     $cat $tmpart >> ${HOME-$LOGDIR}/dead.letter
  292.     $echo "Message appended to ${HOME-$LOGDIR}/dead.letter"
  293.     $echo "A copy may be temporarily found in $tmpart"
  294.     exit
  295.     ;;
  296.     cleanup)
  297.     case "${MAILRECORD-none}" in
  298.     none)
  299.         ;;
  300.     *)
  301.         set X ${USER-${LOGNAME-`$who am i`}} unknown
  302.         shift
  303.         $rnlib/mbox.saver $tmpart "." "." 0 0 Pnews $MAILRECORD "From $1 `LANG= date`"
  304.         if $test $? -eq 0 ; then
  305.         $echo "Message appended to $MAILRECORD"
  306.         else
  307.         $echo "Cannot append to $MAILRECORD"
  308.         fi
  309.         ;;
  310.     esac
  311.     exit
  312.     ;;
  313.     esac
  314. done
  315.