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