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