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