- int status, vecp = 1;
- char tmpfil[BUFSIZ];
- char *vec[MAXARGS];
- struct stat st;
- FILE *fp;
-
- umask (~m_gmprot ());
-
- strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
- if ((fp = fopen (tmpfil, "w+")) == NULL)
- adios (tmpfil, "unable to open for writing");
- chmod (tmpfil, 0600);
-
- if (!strchr(mailsw, '@'))
- mailsw = concat (mailsw, "@", LocalName (), NULL);
- fprintf (fp, "To: %s\n", mailsw);
-
- if (subjsw)
- fprintf (fp, "Subject: %s\n", subjsw);
-
- if (fromsw) {
- if (!strchr(fromsw, '@'))
- fromsw = concat (fromsw, "@", LocalName (), NULL);
- fprintf (fp, "From: %s\n", fromsw);
- }
-
- fprintf (fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE);
- fprintf (fp, "%s: application/octet-stream", TYPE_FIELD);
-
- if (parmsw)
- fprintf (fp, "; %s", parmsw);
-
- if (cmntsw)
- fprintf (fp, "\n\t(%s)", cmntsw);
-
- if (descsw)
- fprintf (fp, "\n%s: %s", DESCR_FIELD, descsw);
-
- fprintf (fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64");
-
- if (fflush (fp))
- adios (tmpfil, "error writing to");
-
- writeBase64aux (stdin, fp);
- if (fflush (fp))
- adios (tmpfil, "error writing to");
-
- if (fstat (fileno (fp), &st) == NOTOK)
- adios ("failed", "fstat of %s", tmpfil);
-
- if (delay < 0)
- splitsw = 10;
- else
- splitsw = delay;
-
- status = 0;
- vec[0] = r1bindex (postproc, '/');
- if (verbsw)
- vec[vecp++] = "-verbose";
-
- switch (sendsbr (vec, vecp, tmpfil, &st, 0)) {
- case DONE:
- case NOTOK:
- status++;
- break;
- case OK:
- break;
- }
-
- fclose (fp);
- if (unlink (tmpfil) == -1)
- advise (NULL, "unable to remove temp file %s", tmpfil);
- return done (status);
+ int status, vecp = 1;
+ char tmpfil[BUFSIZ];
+ char *vec[MAXARGS];
+ struct stat st;
+ FILE *fp;
+ char *tfile = NULL;
+
+ umask(~m_gmprot());
+
+ tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+ if (tfile == NULL)
+ adios("viamail", "unable to create temporary file");
+ chmod(tfile, 0600);
+ strncpy(tmpfil, tfile, sizeof(tmpfil));
+
+ if (!strchr(mailsw, '@'))
+ mailsw = concat(mailsw, "@", LocalName(), NULL);
+ fprintf(fp, "To: %s\n", mailsw);
+
+ if (subjsw)
+ fprintf(fp, "Subject: %s\n", subjsw);
+
+ if (fromsw) {
+ if (!strchr(fromsw, '@'))
+ fromsw = concat(fromsw, "@", LocalName(), NULL);
+ fprintf(fp, "From: %s\n", fromsw);
+ }
+
+ fprintf(fp, "%s: %s\n", VRSN_FIELD, VRSN_VALUE);
+ fprintf(fp, "%s: application/octet-stream", TYPE_FIELD);
+
+ if (parmsw)
+ fprintf(fp, "; %s", parmsw);
+
+ if (cmntsw)
+ fprintf(fp, "\n\t(%s)", cmntsw);
+
+ if (descsw)
+ fprintf(fp, "\n%s: %s", DESCR_FIELD, descsw);
+
+ fprintf(fp, "\n%s: %s\n\n", ENCODING_FIELD, "base64");
+
+ if (fflush(fp))
+ adios(tmpfil, "error writing to");
+
+ writeBase64aux(stdin, fp);
+ if (fflush(fp))
+ adios(tmpfil, "error writing to");
+
+ if (fstat(fileno(fp), &st) == NOTOK)
+ adios("failed", "fstat of %s", tmpfil);
+
+ status = 0;
+ vec[0] = mhbasename(postproc);
+ if (verbsw)
+ vec[vecp++] = "-verbose";
+
+ switch (sendsbr(vec, vecp, tmpfil, &st, 0, (char *)0, 0)) {
+ case DONE:
+ case NOTOK:
+ status++;
+ break;
+ case OK:
+ break;
+ }
+
+ fclose(fp);
+ if (unlink(tmpfil) == -1)
+ advise(NULL, "unable to remove temp file %s", tmpfil);
+ done(status);
+ return 1;