collect.c revision 1.2 1 1.1 cgd /*
2 1.1 cgd * Copyright (c) 1980 Regents of the University of California.
3 1.1 cgd * All rights reserved.
4 1.1 cgd *
5 1.1 cgd * Redistribution and use in source and binary forms, with or without
6 1.1 cgd * modification, are permitted provided that the following conditions
7 1.1 cgd * are met:
8 1.1 cgd * 1. Redistributions of source code must retain the above copyright
9 1.1 cgd * notice, this list of conditions and the following disclaimer.
10 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
11 1.1 cgd * notice, this list of conditions and the following disclaimer in the
12 1.1 cgd * documentation and/or other materials provided with the distribution.
13 1.1 cgd * 3. All advertising materials mentioning features or use of this software
14 1.1 cgd * must display the following acknowledgement:
15 1.1 cgd * This product includes software developed by the University of
16 1.1 cgd * California, Berkeley and its contributors.
17 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
18 1.1 cgd * may be used to endorse or promote products derived from this software
19 1.1 cgd * without specific prior written permission.
20 1.1 cgd *
21 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 1.1 cgd * SUCH DAMAGE.
32 1.1 cgd */
33 1.1 cgd
34 1.1 cgd #ifndef lint
35 1.2 mycroft /*static char sccsid[] = "from: @(#)collect.c 5.24 (Berkeley) 4/1/91";*/
36 1.2 mycroft static char rcsid[] = "$Id: collect.c,v 1.2 1993/08/01 18:13:09 mycroft Exp $";
37 1.1 cgd #endif /* not lint */
38 1.1 cgd
39 1.1 cgd /*
40 1.1 cgd * Mail -- a mail program
41 1.1 cgd *
42 1.1 cgd * Collect input from standard input, handling
43 1.1 cgd * ~ escapes.
44 1.1 cgd */
45 1.1 cgd
46 1.1 cgd #include "rcv.h"
47 1.1 cgd #include <sys/stat.h>
48 1.1 cgd
49 1.1 cgd /*
50 1.1 cgd * Read a message from standard output and return a read file to it
51 1.1 cgd * or NULL on error.
52 1.1 cgd */
53 1.1 cgd
54 1.1 cgd /*
55 1.1 cgd * The following hokiness with global variables is so that on
56 1.1 cgd * receipt of an interrupt signal, the partial message can be salted
57 1.1 cgd * away on dead.letter.
58 1.1 cgd */
59 1.1 cgd
60 1.1 cgd static sig_t saveint; /* Previous SIGINT value */
61 1.1 cgd static sig_t savehup; /* Previous SIGHUP value */
62 1.1 cgd static sig_t savetstp; /* Previous SIGTSTP value */
63 1.1 cgd static sig_t savettou; /* Previous SIGTTOU value */
64 1.1 cgd static sig_t savettin; /* Previous SIGTTIN value */
65 1.1 cgd static FILE *collf; /* File for saving away */
66 1.1 cgd static int hadintr; /* Have seen one SIGINT so far */
67 1.1 cgd
68 1.1 cgd static jmp_buf colljmp; /* To get back to work */
69 1.1 cgd static int colljmp_p; /* whether to long jump */
70 1.1 cgd static jmp_buf collabort; /* To end collection with error */
71 1.1 cgd
72 1.1 cgd FILE *
73 1.1 cgd collect(hp, printheaders)
74 1.1 cgd struct header *hp;
75 1.1 cgd {
76 1.1 cgd FILE *fbuf;
77 1.1 cgd int lc, cc, escape, eofcount;
78 1.1 cgd register int c, t;
79 1.1 cgd char linebuf[LINESIZE], *cp;
80 1.1 cgd extern char tempMail[];
81 1.1 cgd char getsub;
82 1.1 cgd int omask;
83 1.1 cgd void collint(), collhup(), collstop();
84 1.1 cgd
85 1.1 cgd collf = NULL;
86 1.1 cgd /*
87 1.1 cgd * Start catching signals from here, but we're still die on interrupts
88 1.1 cgd * until we're in the main loop.
89 1.1 cgd */
90 1.1 cgd omask = sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
91 1.1 cgd if ((saveint = signal(SIGINT, SIG_IGN)) != SIG_IGN)
92 1.1 cgd signal(SIGINT, collint);
93 1.1 cgd if ((savehup = signal(SIGHUP, SIG_IGN)) != SIG_IGN)
94 1.1 cgd signal(SIGHUP, collhup);
95 1.1 cgd savetstp = signal(SIGTSTP, collstop);
96 1.1 cgd savettou = signal(SIGTTOU, collstop);
97 1.1 cgd savettin = signal(SIGTTIN, collstop);
98 1.1 cgd if (setjmp(collabort) || setjmp(colljmp)) {
99 1.1 cgd rm(tempMail);
100 1.1 cgd goto err;
101 1.1 cgd }
102 1.1 cgd sigsetmask(omask & ~(sigmask(SIGINT) | sigmask(SIGHUP)));
103 1.1 cgd
104 1.1 cgd noreset++;
105 1.1 cgd if ((collf = Fopen(tempMail, "w+")) == NULL) {
106 1.1 cgd perror(tempMail);
107 1.1 cgd goto err;
108 1.1 cgd }
109 1.1 cgd unlink(tempMail);
110 1.1 cgd
111 1.1 cgd /*
112 1.1 cgd * If we are going to prompt for a subject,
113 1.1 cgd * refrain from printing a newline after
114 1.1 cgd * the headers (since some people mind).
115 1.1 cgd */
116 1.1 cgd t = GTO|GSUBJECT|GCC|GNL;
117 1.1 cgd getsub = 0;
118 1.1 cgd if (hp->h_subject == NOSTR && value("interactive") != NOSTR &&
119 1.1 cgd (value("ask") != NOSTR || value("asksub") != NOSTR))
120 1.1 cgd t &= ~GNL, getsub++;
121 1.1 cgd if (printheaders) {
122 1.1 cgd puthead(hp, stdout, t);
123 1.1 cgd fflush(stdout);
124 1.1 cgd }
125 1.1 cgd if ((cp = value("escape")) != NOSTR)
126 1.1 cgd escape = *cp;
127 1.1 cgd else
128 1.1 cgd escape = ESCAPE;
129 1.1 cgd eofcount = 0;
130 1.1 cgd hadintr = 0;
131 1.1 cgd
132 1.1 cgd if (!setjmp(colljmp)) {
133 1.1 cgd if (getsub)
134 1.1 cgd grabh(hp, GSUBJECT);
135 1.1 cgd } else {
136 1.1 cgd /*
137 1.1 cgd * Come here for printing the after-signal message.
138 1.1 cgd * Duplicate messages won't be printed because
139 1.1 cgd * the write is aborted if we get a SIGTTOU.
140 1.1 cgd */
141 1.1 cgd cont:
142 1.1 cgd if (hadintr) {
143 1.1 cgd fflush(stdout);
144 1.1 cgd fprintf(stderr,
145 1.1 cgd "\n(Interrupt -- one more to kill letter)\n");
146 1.1 cgd } else {
147 1.1 cgd printf("(continue)\n");
148 1.1 cgd fflush(stdout);
149 1.1 cgd }
150 1.1 cgd }
151 1.1 cgd for (;;) {
152 1.1 cgd colljmp_p = 1;
153 1.1 cgd c = readline(stdin, linebuf, LINESIZE);
154 1.1 cgd colljmp_p = 0;
155 1.1 cgd if (c < 0) {
156 1.1 cgd if (value("interactive") != NOSTR &&
157 1.1 cgd value("ignoreeof") != NOSTR && ++eofcount < 25) {
158 1.1 cgd printf("Use \".\" to terminate letter\n");
159 1.1 cgd continue;
160 1.1 cgd }
161 1.1 cgd break;
162 1.1 cgd }
163 1.1 cgd eofcount = 0;
164 1.1 cgd hadintr = 0;
165 1.1 cgd if (linebuf[0] == '.' && linebuf[1] == '\0' &&
166 1.1 cgd value("interactive") != NOSTR &&
167 1.1 cgd (value("dot") != NOSTR || value("ignoreeof") != NOSTR))
168 1.1 cgd break;
169 1.1 cgd if (linebuf[0] != escape || value("interactive") == NOSTR) {
170 1.1 cgd if (putline(collf, linebuf) < 0)
171 1.1 cgd goto err;
172 1.1 cgd continue;
173 1.1 cgd }
174 1.1 cgd c = linebuf[1];
175 1.1 cgd switch (c) {
176 1.1 cgd default:
177 1.1 cgd /*
178 1.1 cgd * On double escape, just send the single one.
179 1.1 cgd * Otherwise, it's an error.
180 1.1 cgd */
181 1.1 cgd if (c == escape) {
182 1.1 cgd if (putline(collf, &linebuf[1]) < 0)
183 1.1 cgd goto err;
184 1.1 cgd else
185 1.1 cgd break;
186 1.1 cgd }
187 1.1 cgd printf("Unknown tilde escape.\n");
188 1.1 cgd break;
189 1.1 cgd case 'C':
190 1.1 cgd /*
191 1.1 cgd * Dump core.
192 1.1 cgd */
193 1.1 cgd core();
194 1.1 cgd break;
195 1.1 cgd case '!':
196 1.1 cgd /*
197 1.1 cgd * Shell escape, send the balance of the
198 1.1 cgd * line to sh -c.
199 1.1 cgd */
200 1.1 cgd shell(&linebuf[2]);
201 1.1 cgd break;
202 1.1 cgd case ':':
203 1.1 cgd /*
204 1.1 cgd * Escape to command mode, but be nice!
205 1.1 cgd */
206 1.1 cgd execute(&linebuf[2], 1);
207 1.1 cgd goto cont;
208 1.1 cgd case '.':
209 1.1 cgd /*
210 1.1 cgd * Simulate end of file on input.
211 1.1 cgd */
212 1.1 cgd goto out;
213 1.1 cgd case 'q':
214 1.1 cgd /*
215 1.1 cgd * Force a quit of sending mail.
216 1.1 cgd * Act like an interrupt happened.
217 1.1 cgd */
218 1.1 cgd hadintr++;
219 1.1 cgd collint(SIGINT);
220 1.1 cgd exit(1);
221 1.1 cgd case 'h':
222 1.1 cgd /*
223 1.1 cgd * Grab a bunch of headers.
224 1.1 cgd */
225 1.1 cgd grabh(hp, GTO|GSUBJECT|GCC|GBCC);
226 1.1 cgd goto cont;
227 1.1 cgd case 't':
228 1.1 cgd /*
229 1.1 cgd * Add to the To list.
230 1.1 cgd */
231 1.1 cgd hp->h_to = cat(hp->h_to, extract(&linebuf[2], GTO));
232 1.1 cgd break;
233 1.1 cgd case 's':
234 1.1 cgd /*
235 1.1 cgd * Set the Subject list.
236 1.1 cgd */
237 1.1 cgd cp = &linebuf[2];
238 1.1 cgd while (isspace(*cp))
239 1.1 cgd cp++;
240 1.1 cgd hp->h_subject = savestr(cp);
241 1.1 cgd break;
242 1.1 cgd case 'c':
243 1.1 cgd /*
244 1.1 cgd * Add to the CC list.
245 1.1 cgd */
246 1.1 cgd hp->h_cc = cat(hp->h_cc, extract(&linebuf[2], GCC));
247 1.1 cgd break;
248 1.1 cgd case 'b':
249 1.1 cgd /*
250 1.1 cgd * Add stuff to blind carbon copies list.
251 1.1 cgd */
252 1.1 cgd hp->h_bcc = cat(hp->h_bcc, extract(&linebuf[2], GBCC));
253 1.1 cgd break;
254 1.1 cgd case 'd':
255 1.1 cgd strcpy(linebuf + 2, getdeadletter());
256 1.1 cgd /* fall into . . . */
257 1.1 cgd case 'r':
258 1.1 cgd /*
259 1.1 cgd * Invoke a file:
260 1.1 cgd * Search for the file name,
261 1.1 cgd * then open it and copy the contents to collf.
262 1.1 cgd */
263 1.1 cgd cp = &linebuf[2];
264 1.1 cgd while (isspace(*cp))
265 1.1 cgd cp++;
266 1.1 cgd if (*cp == '\0') {
267 1.1 cgd printf("Interpolate what file?\n");
268 1.1 cgd break;
269 1.1 cgd }
270 1.1 cgd cp = expand(cp);
271 1.1 cgd if (cp == NOSTR)
272 1.1 cgd break;
273 1.1 cgd if (isdir(cp)) {
274 1.1 cgd printf("%s: Directory\n", cp);
275 1.1 cgd break;
276 1.1 cgd }
277 1.1 cgd if ((fbuf = Fopen(cp, "r")) == NULL) {
278 1.1 cgd perror(cp);
279 1.1 cgd break;
280 1.1 cgd }
281 1.1 cgd printf("\"%s\" ", cp);
282 1.1 cgd fflush(stdout);
283 1.1 cgd lc = 0;
284 1.1 cgd cc = 0;
285 1.1 cgd while (readline(fbuf, linebuf, LINESIZE) >= 0) {
286 1.1 cgd lc++;
287 1.1 cgd if ((t = putline(collf, linebuf)) < 0) {
288 1.1 cgd Fclose(fbuf);
289 1.1 cgd goto err;
290 1.1 cgd }
291 1.1 cgd cc += t;
292 1.1 cgd }
293 1.1 cgd Fclose(fbuf);
294 1.1 cgd printf("%d/%d\n", lc, cc);
295 1.1 cgd break;
296 1.1 cgd case 'w':
297 1.1 cgd /*
298 1.1 cgd * Write the message on a file.
299 1.1 cgd */
300 1.1 cgd cp = &linebuf[2];
301 1.1 cgd while (*cp == ' ' || *cp == '\t')
302 1.1 cgd cp++;
303 1.1 cgd if (*cp == '\0') {
304 1.1 cgd fprintf(stderr, "Write what file!?\n");
305 1.1 cgd break;
306 1.1 cgd }
307 1.1 cgd if ((cp = expand(cp)) == NOSTR)
308 1.1 cgd break;
309 1.1 cgd rewind(collf);
310 1.1 cgd exwrite(cp, collf, 1);
311 1.1 cgd break;
312 1.1 cgd case 'm':
313 1.1 cgd case 'M':
314 1.1 cgd case 'f':
315 1.1 cgd case 'F':
316 1.1 cgd /*
317 1.1 cgd * Interpolate the named messages, if we
318 1.1 cgd * are in receiving mail mode. Does the
319 1.1 cgd * standard list processing garbage.
320 1.1 cgd * If ~f is given, we don't shift over.
321 1.1 cgd */
322 1.1 cgd if (forward(linebuf + 2, collf, c) < 0)
323 1.1 cgd goto err;
324 1.1 cgd goto cont;
325 1.1 cgd case '?':
326 1.1 cgd if ((fbuf = Fopen(_PATH_TILDE, "r")) == NULL) {
327 1.1 cgd perror(_PATH_TILDE);
328 1.1 cgd break;
329 1.1 cgd }
330 1.1 cgd while ((t = getc(fbuf)) != EOF)
331 1.1 cgd (void) putchar(t);
332 1.1 cgd Fclose(fbuf);
333 1.1 cgd break;
334 1.1 cgd case 'p':
335 1.1 cgd /*
336 1.1 cgd * Print out the current state of the
337 1.1 cgd * message without altering anything.
338 1.1 cgd */
339 1.1 cgd rewind(collf);
340 1.1 cgd printf("-------\nMessage contains:\n");
341 1.1 cgd puthead(hp, stdout, GTO|GSUBJECT|GCC|GBCC|GNL);
342 1.1 cgd while ((t = getc(collf)) != EOF)
343 1.1 cgd (void) putchar(t);
344 1.1 cgd goto cont;
345 1.1 cgd case '|':
346 1.1 cgd /*
347 1.1 cgd * Pipe message through command.
348 1.1 cgd * Collect output as new message.
349 1.1 cgd */
350 1.1 cgd rewind(collf);
351 1.1 cgd mespipe(collf, &linebuf[2]);
352 1.1 cgd goto cont;
353 1.1 cgd case 'v':
354 1.1 cgd case 'e':
355 1.1 cgd /*
356 1.1 cgd * Edit the current message.
357 1.1 cgd * 'e' means to use EDITOR
358 1.1 cgd * 'v' means to use VISUAL
359 1.1 cgd */
360 1.1 cgd rewind(collf);
361 1.1 cgd mesedit(collf, c);
362 1.1 cgd goto cont;
363 1.1 cgd }
364 1.1 cgd }
365 1.1 cgd goto out;
366 1.1 cgd err:
367 1.1 cgd if (collf != NULL) {
368 1.1 cgd Fclose(collf);
369 1.1 cgd collf = NULL;
370 1.1 cgd }
371 1.1 cgd out:
372 1.1 cgd if (collf != NULL)
373 1.1 cgd rewind(collf);
374 1.1 cgd noreset--;
375 1.1 cgd sigblock(sigmask(SIGINT) | sigmask(SIGHUP));
376 1.1 cgd signal(SIGINT, saveint);
377 1.1 cgd signal(SIGHUP, savehup);
378 1.1 cgd signal(SIGTSTP, savetstp);
379 1.1 cgd signal(SIGTTOU, savettou);
380 1.1 cgd signal(SIGTTIN, savettin);
381 1.1 cgd sigsetmask(omask);
382 1.1 cgd return collf;
383 1.1 cgd }
384 1.1 cgd
385 1.1 cgd /*
386 1.1 cgd * Write a file, ex-like if f set.
387 1.1 cgd */
388 1.1 cgd
389 1.1 cgd exwrite(name, fp, f)
390 1.1 cgd char name[];
391 1.1 cgd FILE *fp;
392 1.1 cgd {
393 1.1 cgd register FILE *of;
394 1.1 cgd register int c;
395 1.1 cgd long cc;
396 1.1 cgd int lc;
397 1.1 cgd struct stat junk;
398 1.1 cgd
399 1.1 cgd if (f) {
400 1.1 cgd printf("\"%s\" ", name);
401 1.1 cgd fflush(stdout);
402 1.1 cgd }
403 1.1 cgd if (stat(name, &junk) >= 0 && (junk.st_mode & S_IFMT) == S_IFREG) {
404 1.1 cgd if (!f)
405 1.1 cgd fprintf(stderr, "%s: ", name);
406 1.1 cgd fprintf(stderr, "File exists\n");
407 1.1 cgd return(-1);
408 1.1 cgd }
409 1.1 cgd if ((of = Fopen(name, "w")) == NULL) {
410 1.1 cgd perror(NOSTR);
411 1.1 cgd return(-1);
412 1.1 cgd }
413 1.1 cgd lc = 0;
414 1.1 cgd cc = 0;
415 1.1 cgd while ((c = getc(fp)) != EOF) {
416 1.1 cgd cc++;
417 1.1 cgd if (c == '\n')
418 1.1 cgd lc++;
419 1.1 cgd (void) putc(c, of);
420 1.1 cgd if (ferror(of)) {
421 1.1 cgd perror(name);
422 1.1 cgd Fclose(of);
423 1.1 cgd return(-1);
424 1.1 cgd }
425 1.1 cgd }
426 1.1 cgd Fclose(of);
427 1.1 cgd printf("%d/%ld\n", lc, cc);
428 1.1 cgd fflush(stdout);
429 1.1 cgd return(0);
430 1.1 cgd }
431 1.1 cgd
432 1.1 cgd /*
433 1.1 cgd * Edit the message being collected on fp.
434 1.1 cgd * On return, make the edit file the new temp file.
435 1.1 cgd */
436 1.1 cgd mesedit(fp, c)
437 1.1 cgd FILE *fp;
438 1.1 cgd {
439 1.1 cgd sig_t sigint = signal(SIGINT, SIG_IGN);
440 1.1 cgd FILE *nf = run_editor(fp, (off_t)-1, c, 0);
441 1.1 cgd
442 1.1 cgd if (nf != NULL) {
443 1.1 cgd fseek(nf, (off_t)0, 2);
444 1.1 cgd collf = nf;
445 1.1 cgd Fclose(fp);
446 1.1 cgd }
447 1.1 cgd (void) signal(SIGINT, sigint);
448 1.1 cgd }
449 1.1 cgd
450 1.1 cgd /*
451 1.1 cgd * Pipe the message through the command.
452 1.1 cgd * Old message is on stdin of command;
453 1.1 cgd * New message collected from stdout.
454 1.1 cgd * Sh -c must return 0 to accept the new message.
455 1.1 cgd */
456 1.1 cgd mespipe(fp, cmd)
457 1.1 cgd FILE *fp;
458 1.1 cgd char cmd[];
459 1.1 cgd {
460 1.1 cgd FILE *nf;
461 1.1 cgd sig_t sigint = signal(SIGINT, SIG_IGN);
462 1.1 cgd extern char tempEdit[];
463 1.1 cgd
464 1.1 cgd if ((nf = Fopen(tempEdit, "w+")) == NULL) {
465 1.1 cgd perror(tempEdit);
466 1.1 cgd goto out;
467 1.1 cgd }
468 1.1 cgd (void) unlink(tempEdit);
469 1.1 cgd /*
470 1.1 cgd * stdin = current message.
471 1.1 cgd * stdout = new message.
472 1.1 cgd */
473 1.1 cgd if (run_command(cmd, 0, fileno(fp), fileno(nf), NOSTR) < 0) {
474 1.1 cgd (void) Fclose(nf);
475 1.1 cgd goto out;
476 1.1 cgd }
477 1.1 cgd if (fsize(nf) == 0) {
478 1.1 cgd fprintf(stderr, "No bytes from \"%s\" !?\n", cmd);
479 1.1 cgd (void) Fclose(nf);
480 1.1 cgd goto out;
481 1.1 cgd }
482 1.1 cgd /*
483 1.1 cgd * Take new files.
484 1.1 cgd */
485 1.1 cgd (void) fseek(nf, 0L, 2);
486 1.1 cgd collf = nf;
487 1.1 cgd (void) Fclose(fp);
488 1.1 cgd out:
489 1.1 cgd (void) signal(SIGINT, sigint);
490 1.1 cgd }
491 1.1 cgd
492 1.1 cgd /*
493 1.1 cgd * Interpolate the named messages into the current
494 1.1 cgd * message, preceding each line with a tab.
495 1.1 cgd * Return a count of the number of characters now in
496 1.1 cgd * the message, or -1 if an error is encountered writing
497 1.1 cgd * the message temporary. The flag argument is 'm' if we
498 1.1 cgd * should shift over and 'f' if not.
499 1.1 cgd */
500 1.1 cgd forward(ms, fp, f)
501 1.1 cgd char ms[];
502 1.1 cgd FILE *fp;
503 1.1 cgd {
504 1.1 cgd register int *msgvec;
505 1.1 cgd extern char tempMail[];
506 1.1 cgd struct ignoretab *ig;
507 1.1 cgd char *tabst;
508 1.1 cgd
509 1.1 cgd msgvec = (int *) salloc((msgCount+1) * sizeof *msgvec);
510 1.1 cgd if (msgvec == (int *) NOSTR)
511 1.1 cgd return(0);
512 1.1 cgd if (getmsglist(ms, msgvec, 0) < 0)
513 1.1 cgd return(0);
514 1.1 cgd if (*msgvec == 0) {
515 1.1 cgd *msgvec = first(0, MMNORM);
516 1.1 cgd if (*msgvec == NULL) {
517 1.1 cgd printf("No appropriate messages\n");
518 1.1 cgd return(0);
519 1.1 cgd }
520 1.1 cgd msgvec[1] = NULL;
521 1.1 cgd }
522 1.1 cgd if (f == 'f' || f == 'F')
523 1.1 cgd tabst = NOSTR;
524 1.1 cgd else if ((tabst = value("indentprefix")) == NOSTR)
525 1.1 cgd tabst = "\t";
526 1.1 cgd ig = isupper(f) ? NULL : ignore;
527 1.1 cgd printf("Interpolating:");
528 1.1 cgd for (; *msgvec != 0; msgvec++) {
529 1.1 cgd struct message *mp = message + *msgvec - 1;
530 1.1 cgd
531 1.1 cgd touch(mp);
532 1.1 cgd printf(" %d", *msgvec);
533 1.1 cgd if (send(mp, fp, ig, tabst) < 0) {
534 1.1 cgd perror(tempMail);
535 1.1 cgd return(-1);
536 1.1 cgd }
537 1.1 cgd }
538 1.1 cgd printf("\n");
539 1.1 cgd return(0);
540 1.1 cgd }
541 1.1 cgd
542 1.1 cgd /*
543 1.1 cgd * Print (continue) when continued after ^Z.
544 1.1 cgd */
545 1.1 cgd /*ARGSUSED*/
546 1.1 cgd void
547 1.1 cgd collstop(s)
548 1.1 cgd {
549 1.1 cgd sig_t old_action = signal(s, SIG_DFL);
550 1.1 cgd
551 1.1 cgd sigsetmask(sigblock(0) & ~sigmask(s));
552 1.1 cgd kill(0, s);
553 1.1 cgd sigblock(sigmask(s));
554 1.1 cgd signal(s, old_action);
555 1.1 cgd if (colljmp_p) {
556 1.1 cgd colljmp_p = 0;
557 1.1 cgd hadintr = 0;
558 1.1 cgd longjmp(colljmp, 1);
559 1.1 cgd }
560 1.1 cgd }
561 1.1 cgd
562 1.1 cgd /*
563 1.1 cgd * On interrupt, come here to save the partial message in ~/dead.letter.
564 1.1 cgd * Then jump out of the collection loop.
565 1.1 cgd */
566 1.1 cgd /*ARGSUSED*/
567 1.1 cgd void
568 1.1 cgd collint(s)
569 1.1 cgd {
570 1.1 cgd /*
571 1.1 cgd * the control flow is subtle, because we can be called from ~q.
572 1.1 cgd */
573 1.1 cgd if (!hadintr) {
574 1.1 cgd if (value("ignore") != NOSTR) {
575 1.1 cgd puts("@");
576 1.1 cgd fflush(stdout);
577 1.1 cgd clearerr(stdin);
578 1.1 cgd return;
579 1.1 cgd }
580 1.1 cgd hadintr = 1;
581 1.1 cgd longjmp(colljmp, 1);
582 1.1 cgd }
583 1.1 cgd rewind(collf);
584 1.1 cgd if (value("nosave") == NOSTR)
585 1.1 cgd savedeadletter(collf);
586 1.1 cgd longjmp(collabort, 1);
587 1.1 cgd }
588 1.1 cgd
589 1.1 cgd /*ARGSUSED*/
590 1.1 cgd void
591 1.1 cgd collhup(s)
592 1.1 cgd {
593 1.1 cgd rewind(collf);
594 1.1 cgd savedeadletter(collf);
595 1.1 cgd /*
596 1.1 cgd * Let's pretend nobody else wants to clean up,
597 1.1 cgd * a true statement at this time.
598 1.1 cgd */
599 1.1 cgd exit(1);
600 1.1 cgd }
601 1.1 cgd
602 1.1 cgd savedeadletter(fp)
603 1.1 cgd register FILE *fp;
604 1.1 cgd {
605 1.1 cgd register FILE *dbuf;
606 1.1 cgd register int c;
607 1.1 cgd char *cp;
608 1.1 cgd
609 1.1 cgd if (fsize(fp) == 0)
610 1.1 cgd return;
611 1.1 cgd cp = getdeadletter();
612 1.1 cgd c = umask(077);
613 1.1 cgd dbuf = Fopen(cp, "a");
614 1.1 cgd (void) umask(c);
615 1.1 cgd if (dbuf == NULL)
616 1.1 cgd return;
617 1.1 cgd while ((c = getc(fp)) != EOF)
618 1.1 cgd (void) putc(c, dbuf);
619 1.1 cgd Fclose(dbuf);
620 1.1 cgd rewind(fp);
621 1.1 cgd }
622