#include <lib-ui/curses.h>
#include <lib-ui/enter.h>
#include <lib-ui/menu.h>
+#include <lib-mx/mx.h>
-#include "mx.h"
#include "handler.h"
#include "pgp.h"
#include "copy.h"
have_any_sigs = have_any_sigs || (clearsign && (s->flags & M_VERIFY));
/* Copy PGP material to temporary file */
- mutt_mktemp (tmpfname);
- if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL) {
+ tmpfp = m_tempfile(tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL);
+ if (tmpfp == NULL) {
mutt_perror (tmpfname);
return (-1);
}
/* Invoke PGP if needed */
if (!clearsign || (s->flags & M_VERIFY)) {
- mutt_mktemp (outfile);
- if ((pgpout = safe_fopen (outfile, "w+")) == NULL) {
- mutt_perror (tmpfname);
+ pgpout = m_tempfile(outfile, sizeof(outfile), NONULL(Tempdir), NULL);
+ if (pgpout == NULL) {
+ mutt_perror (outfile);
return (-1);
}
if ((thepid = pgp_invoke_decode (&pgpin, NULL, &pgperr, -1,
fileno (pgpout), -1, tmpfname,
needpass)) == -1) {
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
maybe_goodsig = 0;
pgpin = NULL;
pgperr = NULL;
fprintf (pgpin, "%s\n", PgpPass);
}
- safe_fclose (&pgpin);
+ m_fclose(&pgpin);
if (s->flags & M_DISPLAY) {
crypt_current_time (s, "PGP");
rc = pgp_copy_checksig (pgperr, s->fpout);
}
- safe_fclose (&pgperr);
+ m_fclose(&pgperr);
rv = mutt_wait_filter (thepid);
if (s->flags & M_DISPLAY) {
m->goodsig = (maybe_goodsig && have_any_sigs);
if (tmpfp) {
- safe_fclose (&tmpfp);
+ m_fclose(&tmpfp);
mutt_unlink (tmpfname);
}
if (pgpout) {
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
mutt_unlink (outfile);
}
key = 1;
}
}
- safe_fclose (&tfp);
+ m_fclose(&tfp);
unlink (tempfile);
if (!enc && !sgn && !key)
fseeko (s->fpin, sigbdy->offset, 0);
mutt_copy_bytes (s->fpin, fp, sigbdy->length);
- fclose (fp);
+ m_fclose(&fp);
- mutt_mktemp (pgperrfile);
- if (!(pgperr = safe_fopen (pgperrfile, "w+"))) {
+ pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+ if (pgperr == NULL) {
mutt_perror (pgperrfile);
unlink (sigfile);
return -1;
badsig = 0;
- safe_fclose (&pgpout);
+ m_fclose(&pgpout);
fflush (pgperr);
rewind (pgperr);
badsig = -1;
}
- safe_fclose (&pgperr);
+ m_fclose(&pgperr);
state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
FILE *tempfp;
char tempfname[_POSIX_PATH_MAX];
- mutt_mktemp (tempfname);
- if (!(tempfp = safe_fopen (tempfname, "w"))) {
+ tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(Tempdir), NULL);
+ if (tempfp == NULL) {
mutt_perror (tempfname);
return;
}
mutt_body_handler (top, &s);
- fclose (tempfp);
+ m_fclose(&tempfp);
pgp_invoke_import (tempfname);
mutt_any_key_to_continue (NULL);
pid_t thepid;
int rv;
- mutt_mktemp (pgperrfile);
- if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL) {
+ pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+ if (!pgperr) {
mutt_perror (pgperrfile);
return NULL;
}
unlink (pgperrfile);
- mutt_mktemp (pgptmpfile);
- if ((pgptmp = safe_fopen (pgptmpfile, "w")) == NULL) {
+ pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(Tempdir), NULL);
+ if (!pgptmp) {
mutt_perror (pgptmpfile);
- fclose (pgperr);
+ m_fclose(&pgperr);
return NULL;
}
fseeko (s->fpin, a->offset, 0);
mutt_copy_bytes (s->fpin, pgptmp, a->length);
- fclose (pgptmp);
+ m_fclose(&pgptmp);
if ((thepid = pgp_invoke_decrypt (&pgpin, &pgpout, NULL, -1, -1,
fileno (pgperr), pgptmpfile)) == -1) {
- fclose (pgperr);
+ m_fclose(&pgperr);
unlink (pgptmpfile);
if (s->flags & M_DISPLAY)
state_attach_puts (_
if (!pgp_use_gpg_agent ())
fputs (PgpPass, pgpin);
fputc ('\n', pgpin);
- fclose (pgpin);
+ m_fclose(&pgpin);
/* Read the output from PGP, and make sure to change CRLF to LF, otherwise
* read_mime_header has a hard time parsing the message.
fputs (buf, fpout);
}
- fclose (pgpout);
+ m_fclose(&pgpout);
rv = mutt_wait_filter (thepid);
mutt_unlink (pgptmpfile);
p->goodsig = 0;
state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
}
- fclose (pgperr);
+ m_fclose(&pgperr);
fflush (fpout);
rewind (fpout);
p_clear(&s, 1);
s.fpin = fpin;
- mutt_mktemp (tempfile);
- if ((*fpout = safe_fopen (tempfile, "w+")) == NULL) {
+ *fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+ if (*fpout == NULL) {
mutt_perror (tempfile);
return (-1);
}
*/
a = a->next;
- mutt_mktemp (tempfile);
- if ((fpout = safe_fopen (tempfile, "w+")) == NULL) {
+ fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+ if (fpout == NULL) {
if (s->flags & M_DISPLAY)
state_attach_puts (_
("[-- Error: could not create temporary file! --]\n"),
rc = -1;
}
- fclose (fpout);
+ m_fclose(&fpout);
mutt_unlink (tempfile);
return (rc);
convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
- mutt_mktemp (sigfile);
- if ((fp = safe_fopen (sigfile, "w")) == NULL) {
+ fp = m_tempfile(sigfile, sizeof(sigfile), NONULL(Tempdir), NULL);
+ if (fp == NULL) {
return (NULL);
}
- mutt_mktemp (signedfile);
- if ((sfp = safe_fopen (signedfile, "w")) == NULL) {
+ sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(Tempdir), NULL);
+ if (sfp == NULL) {
mutt_perror (signedfile);
- fclose (fp);
+ m_fclose(&fp);
unlink (sigfile);
return NULL;
}
mutt_write_mime_header (a, sfp);
fputc ('\n', sfp);
mutt_write_mime_body (a, sfp);
- fclose (sfp);
+ m_fclose(&sfp);
if ((thepid = pgp_invoke_sign (&pgpin, &pgpout, &pgperr,
-1, -1, -1, signedfile)) == -1) {
mutt_perror (_("Can't open PGP subprocess!"));
- fclose (fp);
+ m_fclose(&fp);
unlink (sigfile);
unlink (signedfile);
return NULL;
if (!pgp_use_gpg_agent ())
fputs (PgpPass, pgpin);
fputc ('\n', pgpin);
- fclose (pgpin);
+ m_fclose(&pgpin);
/*
* Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as
if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT))
empty = 1;
- fclose (pgperr);
- fclose (pgpout);
+ m_fclose(&pgperr);
+ m_fclose(&pgpout);
unlink (signedfile);
- if (fclose (fp) != 0) {
+ if (m_fclose(&fp) != 0) {
mutt_perror ("fclose");
unlink (sigfile);
return (NULL);
int empty = 0;
pid_t thepid;
- mutt_mktemp (tempfile);
- if ((fpout = safe_fopen (tempfile, "w+")) == NULL) {
+ fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL);
+ if (fpout == NULL) {
mutt_perror (tempfile);
return (NULL);
}
- mutt_mktemp (pgperrfile);
- if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL) {
+ pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+ if (pgperr == NULL) {
mutt_perror (pgperrfile);
+ m_fclose(&fpout);
unlink (tempfile);
- fclose (fpout);
return NULL;
}
unlink (pgperrfile);
- mutt_mktemp (pgpinfile);
- if ((fptmp = safe_fopen (pgpinfile, "w")) == NULL) {
+ fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL);
+ if (fptmp == NULL) {
mutt_perror (pgpinfile);
+ m_fclose(&fpout);
unlink (tempfile);
- fclose (fpout);
- fclose (pgperr);
+ m_fclose(&pgperr);
+ unlink (pgperrfile);
return NULL;
}
mutt_write_mime_header (a, fptmp);
fputc ('\n', fptmp);
mutt_write_mime_body (a, fptmp);
- fclose (fptmp);
+ m_fclose(&fptmp);
if ((thepid = pgp_invoke_encrypt (&pgpin, NULL, NULL, -1,
fileno (fpout), fileno (pgperr),
pgpinfile, keylist, sign)) == -1) {
- fclose (pgperr);
+ m_fclose(&pgperr);
unlink (pgpinfile);
return (NULL);
}
fputs (PgpPass, pgpin);
fputc ('\n', pgpin);
}
- fclose (pgpin);
+ m_fclose(&pgpin);
if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT))
empty = 1;
rewind (fpout);
if (!empty)
empty = (fgetc (fpout) == EOF);
- fclose (fpout);
+ m_fclose(&fpout);
fflush (pgperr);
rewind (pgperr);
err = 1;
fputs (buf, stdout);
}
- fclose (pgperr);
+ m_fclose(&pgperr);
/* pause if there is any error output from PGP */
if (err)
return NULL;
}
- mutt_mktemp (pgpinfile);
- if ((pgpin = safe_fopen (pgpinfile, "w")) == NULL) {
+ pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL);
+ if (pgpin == NULL) {
mutt_perror (pgpinfile);
- fclose (fp);
+ m_fclose(&fp);
return NULL;
}
send_charset = "us-ascii";
mutt_copy_stream (fp, pgpin);
}
- safe_fclose (&fp);
- fclose (pgpin);
+ m_fclose(&fp);
+ m_fclose(&pgpin);
- mutt_mktemp (pgpoutfile);
- mutt_mktemp (pgperrfile);
- if ((pgpout = safe_fopen (pgpoutfile, "w+")) == NULL ||
- (pgperr = safe_fopen (pgperrfile, "w+")) == NULL) {
+ pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(Tempdir), NULL);
+ pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL);
+ if (pgpout == NULL || pgperr == NULL) {
mutt_perror (pgpout ? pgperrfile : pgpoutfile);
+ m_fclose(&pgpin);
unlink (pgpinfile);
- if (pgpout) {
- fclose (pgpout);
- unlink (pgpoutfile);
- }
+ m_fclose(&pgpout);
+ unlink (pgpoutfile);
+ m_fclose(&pgperr);
+ unlink(pgperrfile);
return NULL;
}
pgpinfile, keylist, flags)) == -1) {
mutt_perror (_("Can't invoke PGP"));
- fclose (pgpout);
- fclose (pgperr);
+ m_fclose(&pgpout);
+ m_fclose(&pgperr);
mutt_unlink (pgpinfile);
unlink (pgpoutfile);
return NULL;
*PgpPass = 0;
if (flags & SIGN)
fprintf (pgpin, "%s\n", PgpPass);
- fclose (pgpin);
+ m_fclose(&pgpin);
if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT))
empty = 1;
if (!empty)
empty = (fgetc (pgpout) == EOF);
- fclose (pgpout);
+ m_fclose(&pgpout);
err = 0;
fputs (buff, stdout);
}
- fclose (pgperr);
+ m_fclose(&pgperr);
if (err)
mutt_any_key_to_continue (NULL);