]> diplodocus.org Git - nmh/blob - uip/spost.c
Sigh. I put the documentation about the -tls switch in the long description,
[nmh] / uip / spost.c
1
2 /*
3 * spost.c -- feed messages to sendmail
4 *
5 * This is a simpler, faster, replacement for "post" for use
6 * when "sendmail" is the transport system.
7 *
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
11 */
12
13 #include <h/mh.h>
14 #include <signal.h>
15 #include <h/addrsbr.h>
16 #include <h/aliasbr.h>
17 #include <h/dropsbr.h>
18 #include <h/tws.h>
19 #include <h/mts.h>
20 #include <h/utils.h>
21
22 #define MAX_SM_FIELD 1476 /* < largest hdr field sendmail will accept */
23 #define FCCS 10 /* max number of fccs allowed */
24
25 struct swit switches[] = {
26 #define FILTSW 0
27 { "filter filterfile", 0 },
28 #define NFILTSW 1
29 { "nofilter", 0 },
30 #define FRMTSW 2
31 { "format", 0 },
32 #define NFRMTSW 3
33 { "noformat", 0 },
34 #define REMVSW 4
35 { "remove", 0 },
36 #define NREMVSW 5
37 { "noremove", 0 },
38 #define VERBSW 6
39 { "verbose", 0 },
40 #define NVERBSW 7
41 { "noverbose", 0 },
42 #define WATCSW 8
43 { "watch", 0 },
44 #define NWATCSW 9
45 { "nowatch", 0 },
46 #define BACKSW 10
47 { "backup", 0 },
48 #define NBACKSW 11
49 { "nobackup", 0 },
50 #define ALIASW 12
51 { "alias aliasfile", 0 },
52 #define NALIASW 13
53 { "noalias", 0 },
54 #define WIDTHSW 14
55 { "width columns", 0 },
56 #define VERSIONSW 15
57 { "version", 0 },
58 #define HELPSW 16
59 { "help", 0 },
60 #define DEBUGSW 17
61 { "debug", -5 },
62 #define DISTSW 18
63 { "dist", -4 }, /* interface from dist */
64 #define CHKSW 19
65 { "check", -5 }, /* interface from whom */
66 #define NCHKSW 20
67 { "nocheck", -7 }, /* interface from whom */
68 #define WHOMSW 21
69 { "whom", -4 }, /* interface from whom */
70 #define PUSHSW 22 /* fork to sendmail then exit */
71 { "push", -4 },
72 #define NPUSHSW 23 /* exec sendmail */
73 { "nopush", -6 },
74 #define LIBSW 24
75 { "library directory", -7 },
76 #define ANNOSW 25
77 { "idanno number", -6 },
78 { NULL, 0 }
79 };
80
81
82 /* flags for headers->flags */
83 #define HNOP 0x0000 /* just used to keep .set around */
84 #define HBAD 0x0001 /* bad header - don't let it through */
85 #define HADR 0x0002 /* header has an address field */
86 #define HSUB 0x0004 /* Subject: header */
87 #define HTRY 0x0008 /* try to send to addrs on header */
88 #define HBCC 0x0010 /* don't output this header */
89 #define HMNG 0x0020 /* mung this header */
90 #define HNGR 0x0040 /* no groups allowed in this header */
91 #define HFCC 0x0080 /* FCC: type header */
92 #define HNIL 0x0100 /* okay for this header not to have addrs */
93 #define HIGN 0x0200 /* ignore this header */
94
95 /* flags for headers->set */
96 #define MFRM 0x0001 /* we've seen a From: */
97 #define MDAT 0x0002 /* we've seen a Date: */
98 #define MRFM 0x0004 /* we've seen a Resent-From: */
99 #define MVIS 0x0008 /* we've seen sighted addrs */
100 #define MINV 0x0010 /* we've seen blind addrs */
101 #define MRDT 0x0020 /* we've seen a Resent-Date: */
102
103 struct headers {
104 char *value;
105 unsigned int flags;
106 unsigned int set;
107 };
108
109
110 static struct headers NHeaders[] = {
111 { "Return-Path", HBAD, 0 },
112 { "Received", HBAD, 0 },
113 { "Reply-To", HADR|HNGR, 0 },
114 { "From", HADR|HNGR, MFRM },
115 { "Sender", HADR|HBAD, 0 },
116 { "Date", HNOP, MDAT },
117 { "Subject", HSUB, 0 },
118 { "To", HADR|HTRY, MVIS },
119 { "cc", HADR|HTRY, MVIS },
120 { "Bcc", HADR|HTRY|HBCC|HNIL, MINV },
121 { "Message-Id", HBAD, 0 },
122 { "Fcc", HFCC, 0 },
123 { NULL, 0, 0 }
124 };
125
126 static struct headers RHeaders[] = {
127 { "Resent-Reply-To", HADR|HNGR, 0 },
128 { "Resent-From", HADR|HNGR, MRFM },
129 { "Resent-Sender", HADR|HBAD, 0 },
130 { "Resent-Date", HNOP, MRDT },
131 { "Resent-Subject", HSUB, 0 },
132 { "Resent-To", HADR|HTRY, MVIS },
133 { "Resent-cc", HADR|HTRY, MVIS },
134 { "Resent-Bcc", HADR|HTRY|HBCC, MINV },
135 { "Resent-Message-Id", HBAD, 0 },
136 { "Resent-Fcc", HFCC, 0 },
137 { "Reply-To", HADR, 0 },
138 { "Fcc", HIGN, 0 },
139 { NULL, 0, 0 }
140 };
141
142
143 static short fccind = 0; /* index into fccfold[] */
144
145 static int badmsg = 0; /* message has bad semantics */
146 static int verbose = 0; /* spell it out */
147 static int debug = 0; /* debugging post */
148 static int rmflg = 1; /* remove temporary file when done */
149 static int watch = 0; /* watch the delivery process */
150 static int backflg = 0; /* rename input file as *.bak when done */
151 static int whomflg = 0; /* if just checking addresses */
152 static int pushflg = 0; /* if going to fork to sendmail */
153 static int aliasflg = -1; /* if going to process aliases */
154 static int outputlinelen=72;
155
156 static unsigned msgflags = 0; /* what we've seen */
157
158 static enum {
159 normal, resent
160 } msgstate = normal;
161
162 static char tmpfil[] = "/tmp/pstXXXXXX";
163
164 static char from[BUFSIZ]; /* my network address */
165 static char signature[BUFSIZ]; /* my signature */
166 static char *filter = NULL; /* the filter for BCC'ing */
167 static char *subject = NULL; /* the subject field for BCC'ing */
168 static char *fccfold[FCCS]; /* foldernames for FCC'ing */
169
170 static struct headers *hdrtab; /* table for the message we're doing */
171 static FILE *out; /* output (temp) file */
172
173 extern char *sendmail;
174
175 /*
176 * external prototypes
177 */
178 extern char *getfullname (void);
179 extern char *getusername (void);
180
181 extern boolean draft_from_masquerading; /* defined in mts.c */
182
183 /*
184 * static prototypes
185 */
186 static void putfmt (char *, char *, FILE *);
187 static void start_headers (void);
188 static void finish_headers (FILE *);
189 static int get_header (char *, struct headers *);
190 static void putadr (char *, struct mailname *);
191 static int putone (char *, int, int);
192 static void insert_fcc (struct headers *, unsigned char *);
193 static void file (char *);
194 static void fcc (char *, char *);
195
196 #if 0
197 static void die (char *, char *, ...);
198 static void make_bcc_file (void);
199 #endif
200
201
202 int
203 main (int argc, char **argv)
204 {
205 int state, i, pid, compnum;
206 char *cp, *msg = NULL, **argp, **arguments;
207 char *sargv[16], buf[BUFSIZ], name[NAMESZ];
208 FILE *in;
209
210 #ifdef LOCALE
211 setlocale(LC_ALL, "");
212 #endif
213 invo_name = r1bindex (argv[0], '/');
214
215 /* foil search of user profile/context */
216 if (context_foil (NULL) == -1)
217 done (1);
218
219 mts_init (invo_name);
220 arguments = getarguments (invo_name, argc, argv, 0);
221 argp = arguments;
222
223 while ((cp = *argp++)) {
224 if (*cp == '-') {
225 switch (smatch (++cp, switches)) {
226 case AMBIGSW:
227 ambigsw (cp, switches);
228 done (1);
229 case UNKWNSW:
230 adios (NULL, "-%s unknown", cp);
231
232 case HELPSW:
233 snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
234 print_help (buf, switches, 1);
235 done (1);
236 case VERSIONSW:
237 print_version(invo_name);
238 done (1);
239
240 case DEBUGSW:
241 debug++;
242 continue;
243
244 case DISTSW:
245 msgstate = resent;
246 continue;
247
248 case WHOMSW:
249 whomflg++;
250 continue;
251
252 case FILTSW:
253 if (!(filter = *argp++) || *filter == '-')
254 adios (NULL, "missing argument to %s", argp[-2]);
255 continue;
256 case NFILTSW:
257 filter = NULL;
258 continue;
259
260 case REMVSW:
261 rmflg++;
262 continue;
263 case NREMVSW:
264 rmflg = 0;
265 continue;
266
267 case BACKSW:
268 backflg++;
269 continue;
270 case NBACKSW:
271 backflg = 0;
272 continue;
273
274 case VERBSW:
275 verbose++;
276 continue;
277 case NVERBSW:
278 verbose = 0;
279 continue;
280
281 case WATCSW:
282 watch++;
283 continue;
284 case NWATCSW:
285 watch = 0;
286 continue;
287
288 case PUSHSW:
289 pushflg++;
290 continue;
291 case NPUSHSW:
292 pushflg = 0;
293 continue;
294
295 case ALIASW:
296 if (!(cp = *argp++) || *cp == '-')
297 adios (NULL, "missing argument to %s", argp[-2]);
298 if (aliasflg < 0)
299 alias (AliasFile);/* load default aka's */
300 aliasflg = 1;
301 if ((state = alias(cp)) != AK_OK)
302 adios (NULL, "aliasing error in file %s - %s",
303 cp, akerror(state) );
304 continue;
305 case NALIASW:
306 aliasflg = 0;
307 continue;
308
309 case WIDTHSW:
310 if (!(cp = *argp++) || *cp == '-')
311 adios (NULL, "missing argument to %s", argp[-2]);
312 outputlinelen = atoi (cp);
313 if (outputlinelen <= 10)
314 outputlinelen = 72;
315 continue;
316
317 case LIBSW:
318 if (!(cp = *argp++) || *cp == '-')
319 adios (NULL, "missing argument to %s", argp[-2]);
320 /* create a minimal context */
321 if (context_foil (cp) == -1)
322 done(1);
323 continue;
324
325 case ANNOSW:
326 /* -idanno switch ignored */
327 if (!(cp = *argp++) || *cp == '-')
328 adios (NULL, "missing argument to %s", argp[-2]);
329 continue;
330 }
331 }
332 if (msg)
333 adios (NULL, "only one message at a time!");
334 else
335 msg = cp;
336 }
337
338 if (aliasflg < 0)
339 alias (AliasFile); /* load default aka's */
340
341 if (!msg)
342 adios (NULL, "usage: %s [switches] file", invo_name);
343
344 if ((in = fopen (msg, "r")) == NULL)
345 adios (msg, "unable to open");
346
347 start_headers ();
348 if (debug) {
349 verbose++;
350 out = stdout;
351 }
352 else {
353 #ifdef HAVE_MKSTEMP
354 if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL )
355 adios (tmpfil, "unable to create");
356 #else
357 mktemp (tmpfil);
358 if ((out = fopen (tmpfil, "w")) == NULL)
359 adios (tmpfil, "unable to create");
360 chmod (tmpfil, 0600);
361 #endif
362 }
363
364 hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
365
366 for (compnum = 1, state = FLD;;) {
367 switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
368 case FLD:
369 compnum++;
370 putfmt (name, buf, out);
371 continue;
372
373 case FLDPLUS:
374 compnum++;
375 cp = add (buf, cp);
376 while (state == FLDPLUS) {
377 state = m_getfld (state, name, buf, sizeof(buf), in);
378 cp = add (buf, cp);
379 }
380 putfmt (name, cp, out);
381 free (cp);
382 continue;
383
384 case BODY:
385 finish_headers (out);
386 fprintf (out, "\n%s", buf);
387 if(whomflg == 0)
388 while (state == BODY) {
389 state = m_getfld (state, name, buf, sizeof(buf), in);
390 fputs (buf, out);
391 }
392 break;
393
394 case FILEEOF:
395 finish_headers (out);
396 break;
397
398 case LENERR:
399 case FMTERR:
400 adios (NULL, "message format error in component #%d",
401 compnum);
402
403 default:
404 adios (NULL, "getfld() returned %d", state);
405 }
406 break;
407 }
408
409 fclose (in);
410 if (backflg && !whomflg) {
411 strncpy (buf, m_backup (msg), sizeof(buf));
412 if (rename (msg, buf) == NOTOK)
413 advise (buf, "unable to rename %s to", msg);
414 }
415
416 if (debug) {
417 done (0);
418 }
419 else
420 fclose (out);
421
422 file (tmpfil);
423
424 /*
425 * re-open the temp file, unlink it and exec sendmail, giving it
426 * the msg temp file as std in.
427 */
428 if ( freopen( tmpfil, "r", stdin) == NULL)
429 adios (tmpfil, "can't reopen for sendmail");
430 if (rmflg)
431 unlink (tmpfil);
432
433 argp = sargv;
434 *argp++ = "send-mail";
435 *argp++ = "-m"; /* send to me too */
436 *argp++ = "-t"; /* read msg for recipients */
437 *argp++ = "-i"; /* don't stop on "." */
438 if (whomflg)
439 *argp++ = "-bv";
440 if (watch || verbose)
441 *argp++ = "-v";
442 *argp = NULL;
443
444 if (pushflg && !(watch || verbose)) {
445 /* fork to a child to run sendmail */
446 for (i=0; (pid = vfork()) == NOTOK && i < 5; i++)
447 sleep(5);
448 switch (pid) {
449 case NOTOK:
450 fprintf (verbose ? stdout : stderr, "%s: can't fork to %s\n",
451 invo_name, sendmail);
452 exit(-1);
453 case OK:
454 /* we're the child .. */
455 break;
456 default:
457 exit(0);
458 }
459 }
460 execv ( sendmail, sargv);
461 adios ( sendmail, "can't exec");
462 return 0; /* dead code to satisfy the compiler */
463 }
464
465 /* DRAFT GENERATION */
466
467 static void
468 putfmt (char *name, char *str, FILE *out)
469 {
470 int i;
471 char *cp, *pp;
472 struct headers *hdr;
473
474 while (*str == ' ' || *str == '\t')
475 str++;
476
477 if ((i = get_header (name, hdrtab)) == NOTOK) {
478 fprintf (out, "%s: %s", name, str);
479 return;
480 }
481
482 hdr = &hdrtab[i];
483 if (hdr->flags & HIGN)
484 return;
485 if (hdr->flags & HBAD) {
486 advise (NULL, "illegal header line -- %s:", name);
487 badmsg++;
488 return;
489 }
490 msgflags |= hdr->set;
491
492 if (hdr->flags & HSUB)
493 subject = subject ? add (str, add ("\t", subject)) : getcpy (str);
494
495 if (hdr->flags & HFCC) {
496 if ((cp = strrchr(str, '\n')))
497 *cp = 0;
498 for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
499 *cp++ = 0;
500 insert_fcc (hdr, pp);
501 }
502 insert_fcc (hdr, pp);
503 return;
504 }
505
506 #ifdef notdef
507 if (hdr->flags & HBCC) {
508 insert_bcc(str);
509 return;
510 }
511 #endif /* notdef */
512
513 if (*str != '\n' && *str != '\0') {
514 if (aliasflg && hdr->flags & HTRY) {
515 /* this header contains address(es) that we have to do
516 * alias expansion on. Because of the saved state in
517 * getname we have to put all the addresses into a list.
518 * We then let putadr munch on that list, possibly
519 * expanding aliases.
520 */
521 register struct mailname *f = 0;
522 register struct mailname *mp = 0;
523
524 while ((cp = getname(str))) {
525 mp = getm( cp, NULL, 0, AD_HOST, NULL);
526 if (f == 0) {
527 f = mp;
528 mp->m_next = mp;
529 } else {
530 mp->m_next = f->m_next;
531 f->m_next = mp;
532 f = mp;
533 }
534 }
535 f = mp->m_next; mp->m_next = 0;
536 putadr( name, f );
537 } else {
538 /* The author(s) of spost decided that alias substitution wasn't
539 necessary for the non-HTRY headers. Unfortunately, one of those
540 headers is "From:", and having alias substitution work on that is
541 extremely useful for someone with a lot of POP3 email accounts or
542 aliases. post supports aliasing of "From:"...
543
544 Since "From:"-processing is incompletely implemented in this
545 unsupported and undocumented spost backend, I'm not going to take
546 the time to implement my new draft-From:-based email address
547 masquerading. If I do ever implement it here, I'd almost
548 certainly want to implement "From:" line alias processing as
549 well. -- Dan Harkless <dan-nmh@dilvish.speed.net> */
550 fprintf (out, "%s: %s", name, str );
551 }
552 }
553 }
554
555
556 static void
557 start_headers (void)
558 {
559 char *cp;
560 char sigbuf[BUFSIZ];
561
562 strncpy(from, getusername(), sizeof(from));
563
564 if ((cp = getfullname ()) && *cp) {
565 strncpy (sigbuf, cp, sizeof(sigbuf));
566 snprintf (signature, sizeof(signature), "%s <%s>", sigbuf, from);
567 }
568 else
569 snprintf (signature, sizeof(signature), "%s", from);
570 }
571
572
573 static void
574 finish_headers (FILE *out)
575 {
576 switch (msgstate) {
577 case normal:
578 if (!(msgflags & MDAT))
579 fprintf (out, "Date: %s\n", dtimenow (0));
580
581 if (msgflags & MFRM) {
582 /* There was already a From: in the draft. Don't add one. */
583 if (!draft_from_masquerading)
584 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
585 so we'll reveal the user's actual account@thismachine
586 address in a Sender: header (and use it as the envelope
587 From: later). */
588 fprintf (out, "Sender: %s\n", from);
589 }
590 else
591 fprintf (out, "From: %s\n", signature);
592
593 #ifdef notdef
594 if (!(msgflags & MVIS))
595 fprintf (out, "Bcc: Blind Distribution List: ;\n");
596 #endif /* notdef */
597 break;
598
599 case resent:
600 if (!(msgflags & MRDT))
601 fprintf (out, "Resent-Date: %s\n", dtimenow(0));
602 if (msgflags & MRFM) {
603 /* There was already a Resent-From: in draft. Don't add one. */
604 if (!draft_from_masquerading)
605 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
606 so we'll reveal the user's actual account@thismachine
607 address in a Sender: header (and use it as the envelope
608 From: later). */
609 fprintf (out, "Resent-Sender: %s\n", from);
610 }
611 else
612 /* Construct a Resent-From: header. */
613 fprintf (out, "Resent-From: %s\n", signature);
614 #ifdef notdef
615 if (!(msgflags & MVIS))
616 fprintf (out, "Resent-Bcc: Blind Re-Distribution List: ;\n");
617 #endif /* notdef */
618 break;
619 }
620
621 if (badmsg)
622 adios (NULL, "re-format message and try again");
623 }
624
625
626 static int
627 get_header (char *header, struct headers *table)
628 {
629 struct headers *h;
630
631 for (h = table; h->value; h++)
632 if (!mh_strcasecmp (header, h->value))
633 return (h - table);
634
635 return NOTOK;
636 }
637
638
639 /*
640 * output the address list for header "name". The address list
641 * is a linked list of mailname structs. "nl" points to the head
642 * of the list. Alias substitution should be done on nl.
643 */
644 static void
645 putadr (char *name, struct mailname *nl)
646 {
647 register struct mailname *mp, *mp2;
648 register int linepos;
649 register char *cp;
650 int namelen;
651
652 fprintf (out, "%s: ", name);
653 namelen = strlen(name) + 2;
654 linepos = namelen;
655
656 for (mp = nl; mp; ) {
657 if (linepos > MAX_SM_FIELD) {
658 fprintf (out, "\n%s: ", name);
659 linepos = namelen;
660 }
661 if (mp->m_nohost) {
662 /* a local name - see if it's an alias */
663 cp = akvalue(mp->m_mbox);
664 if (cp == mp->m_mbox)
665 /* wasn't an alias - use what the user typed */
666 linepos = putone( mp->m_text, linepos, namelen );
667 else
668 /* an alias - expand it */
669 while ((cp = getname(cp))) {
670 if (linepos > MAX_SM_FIELD) {
671 fprintf (out, "\n%s: ", name);
672 linepos = namelen;
673 }
674 mp2 = getm( cp, NULL, 0, AD_HOST, NULL);
675 if (akvisible()) {
676 mp2->m_pers = getcpy(mp->m_mbox);
677 linepos = putone( adrformat(mp2), linepos, namelen );
678 } else {
679 linepos = putone( mp2->m_text, linepos, namelen );
680 }
681 mnfree( mp2 );
682 }
683 } else {
684 /* not a local name - use what the user typed */
685 linepos = putone( mp->m_text, linepos, namelen );
686 }
687 mp2 = mp;
688 mp = mp->m_next;
689 mnfree( mp2 );
690 }
691 putc( '\n', out );
692 }
693
694 static int
695 putone (char *adr, int pos, int indent)
696 {
697 register int len;
698 static int linepos;
699
700 len = strlen( adr );
701 if (pos == indent)
702 linepos = pos;
703 else if ( linepos+len > outputlinelen ) {
704 fprintf ( out, ",\n%*s", indent, "");
705 linepos = indent;
706 pos += indent + 2;
707 }
708 else {
709 fputs( ", ", out );
710 linepos += 2;
711 pos += 2;
712 }
713 fputs( adr, out );
714
715 linepos += len;
716 return (pos+len);
717 }
718
719
720 static void
721 insert_fcc (struct headers *hdr, unsigned char *pp)
722 {
723 unsigned char *cp;
724
725 for (cp = pp; isspace (*cp); cp++)
726 continue;
727 for (pp += strlen (pp) - 1; pp > cp && isspace (*pp); pp--)
728 continue;
729 if (pp >= cp)
730 *++pp = 0;
731 if (*cp == 0)
732 return;
733
734 if (fccind >= FCCS)
735 adios (NULL, "too many %ss", hdr->value);
736 fccfold[fccind++] = getcpy (cp);
737 }
738
739 #if 0
740 /* BCC GENERATION */
741
742 static void
743 make_bcc_file (void)
744 {
745 pid_t child_id;
746 int fd, i, status;
747 char *vec[6];
748 FILE * in, *out;
749
750 #ifdef HAVE_MKSTEMP
751 fd = mkstemp(bccfil);
752 if (fd == -1 || (out = fdopen(fd, "w")) == NULL)
753 adios (bccfil, "unable to create");
754 #else
755 mktemp (bccfil);
756 if ((out = fopen (bccfil, "w")) == NULL)
757 adios (bccfil, "unable to create");
758 #endif
759 chmod (bccfil, 0600);
760
761 fprintf (out, "Date: %s\n", dtimenow (0));
762 if (msgflags & MFRM) {
763 /* There was already a From: in the draft. Don't add one. */
764 if (!draft_from_masquerading)
765 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
766 so we'll reveal the user's actual account@thismachine
767 address in a Sender: header (and use it as the envelope
768 From: later). */
769 fprintf (out, "Sender: %s\n", from);
770 }
771 else
772 /* Construct a From: header. */
773 fprintf (out, "From: %s\n", signature);
774 if (subject)
775 fprintf (out, "Subject: %s", subject);
776 fprintf (out, "BCC:\n\n------- Blind-Carbon-Copy\n\n");
777 fflush (out);
778
779 if (filter == NULL) {
780 if ((fd = open (tmpfil, O_RDONLY)) == NOTOK)
781 adios (NULL, "unable to re-open");
782 cpydgst (fd, fileno (out), tmpfil, bccfil);
783 close (fd);
784 }
785 else {
786 vec[0] = r1bindex (mhlproc, '/');
787
788 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
789 sleep (5);
790 switch (child_id) {
791 case NOTOK:
792 adios ("vfork", "unable to");
793
794 case OK:
795 dup2 (fileno (out), 1);
796
797 i = 1;
798 vec[i++] = "-forward";
799 vec[i++] = "-form";
800 vec[i++] = filter;
801 vec[i++] = tmpfil;
802 vec[i] = NULL;
803
804 execvp (mhlproc, vec);
805 adios (mhlproc, "unable to exec");
806
807 default:
808 if (status = pidwait(child_id, OK))
809 admonish (NULL, "%s lost (status=0%o)", vec[0], status);
810 break;
811 }
812 }
813
814 fseek (out, 0L, SEEK_END);
815 fprintf (out, "\n------- End of Blind-Carbon-Copy\n");
816 fclose (out);
817 }
818 #endif /* if 0 */
819
820 /* FCC INTERACTION */
821
822 static void
823 file (char *path)
824 {
825 int i;
826
827 if (fccind == 0)
828 return;
829
830 for (i = 0; i < fccind; i++)
831 if (whomflg)
832 printf ("Fcc: %s\n", fccfold[i]);
833 else
834 fcc (path, fccfold[i]);
835 }
836
837
838 static void
839 fcc (char *file, char *folder)
840 {
841 pid_t child_id;
842 int i, status;
843 char fold[BUFSIZ];
844
845 if (verbose)
846 printf ("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", folder);
847 fflush (stdout);
848
849 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
850 sleep (5);
851 switch (child_id) {
852 case NOTOK:
853 if (!verbose)
854 fprintf (stderr, " %sFcc %s: ",
855 msgstate == resent ? "Resent-" : "", folder);
856 fprintf (verbose ? stdout : stderr, "no forks, so not ok\n");
857 break;
858
859 case OK:
860 snprintf (fold, sizeof(fold), "%s%s",
861 *folder == '+' || *folder == '@' ? "" : "+", folder);
862 execlp (fileproc, r1bindex (fileproc, '/'),
863 "-link", "-file", file, fold, NULL);
864 _exit (-1);
865
866 default:
867 if ((status = pidwait(child_id, OK))) {
868 if (!verbose)
869 fprintf (stderr, " %sFcc %s: ",
870 msgstate == resent ? "Resent-" : "", folder);
871 fprintf (verbose ? stdout : stderr,
872 " errored (0%o)\n", status);
873 }
874 }
875
876 fflush (stdout);
877 }
878
879
880 #if 0
881
882 /*
883 * TERMINATION
884 */
885
886 static void
887 die (char *what, char *fmt, ...)
888 {
889 va_list ap;
890
891 va_start(ap, fmt);
892 advertise (what, NULL, fmt, ap);
893 va_end(ap);
894
895 done (1);
896 }
897 #endif