BSD 4_3 development
[unix-history] / usr / contrib / rn / Rnmail.SH
CommitLineData
6048dd29
C
1case $CONFIG in
2 '') . config.sh ;;
3esac
4echo "Extracting Rnmail (with variable substitutions)"
5$spitshell >Rnmail <<!GROK!THIS!
6$startsh
7# $Header: Rnmail.SH,v 4.3.1.4 85/08/01 14:23:05 lwall Exp $
8#
9# $Log: Rnmail.SH,v $
10# Revision 4.3.1.4 85/08/01 14:23:05 lwall
11# Added MAILRECORD. Temp file is no longer in /tmp. 'e editor' added.
12#
13# Revision 4.3.1.3 85/05/20 16:25:17 lwall
14# Shouldn't ask editor if EDITOR or VISUAL defined.
15#
16# Revision 4.3.1.2 85/05/17 10:36:19 lwall
17# Added "-- " before .signature.
18#
19# Revision 4.3.1.1 85/05/10 11:30:38 lwall
20# Branch for patches.
21#
22# Revision 4.3 85/05/01 11:34:18 lwall
23# Baseline for release with 4.3bsd.
24#
25#
26# syntax: Rnmail -h headerfile [oldart] or
27# Rnmail destination-list or just
28# Rnmail
29
30export PATH || (echo "OOPS, this isn't sh. Desperation time. I will feed myself to sh."; sh \$0; kill \$\$)
31
32# System dependencies
33
34mailer="${mailer-/bin/mail}"
35# if you change this to something that does signatures, take out signature code
36
37# your site name
38case $portable in
39define) sitename=\`$hostcmd\` ;;
40undef) sitename="$sitename" ;;
41esac
42# your organization name
43orgname="$orgname"
44# what pager you use--if you have kernal paging use cat
45pager="\${PAGER-$pager}"
46# how you derive full names, bsd, usg, or other
47nametype="$nametype"
48# default editor
49defeditor="$defeditor"
50# how not to do a newline with echo
51n="$n"
52c="$c"
53
54test=${test-test}
55sed=${sed-sed}
56echo=${echo-echo}
57cat=${cat-cat}
58grep=${grep-grep}
59rm=${rm-rm}
60
61!GROK!THIS!
62$spitshell >>Rnmail <<'!NO!SUBS!'
63dotdir=${DOTDIR-${HOME-$LOGDIR}}
64tmpart=$dotdir/.letter
65
66headerfile=""
67case $# in
680) ;;
69*) case $1 in
70 -h)
71 headerfile="$2"
72 case $# in
73 3) oldart=$3 ;;
74 esac
75 ;;
76 esac
77 ;;
78esac
79
80case $headerfile in
81'')
82 case $# in
83 0)
84 to=h
85 while $test "$to" = h ; do
86 $echo ""
87 $echo $n "To: $c"
88 read to
89 case $to in
90 h)
91 $cat <<'EOH'
92
93Type the net address of those people that you wish the message sent to.
94Additional recipients may be added on the Cc: line when you edit.
95
96Separate multiple addresses with spaces.
97
98EOH
99 ;;
100 esac
101 done
102 ;;
103 *)
104 to="$*"
105 ;;
106 esac
107 to=`$echo "$to" | $sed 's/ */ /g'`
108
109 title=h
110 while $test "$title" = h ; do
111 $echo ""
112 $echo $n "Title/Subject: $c"
113 read title
114 case $title in
115 h)
116 $cat <<'EOH'
117
118Type the title for your message.
119EOH
120 ;;
121 esac
122 done
123
124# now build a file with a header for them to edit
125
126 orgname=${ORGANIZATION-$orgname}
127 case $orgname in
128 /*) orgname=`$cat $orgname` ;;
129 esac
130
131 $cat > $tmpart <<EOHeader
132To: $to
133Subject: $title
134Organization: $orgname
135Cc:
136Bcc:
137
138EOHeader
139
140 ;;
141*)
142 $cat < $headerfile > $tmpart
143 ;;
144esac
145
146
147file=h
148while $test "$file" = h ; do
149 $echo ""
150 $echo $n "Prepared file to include [none]: $c"
151 read file
152 case $file in
153 h)
154 $cat <<'EOH'
155
156If you have already produced the body of your message, type the filename
157for it here. If you just want to proceed directly to the editor, type a
158RETURN. In any event, you will be allowed to edit as many times as you
159want before you send off the message.
160EOH
161 ;;
162 '')
163 $echo "" >> $tmpart
164 state=edit
165 ;;
166 *)
167 $cat $file >>$tmpart
168 state=ask
169 ;;
170 esac
171done
172
173$echo ""
174
175while true ; do
176 case $state in
177 edit)
178 rescue="sleep 1; $cat $tmpart >>${HOME-$LOGDIR}/dead.letter ; $echo Message appended to ${HOME-$LOGDIR}/dead.letter ; exit"
179 trap "$rescue" 1
180 trap : 2
181 case "${VISUAL-${EDITOR-}}" in
182 '')
183 tmp=h
184 ;;
185 *)
186 tmp=''
187 ;;
188 esac
189 while $test "$tmp" = h ; do
190 $echo $n "Editor [${VISUAL-${EDITOR-$defeditor}}]: $c"
191 read tmp
192 case $tmp in
193 h)
194 $cat <<'EOH'
195
196Type a return to get the default editor, or type the name of the editor you
197prefer. The default editor depends on the VISUAL and EDITOR environment
198variables.
199
200EOH
201 ;;
202 '')
203 ;;
204 *)
205 VISUAL=$tmp
206 export VISUAL
207 ;;
208 esac
209 done
210 ${VISUAL-${EDITOR-$defeditor}} $tmpart $oldart
211 trap "$rescue" 2
212 state=ask
213 ;;
214
215 ask)
216 $echo ""
217 $echo $n "Send, abort, edit, or list? $c"
218 read ans
219
220 case $ans in
221 a*)
222 state=rescue
223 ;;
224 e*)
225 set $ans
226 case $# in
227 2) VISUAL="$2" ;;
228 esac
229 state=edit
230 ;;
231 l*)
232 $pager $tmpart
233 state=ask
234 ;;
235 s*)
236 state=send
237 ;;
238 h*)
239 $cat <<'EOH'
240
241Type s to send the message, a to abort and append the message to dead.letter,
242e to edit the message again, or l to list the message.
243
244To invoke an alternate editor, type 'e editor'.
245EOH
246 esac
247 ;;
248
249 send)
250 if $test -f $dotdir/.signature; then
251 echo $n "Append .signature file? [y] $c"
252 read ans
253 case $ans in
254 ''|y*)
255 echo "-- " >> $tmpart
256 cat $dotdir/.signature >> $tmpart
257 ;;
258 esac
259 fi
260 case $mailer in
261 *sendmail)
262 $mailer -t <$tmpart
263 ;;
264# but recmail does not know about Bcc, alas
265 *recmail)
266 $mailer <$tmpart
267 ;;
268 *)
269 set X `$sed <$tmpart -n -e '/^To:/{' -e 's/To: *//p' -e q -e '}'`
270 shift
271 set X "$@" `$sed <$tmpart -n -e '/^Cc:/{' -e 's/Cc: *//p' -e q -e '}'`
272 shift
273 set X "$@" `$sed <$tmpart -n -e '/^Bcc:/{' -e 's/Bcc: *//p' -e q -e '}'`
274 shift
275 $grep -v "^Bcc:" <$tmpart | $mailer "$@"
276 ;;
277 esac
278 case $? in
279 0)
280 state=cleanup
281 ;;
282 *)
283 state=rescue
284 ;;
285 esac
286 ;;
287 rescue)
288 $cat $tmpart >> ${HOME-$LOGDIR}/dead.letter
289 $echo "Message appended to ${HOME-$LOGDIR}/dead.letter"
290 $echo "A copy may be temporarily found in $tmpart"
291 exit
292 ;;
293 cleanup)
294 case "${MAILRECORD-none}" in
295 none)
296 ;;
297 *) if $cat $tmpart >> $MAILRECORD; then
298 $echo "Article appended to $MAILRECORD"
299 else
300 $echo "Cannot append to $MAILRECORD"
301 fi
302 ;;
303 esac
304 exit
305 ;;
306 esac
307done
308!NO!SUBS!
309$eunicefix Rnmail
310chmod 755 Rnmail