- pid_t child_id;
- int i, vecp = 1;
- char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
- char **argp, **arguments, *vec[MAXARGS];
- register FILE *fp;
-
- done=unlink_done;
-
-#ifdef LOCALE
- setlocale(LC_ALL, "");
-#endif
- invo_name = r1bindex (argv[0], '/');
-
- /* read user profile/context */
- context_read();
-
- mts_init (invo_name);
- arguments = getarguments (invo_name, argc, argv, 1);
- argp = arguments;
-
- while ((cp = *argp++)) {
- if (*cp == '-') {
- switch (smatch (++cp, switches)) {
- case AMBIGSW:
- ambigsw (cp, switches);
- done (1);
- case UNKWNSW:
- vec[vecp++] = --cp;
- continue;
-
- case HELPSW:
- snprintf (buf, sizeof(buf),
- "%s [switches] [switches for postproc] address ...",
- invo_name);
- print_help (buf, switches, 1);
- done (1);
- case VERSIONSW:
- print_version(invo_name);
- done (1);
-
- case FORMSW:
- if (!(form = *argp++) || *form == '-')
- adios (NULL, "missing argument to %s", argp[-2]);
- continue;
- }
+ int vecp = 1;
+ char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
+ char **argp, **arguments, *vec[MAXARGS];
+ FILE *fp;
+ char *tfile = NULL;
+
+ if (atexit(unlink_done) != 0) {
+ adios(EX_OSERR, NULL, "atexit failed");
+ }
+
+ setlocale(LC_ALL, "");
+ invo_name = mhbasename(argv[0]);
+
+ /* read user profile/context */
+ context_read();
+
+ arguments = getarguments(invo_name, argc, argv, 1);
+ argp = arguments;
+
+ while ((cp = *argp++)) {
+ if (*cp == '-') {
+ switch (smatch(++cp, switches)) {
+ case AMBIGSW:
+ ambigsw(cp, switches);
+ exit(EX_USAGE);
+ case UNKWNSW:
+ vec[vecp++] = --cp;
+ continue;
+
+ case HELPSW:
+ snprintf(buf, sizeof(buf), "%s [switches] [switches for spost] address ...", invo_name);
+ print_help(buf, switches, 1);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+ case VERSIONSW:
+ print_version(invo_name);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
+
+ case FORMSW:
+ if (!(form = *argp++) || *form == '-') {
+ adios(EX_USAGE, NULL, "missing argument to %s",
+ argp[-2]);
+ }
+ continue;
+ }
+ }
+ addrs = addrs ? add(cp, add(", ", addrs)) : getcpy(cp);
+ }
+
+ if (!addrs) {
+ adios(EX_USAGE, NULL, "usage: %s [switches] [switches for spost] address ...", invo_name);
+ }
+
+ umask(~m_gmprot());
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) adios(EX_CANTCREAT, "rcvdist", "unable to create temporary file");
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
+
+ cpydata(fileno(stdin), fileno(fp), "message", tmpfil);
+ fseek(fp, 0L, SEEK_SET);
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+ if (tfile == NULL) adios(EX_CANTCREAT, "forw", "unable to create temporary file");
+ strncpy(drft, tfile, sizeof(tmpfil));
+
+ rcvdistout(fp, form, addrs);
+ fclose(fp);
+
+ if (distout(drft, tmpfil, backup) == NOTOK) {
+ exit(EX_IOERR);