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