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