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