- }
- fclose (out);
-
- nvec = 0;
- vec[nvec++] = r1bindex (postproc, '/');
- vec[nvec++] = tmpfil;
- if (resent)
- vec[nvec++] = "-dist";
- if (queued)
- vec[nvec++] = "-queued";
- vec[nvec] = NULL;
-
- for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
- sleep (5);
-
- if (child_id == NOTOK) {
- /* report failure and then send it */
- adios (NULL, "unable to fork");
- } else if (child_id) {
- /* parent process */
- if ((status = pidXwait(child_id, postproc))) {
- fprintf (stderr, "Letter saved in dead.letter\n");
- execl ("/bin/mv", "mv", tmpfil, "dead.letter", NULL);
- execl ("/usr/bin/mv", "mv", tmpfil, "dead.letter", NULL);
- perror ("mv");
- _exit (-1);
+
+ if (tolist == NULL)
+ adios(NULL, "usage: %s addrs ... [switches]", invo_name);
+
+ tfile = m_mktemp2("/tmp/", invo_name, NULL, &out);
+ if (tfile == NULL)
+ adios("mhmail", "unable to create temporary file");
+ chmod(tfile, 0600);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
+
+ SIGNAL2(SIGINT, intrser);
+
+ fprintf(out, "%sTo: %s\n", resent ? "Resent-" : "", tolist);
+ if (cclist)
+ fprintf(out, "%sCc: %s\n", resent ? "Resent-" : "", cclist);
+ if (subject)
+ fprintf(out, "%sSubject: %s\n", resent ? "Resent-" : "", subject);
+ if (from)
+ fprintf(out, "%sFrom: %s\n", resent ? "Resent-" : "", from);
+ if (!resent)
+ fputs("\n", out);
+
+ if (body) {
+ fprintf(out, "%s", body);
+ if (*body && *(body + strlen(body) - 1) != '\n')
+ fputs("\n", out);
+ } else {
+ for (somebody = 0; (i = fread(buf, sizeof(*buf), sizeof(buf),
+ stdin)) > 0; somebody++)
+ if (fwrite(buf, sizeof(*buf), i, out) != i)
+ adios(tmpfil, "error writing");
+ if (!somebody) {
+ unlink(tmpfil);
+ done(1);
+ }
+ }
+ fclose(out);
+
+ nvec = 0;
+ vec[nvec++] = mhbasename(postproc);
+ vec[nvec++] = tmpfil;
+ if (resent)
+ vec[nvec++] = "-dist";
+ if (queued)
+ vec[nvec++] = "-queued";
+ vec[nvec] = NULL;
+
+ for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
+ sleep(5);
+
+ if (child_id == NOTOK) {
+ /* report failure and then send it */
+ adios(NULL, "unable to fork");
+ } else if (child_id) {
+ /* parent process */
+ if ((status = pidXwait(child_id, postproc))) {
+ fprintf(stderr, "Letter saved in dead.letter\n");
+ execl("/bin/mv", "mv", tmpfil, "dead.letter", NULL);
+ execl("/usr/bin/mv", "mv", tmpfil, "dead.letter",
+ NULL);
+ perror("mv");
+ _exit(-1);
+ }
+ unlink(tmpfil);
+ done(status ? 1 : 0);
+ } else {
+ /* child process */
+ execvp(postproc, vec);
+ fprintf(stderr, "unable to exec ");
+ perror(postproc);
+ _exit(-1);