home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / newsgate / part03 / mail-interface < prev    next >
Text File  |  1991-10-09  |  3KB  |  173 lines

  1. #! /bin/sh
  2. ##  A portable mail interface program.  Original by Piete Brooks,
  3. ##  modified by Rich $alz <rsalz@bbn.com>
  4.  
  5. mailer="${mailer-/usr/lib/sendmail}"
  6. headers=false
  7.  
  8. ##  Decode the arguments.
  9. while test $# -gt 0 ; do
  10.     arg="$1"
  11.     shift
  12.     case "$arg" in
  13.     -A|-ASIS)
  14.     asis=true
  15.     ;;
  16.     -b|-body)
  17.     body="$body
  18. $1"
  19.     shift
  20.     ;;
  21.     -c|-cc)
  22.     cc="$cc, $1"
  23.     shift
  24.     headers=true
  25.     ;;
  26.     -f|-from)
  27.     from="$1"
  28.     shift
  29.     headers=true
  30.     ;;
  31.     -h|-help)
  32.     cat <<EOF
  33. Usage: $0 [flags] [recipients...]
  34.     -A -ASIS    Send text ASIS, i.e. headers are present in the input
  35.     -b -body    String which is to be the body of the message
  36.     -c -cc        Carbon Copy recipients
  37.     -f -from    From field
  38.     -h -help    This message
  39.     -r -recip    Recipient (passed on command line)
  40.     -s -subject    Set the subject field
  41.     -t -to        Main recipients
  42.     -*        ERROR
  43.     *        treat as recipients
  44. EOF
  45.     exit 1
  46.     ;;
  47.     -r|-recip)
  48.     recip="$recip $1"
  49.     shift
  50.     ;;
  51.     -s|-subject)
  52.     subject="$subject, $1"
  53.     shift
  54.     headers=true
  55.     ;;
  56.     -t|-to)
  57.     to="$to, $1"
  58.     shift
  59.     headers=true
  60.     ;;
  61.     -*)
  62.     echo $0: invalid argument \""$arg"\"
  63.     exit 1
  64.     ;;
  65.     *)
  66.     to="$to, $arg"
  67.     ;;
  68.     esac
  69. done
  70.  
  71. ##  If no recipients, send to postmaster.
  72. case "$to$cc$recip" in
  73. '')
  74.     recip=postmaster
  75.     ;;
  76. esac
  77.  
  78. ##  If we got no headers on the command line, read them from the message.
  79. case $headers in
  80. false)
  81.     asis=true
  82.     ;;
  83. esac
  84.  
  85. ##  Strip off the spurious leading ", " in repeatable items
  86. case "$to" in
  87. ', '*)
  88.     to=`expr "$to" : ", \(.*\)`
  89.     ;;
  90. esac
  91. case "$cc"  in
  92. ', '*)
  93.     cc=`expr "$cc" : ", \(.*\)`
  94.     ;;
  95. esac
  96. case "$subject"    in ', '*)
  97.     subject=`expr "$subject" : ", \(.*\)`
  98.     ;;
  99. esac
  100.  
  101. ##  Now do the business.
  102. case "$mailer" in
  103. */sendmail|sendmail|*/sendmail' '*|sendmail' '*)
  104.     args="-oi"
  105.     if [ -z "$recip" ] ; then
  106.     args="$args -t"
  107.     fi
  108.     (
  109.     if [ ! -z "$subject" ] ; then
  110.         echo "Subject: $subject"
  111.     fi
  112.     if [ ! -z "$from" ] ; then
  113.         echo "From: $from"
  114.     fi
  115.     if [ ! -z "$to" ] ; then
  116.         echo "To: $to"
  117.     fi
  118.     if [ ! -z "$cc" ] ; then
  119.         echo "Cc: $cc"
  120.     fi
  121.     if [ -z "$asis" ] ; then
  122.         echo ""
  123.     fi
  124.     if [ -z "$body" ] ; then
  125.         cat
  126.     else
  127.         echo "$body" | sed 1d
  128.     fi
  129.     ) | $debug $mailer $args $recip
  130.     ;;
  131.  
  132. */submit|submit|*/submit' '*|submit' '*)
  133.     args="-tsz"
  134.     case "$recip" in
  135.     if [ -z "$recip" ] ; then
  136.     if [ ! -z "$to" ] ; then
  137.         args="${args}gto*"
  138.     fi
  139.     if [ ! -z "$cc" ] ; then
  140.         args="${args}gcc*"
  141.     fi
  142.     fi
  143.     (
  144.     if [ ! -z "$subject" ] ; then
  145.         echo "Subject: $subject"
  146.     fi
  147.     if [ ! -z "$from" ] ; then
  148.         echo "From: $from"
  149.     fi
  150.     if [ ! -z "$to" ] ; then
  151.         echo "To: $to"
  152.     fi
  153.     if [ ! -z "$cc" ] ; then
  154.         echo "Cc: $cc"
  155.     fi
  156.     if [ -z "$asis" ] ; then
  157.         echo ""
  158.     fi
  159.     if [ -z "$body" ] ; then
  160.         cat
  161.     else
  162.         echo "$body" | sed 1d
  163.     fi
  164.     ) | $debug $mailer $args $recip
  165.     ;;
  166.  
  167. *)
  168.     echo Unknown mailer 1>&2
  169.     exit 1
  170.     ;;
  171.  
  172. esac
  173.