/*
* rcvdist.c -- asynchronously redistribute messages
*
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh. See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
*/
#include <h/mh.h>
#include <h/fmt_scan.h>
#include <h/rcvmail.h>
-#include <zotnet/tws/tws.h>
+#include <h/tws.h>
+#include <h/mts.h>
+#include <h/utils.h>
static struct swit switches[] = {
#define FORMSW 0
#define VERSIONSW 1
{ "version", 0 },
#define HELPSW 2
- { "help", 4 },
+ { "help", 0 },
{ NULL, 0 }
};
* prototypes
*/
static void rcvdistout (FILE *, char *, char *);
-int done (int);
+static void unlink_done (int) NORETURN;
int
int i, vecp = 1;
char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
char **argp, **arguments, *vec[MAXARGS];
- register FILE *fp;
+ FILE *fp;
+ char *tfile = NULL;
+
+ done=unlink_done;
#ifdef LOCALE
setlocale(LC_ALL, "");
"%s [switches] [switches for postproc] address ...",
invo_name);
print_help (buf, switches, 1);
- done (1);
+ done (0);
case VERSIONSW:
print_version(invo_name);
- done (1);
+ done (0);
case FORMSW:
if (!(form = *argp++) || *form == '-')
invo_name);
umask (~m_gmprot ());
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- adios (tmpfil, "unable to create");
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+ strncpy (tmpfil, tfile, sizeof(tmpfil));
+
cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
fseek (fp, 0L, SEEK_SET);
- strncpy (drft, m_tmpfil (invo_name), sizeof(drft));
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+ if (tfile == NULL) adios("forw", "unable to create temporary file");
+ strncpy (drft, tfile, sizeof(tmpfil));
+
rcvdistout (fp, form, addrs);
fclose (fp);
vec[0] = r1bindex (postproc, '/');
vec[vecp++] = "-dist";
vec[vecp++] = drft;
+ if ((cp = context_find ("mhlproc"))) {
+ vec[vecp++] = "-mhlproc";
+ vec[vecp++] = cp;
+ }
vec[vecp] = NULL;
for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
*--savecomp = 0;
for (i = ncomps; i--;)
- if (!(*nxtbuf++ = malloc (SBUFSIZ)))
- adios (NULL, "unable to allocate component buffer");
+ *nxtbuf++ = mh_xmalloc (SBUFSIZ);
nxtbuf = compbuffers;
tmpbuf = *nxtbuf++;
case FLDPLUS:
if ((cptr = wantcomp[CHASH (name)]))
do {
- if (!strcasecmp (name, cptr->c_name)) {
+ if (!mh_strcasecmp (name, cptr->c_name)) {
char_read += msg_count;
if (!cptr->c_text) {
cptr->c_text = tmpbuf;
finished: ;
i = format_len + char_read + 256;
- scanl = malloc ((size_t) i + 2);
+ scanl = mh_xmalloc ((size_t) i + 2);
dat[0] = dat[1] = dat[2] = dat[4] = 0;
dat[3] = outputlinelen;
- fmt_scan (fmt, scanl, i, dat);
+ fmt_scan (fmt, scanl, i + 1, i, dat);
fputs (scanl, out);
if (ferror (out))
}
-int
-done (int status)
+static void
+unlink_done (int status)
{
if (backup[0])
unlink (backup);
unlink (tmpfil);
exit (status ? RCV_MBX : RCV_MOK);
- return 1; /* dead code to satisfy the compiler */
}