]> diplodocus.org Git - nmh/blob - uip/spost.c
Feed fileproc and mhlproc from rcvdist, send, and whatnow to post.
[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 if ((out = fdopen( mkstemp (tmpfil), "w" )) == NULL )
354 adios (tmpfil, "unable to create");
355 }
356
357 hdrtab = (msgstate == normal) ? NHeaders : RHeaders;
358
359 for (compnum = 1, state = FLD;;) {
360 switch (state = m_getfld (state, name, buf, sizeof(buf), in)) {
361 case FLD:
362 compnum++;
363 putfmt (name, buf, out);
364 continue;
365
366 case FLDPLUS:
367 compnum++;
368 cp = add (buf, cp);
369 while (state == FLDPLUS) {
370 state = m_getfld (state, name, buf, sizeof(buf), in);
371 cp = add (buf, cp);
372 }
373 putfmt (name, cp, out);
374 free (cp);
375 continue;
376
377 case BODY:
378 finish_headers (out);
379 fprintf (out, "\n%s", buf);
380 if(whomflg == 0)
381 while (state == BODY) {
382 state = m_getfld (state, name, buf, sizeof(buf), in);
383 fputs (buf, out);
384 }
385 break;
386
387 case FILEEOF:
388 finish_headers (out);
389 break;
390
391 case LENERR:
392 case FMTERR:
393 adios (NULL, "message format error in component #%d",
394 compnum);
395
396 default:
397 adios (NULL, "getfld() returned %d", state);
398 }
399 break;
400 }
401
402 fclose (in);
403 if (backflg && !whomflg) {
404 strncpy (buf, m_backup (msg), sizeof(buf));
405 if (rename (msg, buf) == NOTOK)
406 advise (buf, "unable to rename %s to", msg);
407 }
408
409 if (debug) {
410 done (0);
411 }
412 else
413 fclose (out);
414
415 file (tmpfil);
416
417 /*
418 * re-open the temp file, unlink it and exec sendmail, giving it
419 * the msg temp file as std in.
420 */
421 if ( freopen( tmpfil, "r", stdin) == NULL)
422 adios (tmpfil, "can't reopen for sendmail");
423 if (rmflg)
424 unlink (tmpfil);
425
426 argp = sargv;
427 *argp++ = "send-mail";
428 *argp++ = "-m"; /* send to me too */
429 *argp++ = "-t"; /* read msg for recipients */
430 *argp++ = "-i"; /* don't stop on "." */
431 if (whomflg)
432 *argp++ = "-bv";
433 if (watch || verbose)
434 *argp++ = "-v";
435 *argp = NULL;
436
437 if (pushflg && !(watch || verbose)) {
438 /* fork to a child to run sendmail */
439 for (i=0; (pid = vfork()) == NOTOK && i < 5; i++)
440 sleep(5);
441 switch (pid) {
442 case NOTOK:
443 fprintf (verbose ? stdout : stderr, "%s: can't fork to %s\n",
444 invo_name, sendmail);
445 exit(-1);
446 case OK:
447 /* we're the child .. */
448 break;
449 default:
450 exit(0);
451 }
452 }
453 execv ( sendmail, sargv);
454 adios ( sendmail, "can't exec");
455 return 0; /* dead code to satisfy the compiler */
456 }
457
458 /* DRAFT GENERATION */
459
460 static void
461 putfmt (char *name, char *str, FILE *out)
462 {
463 int i;
464 char *cp, *pp;
465 struct headers *hdr;
466
467 while (*str == ' ' || *str == '\t')
468 str++;
469
470 if ((i = get_header (name, hdrtab)) == NOTOK) {
471 fprintf (out, "%s: %s", name, str);
472 return;
473 }
474
475 hdr = &hdrtab[i];
476 if (hdr->flags & HIGN)
477 return;
478 if (hdr->flags & HBAD) {
479 advise (NULL, "illegal header line -- %s:", name);
480 badmsg++;
481 return;
482 }
483 msgflags |= hdr->set;
484
485 if (hdr->flags & HSUB)
486 subject = subject ? add (str, add ("\t", subject)) : getcpy (str);
487
488 if (hdr->flags & HFCC) {
489 if ((cp = strrchr(str, '\n')))
490 *cp = 0;
491 for (cp = pp = str; (cp = strchr(pp, ',')); pp = cp) {
492 *cp++ = 0;
493 insert_fcc (hdr, pp);
494 }
495 insert_fcc (hdr, pp);
496 return;
497 }
498
499 #ifdef notdef
500 if (hdr->flags & HBCC) {
501 insert_bcc(str);
502 return;
503 }
504 #endif /* notdef */
505
506 if (*str != '\n' && *str != '\0') {
507 if (aliasflg && hdr->flags & HTRY) {
508 /* this header contains address(es) that we have to do
509 * alias expansion on. Because of the saved state in
510 * getname we have to put all the addresses into a list.
511 * We then let putadr munch on that list, possibly
512 * expanding aliases.
513 */
514 register struct mailname *f = 0;
515 register struct mailname *mp = 0;
516
517 while ((cp = getname(str))) {
518 mp = getm( cp, NULL, 0, AD_HOST, NULL);
519 if (f == 0) {
520 f = mp;
521 mp->m_next = mp;
522 } else {
523 mp->m_next = f->m_next;
524 f->m_next = mp;
525 f = mp;
526 }
527 }
528 f = mp->m_next; mp->m_next = 0;
529 putadr( name, f );
530 } else {
531 /* The author(s) of spost decided that alias substitution wasn't
532 necessary for the non-HTRY headers. Unfortunately, one of those
533 headers is "From:", and having alias substitution work on that is
534 extremely useful for someone with a lot of POP3 email accounts or
535 aliases. post supports aliasing of "From:"...
536
537 Since "From:"-processing is incompletely implemented in this
538 unsupported and undocumented spost backend, I'm not going to take
539 the time to implement my new draft-From:-based email address
540 masquerading. If I do ever implement it here, I'd almost
541 certainly want to implement "From:" line alias processing as
542 well. -- Dan Harkless <dan-nmh@dilvish.speed.net> */
543 fprintf (out, "%s: %s", name, str );
544 }
545 }
546 }
547
548
549 static void
550 start_headers (void)
551 {
552 char *cp;
553 char sigbuf[BUFSIZ];
554
555 strncpy(from, getusername(), sizeof(from));
556
557 if ((cp = getfullname ()) && *cp) {
558 strncpy (sigbuf, cp, sizeof(sigbuf));
559 snprintf (signature, sizeof(signature), "%s <%s>", sigbuf, from);
560 }
561 else
562 snprintf (signature, sizeof(signature), "%s", from);
563 }
564
565
566 static void
567 finish_headers (FILE *out)
568 {
569 switch (msgstate) {
570 case normal:
571 if (!(msgflags & MDAT))
572 fprintf (out, "Date: %s\n", dtimenow (0));
573
574 if (msgflags & MFRM) {
575 /* There was already a From: in the draft. Don't add one. */
576 if (!draft_from_masquerading)
577 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
578 so we'll reveal the user's actual account@thismachine
579 address in a Sender: header (and use it as the envelope
580 From: later). */
581 fprintf (out, "Sender: %s\n", from);
582 }
583 else
584 fprintf (out, "From: %s\n", signature);
585
586 #ifdef notdef
587 if (!(msgflags & MVIS))
588 fprintf (out, "Bcc: Blind Distribution List: ;\n");
589 #endif /* notdef */
590 break;
591
592 case resent:
593 if (!(msgflags & MRDT))
594 fprintf (out, "Resent-Date: %s\n", dtimenow(0));
595 if (msgflags & MRFM) {
596 /* There was already a Resent-From: in draft. Don't add one. */
597 if (!draft_from_masquerading)
598 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
599 so we'll reveal the user's actual account@thismachine
600 address in a Sender: header (and use it as the envelope
601 From: later). */
602 fprintf (out, "Resent-Sender: %s\n", from);
603 }
604 else
605 /* Construct a Resent-From: header. */
606 fprintf (out, "Resent-From: %s\n", signature);
607 #ifdef notdef
608 if (!(msgflags & MVIS))
609 fprintf (out, "Resent-Bcc: Blind Re-Distribution List: ;\n");
610 #endif /* notdef */
611 break;
612 }
613
614 if (badmsg)
615 adios (NULL, "re-format message and try again");
616 }
617
618
619 static int
620 get_header (char *header, struct headers *table)
621 {
622 struct headers *h;
623
624 for (h = table; h->value; h++)
625 if (!mh_strcasecmp (header, h->value))
626 return (h - table);
627
628 return NOTOK;
629 }
630
631
632 /*
633 * output the address list for header "name". The address list
634 * is a linked list of mailname structs. "nl" points to the head
635 * of the list. Alias substitution should be done on nl.
636 */
637 static void
638 putadr (char *name, struct mailname *nl)
639 {
640 register struct mailname *mp, *mp2;
641 register int linepos;
642 register char *cp;
643 int namelen;
644
645 fprintf (out, "%s: ", name);
646 namelen = strlen(name) + 2;
647 linepos = namelen;
648
649 for (mp = nl; mp; ) {
650 if (linepos > MAX_SM_FIELD) {
651 fprintf (out, "\n%s: ", name);
652 linepos = namelen;
653 }
654 if (mp->m_nohost) {
655 /* a local name - see if it's an alias */
656 cp = akvalue(mp->m_mbox);
657 if (cp == mp->m_mbox)
658 /* wasn't an alias - use what the user typed */
659 linepos = putone( mp->m_text, linepos, namelen );
660 else
661 /* an alias - expand it */
662 while ((cp = getname(cp))) {
663 if (linepos > MAX_SM_FIELD) {
664 fprintf (out, "\n%s: ", name);
665 linepos = namelen;
666 }
667 mp2 = getm( cp, NULL, 0, AD_HOST, NULL);
668 if (akvisible()) {
669 mp2->m_pers = getcpy(mp->m_mbox);
670 linepos = putone( adrformat(mp2), linepos, namelen );
671 } else {
672 linepos = putone( mp2->m_text, linepos, namelen );
673 }
674 mnfree( mp2 );
675 }
676 } else {
677 /* not a local name - use what the user typed */
678 linepos = putone( mp->m_text, linepos, namelen );
679 }
680 mp2 = mp;
681 mp = mp->m_next;
682 mnfree( mp2 );
683 }
684 putc( '\n', out );
685 }
686
687 static int
688 putone (char *adr, int pos, int indent)
689 {
690 register int len;
691 static int linepos;
692
693 len = strlen( adr );
694 if (pos == indent)
695 linepos = pos;
696 else if ( linepos+len > outputlinelen ) {
697 fprintf ( out, ",\n%*s", indent, "");
698 linepos = indent;
699 pos += indent + 2;
700 }
701 else {
702 fputs( ", ", out );
703 linepos += 2;
704 pos += 2;
705 }
706 fputs( adr, out );
707
708 linepos += len;
709 return (pos+len);
710 }
711
712
713 static void
714 insert_fcc (struct headers *hdr, unsigned char *pp)
715 {
716 unsigned char *cp;
717
718 for (cp = pp; isspace (*cp); cp++)
719 continue;
720 for (pp += strlen (pp) - 1; pp > cp && isspace (*pp); pp--)
721 continue;
722 if (pp >= cp)
723 *++pp = 0;
724 if (*cp == 0)
725 return;
726
727 if (fccind >= FCCS)
728 adios (NULL, "too many %ss", hdr->value);
729 fccfold[fccind++] = getcpy (cp);
730 }
731
732 #if 0
733 /* BCC GENERATION */
734
735 static void
736 make_bcc_file (void)
737 {
738 pid_t child_id;
739 int fd, i, status;
740 char *vec[6];
741 FILE * in, *out;
742
743 fd = mkstemp(bccfil);
744 if (fd == -1 || (out = fdopen(fd, "w")) == NULL)
745 adios (bccfil, "unable to create");
746 chmod (bccfil, 0600);
747
748 fprintf (out, "Date: %s\n", dtimenow (0));
749 if (msgflags & MFRM) {
750 /* There was already a From: in the draft. Don't add one. */
751 if (!draft_from_masquerading)
752 /* mts.conf didn't contain "masquerade:[...]draft_from[...]"
753 so we'll reveal the user's actual account@thismachine
754 address in a Sender: header (and use it as the envelope
755 From: later). */
756 fprintf (out, "Sender: %s\n", from);
757 }
758 else
759 /* Construct a From: header. */
760 fprintf (out, "From: %s\n", signature);
761 if (subject)
762 fprintf (out, "Subject: %s", subject);
763 fprintf (out, "BCC:\n\n------- Blind-Carbon-Copy\n\n");
764 fflush (out);
765
766 if (filter == NULL) {
767 if ((fd = open (tmpfil, O_RDONLY)) == NOTOK)
768 adios (NULL, "unable to re-open");
769 cpydgst (fd, fileno (out), tmpfil, bccfil);
770 close (fd);
771 }
772 else {
773 vec[0] = r1bindex (mhlproc, '/');
774
775 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
776 sleep (5);
777 switch (child_id) {
778 case NOTOK:
779 adios ("vfork", "unable to");
780
781 case OK:
782 dup2 (fileno (out), 1);
783
784 i = 1;
785 vec[i++] = "-forward";
786 vec[i++] = "-form";
787 vec[i++] = filter;
788 vec[i++] = tmpfil;
789 vec[i] = NULL;
790
791 execvp (mhlproc, vec);
792 adios (mhlproc, "unable to exec");
793
794 default:
795 if (status = pidwait(child_id, OK))
796 admonish (NULL, "%s lost (status=0%o)", vec[0], status);
797 break;
798 }
799 }
800
801 fseek (out, 0L, SEEK_END);
802 fprintf (out, "\n------- End of Blind-Carbon-Copy\n");
803 fclose (out);
804 }
805 #endif /* if 0 */
806
807 /* FCC INTERACTION */
808
809 static void
810 file (char *path)
811 {
812 int i;
813
814 if (fccind == 0)
815 return;
816
817 for (i = 0; i < fccind; i++)
818 if (whomflg)
819 printf ("Fcc: %s\n", fccfold[i]);
820 else
821 fcc (path, fccfold[i]);
822 }
823
824
825 static void
826 fcc (char *file, char *folder)
827 {
828 pid_t child_id;
829 int i, status;
830 char fold[BUFSIZ];
831
832 if (verbose)
833 printf ("%sFcc: %s\n", msgstate == resent ? "Resent-" : "", folder);
834 fflush (stdout);
835
836 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
837 sleep (5);
838 switch (child_id) {
839 case NOTOK:
840 if (!verbose)
841 fprintf (stderr, " %sFcc %s: ",
842 msgstate == resent ? "Resent-" : "", folder);
843 fprintf (verbose ? stdout : stderr, "no forks, so not ok\n");
844 break;
845
846 case OK:
847 snprintf (fold, sizeof(fold), "%s%s",
848 *folder == '+' || *folder == '@' ? "" : "+", folder);
849 execlp (fileproc, r1bindex (fileproc, '/'),
850 "-link", "-file", file, fold, NULL);
851 _exit (-1);
852
853 default:
854 if ((status = pidwait(child_id, OK))) {
855 if (!verbose)
856 fprintf (stderr, " %sFcc %s: ",
857 msgstate == resent ? "Resent-" : "", folder);
858 fprintf (verbose ? stdout : stderr,
859 " errored (0%o)\n", status);
860 }
861 }
862
863 fflush (stdout);
864 }
865
866
867 #if 0
868
869 /*
870 * TERMINATION
871 */
872
873 static void
874 die (char *what, char *fmt, ...)
875 {
876 va_list ap;
877
878 va_start(ap, fmt);
879 advertise (what, NULL, fmt, ap);
880 va_end(ap);
881
882 done (1);
883 }
884 #endif