* a message.
*/
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/ascii.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
#include <lib-mime/mime.h>
+#include <lib-sys/unix.h>
+
+#include <lib-ui/curses.h>
+#include <lib-ui/enter.h>
+#include <lib-ui/menu.h>
+#include <lib-mx/mx.h>
-#include "mutt.h"
-#include "enter.h"
#include "handler.h"
-#include "mutt_curses.h"
#include "pgp.h"
#include "copy.h"
#include "attach.h"
-#include "lib/debug.h"
-
-#include <sys/wait.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <ctype.h>
-
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
-
#include "crypt.h"
-#include "mutt_menu.h"
char PgpPass[LONG_STRING];
void pgp_void_passphrase (void)
{
- p_clear(PgpPass, sizeof(PgpPass));
+ p_clear(PgpPass, countof(PgpPass));
PgpExptime = 0;
}
if (PgpGoodSign.pattern) {
char *line = NULL;
int lineno = 0;
- size_t linelen;
+ ssize_t linelen;
while ((line = mutt_read_line (line, &linelen, fpin, &lineno)) != NULL) {
if (regexec (PgpGoodSign.rx, line, 0, NULL, 0) == 0) {
- debug_print (2, ("\"%s\" matches regexp.\n", line));
rv = 0;
}
- else
- debug_print (2, ("\"%s\" doesn't match regexp.\n", line));
if (strncmp (line, "[GNUPG:] ", 9) == 0)
continue;
p_delete(&line);
}
else {
- debug_print (2, ("No pattern.\n"));
mutt_copy_stream (fpin, fpout);
rv = 1;
}
char buf[HUGE_STRING];
short complete, armor_header;
- FGETCONV *fc;
+ fgetconv_t *fc;
rewind (fpin);
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);
}
pgp_copy_clearsigned (tmpfp, s, body_charset);
}
else if (pgpout) {
- FGETCONV *fc;
- int c;
+ fgetconv_t *fc;
rewind (pgpout);
state_set_prefix (s);
/* fix the content type */
- mutt_set_parameter ("format", "fixed", &b->parameter);
+ parameter_setval(&b->parameter, "format", "fixed");
if (enc)
- mutt_set_parameter ("x-action", "pgp-encrypted", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-encrypted");
else if (sgn)
- mutt_set_parameter ("x-action", "pgp-signed", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-signed");
else if (key)
- mutt_set_parameter ("x-action", "pgp-keys", &b->parameter);
+ parameter_setval(&b->parameter, "x-action", "pgp-keys");
return 1;
}
mutt_copy_bytes (s->fpin, fp, sigbdy->length);
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;
if ((rv = mutt_wait_filter (thepid)))
badsig = -1;
-
- debug_print (1, ("mutt_wait_filter returned %d.\n", rv));
}
safe_fclose (&pgperr);
mutt_unlink (sigfile);
mutt_unlink (pgperrfile);
- debug_print (1, ("returning %d.\n", badsig));
-
return badsig;
}
/* Extract pgp public keys from messages or attachments */
-void pgp_extract_keys_from_messages (HEADER * h)
-{
- int i;
- char tempfname[_POSIX_PATH_MAX];
- FILE *fpout;
-
- if (h) {
- mutt_parse_mime_message (Context, h);
- if (h->security & PGPENCRYPT && !pgp_valid_passphrase ())
- return;
- }
-
- mutt_mktemp (tempfname);
- if (!(fpout = safe_fopen (tempfname, "w"))) {
- mutt_perror (tempfname);
- return;
- }
-
- set_option (OPTDONTHANDLEPGPKEYS);
-
- if (!h) {
- for (i = 0; i < Context->vcount; i++) {
- if (Context->hdrs[Context->v2r[i]]->tagged) {
- mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]);
- if (Context->hdrs[Context->v2r[i]]->security & PGPENCRYPT
- && !pgp_valid_passphrase ()) {
- fclose (fpout);
- goto bailout;
- }
- mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
- M_CM_DECODE | M_CM_CHARCONV, 0);
- }
- }
- }
- else {
- mutt_parse_mime_message (Context, h);
- if (h->security & PGPENCRYPT && !pgp_valid_passphrase ()) {
- fclose (fpout);
- goto bailout;
- }
- mutt_copy_message (fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0);
- }
-
- fclose (fpout);
- mutt_endwin (NULL);
- pgp_invoke_import (tempfname);
- mutt_any_key_to_continue (NULL);
-
-bailout:
-
- mutt_unlink (tempfname);
- unset_option (OPTDONTHANDLEPGPKEYS);
-
-}
-
static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top)
{
STATE 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;
}
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 == NULL) {
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 == NULL) {
mutt_perror (pgptmpfile);
fclose (pgperr);
return NULL;
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"),
state_attach_puts (_("[-- End of PGP/MIME encrypted data --]\n"), s);
}
- mutt_free_body (&tattach);
+ body_list_wipe(&tattach);
/* clear 'Invoking...' message, since there's no error */
mutt_message _("PGP message successfully decrypted.");
} else {
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);
unlink (sigfile);
return (NULL); /* fatal error while signing */
}
- t = mutt_new_body ();
+ t = body_new();
t->type = TYPEMULTIPART;
t->subtype = m_strdup("signed");
t->encoding = ENC7BIT;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol", "application/pgp-signature", &t->parameter);
- mutt_set_parameter ("micalg", pgp_micalg (sigfile), &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol", "application/pgp-signature");
+ parameter_setval(&t->parameter, "micalg", pgp_micalg (sigfile));
t->parts = a;
a = t;
- t->parts->next = mutt_new_body ();
+ t->parts->next = body_new();
t = t->parts->next;
t->type = TYPEAPPLICATION;
t->subtype = m_strdup("pgp-signature");
*/
char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc)
{
- char *keyID, *keylist = NULL, *t;
+ char *keylist = NULL, *t;
+ const char *keyID;
size_t keylist_size = 0;
size_t keylist_used = 0;
address_t *tmp = NULL, *addr = NULL;
if (fqdn)
rfc822_qualify (tmp, fqdn);
- tmp = mutt_remove_duplicates (tmp);
+ address_list_uniq(tmp);
for (p = tmp; p; p = p->next) {
char buf[LONG_STRING];
}
else if (r == -1) {
p_delete(&keylist);
- address_delete (&tmp);
- address_delete (&addr);
+ address_list_wipe(&tmp);
+ address_list_wipe(&addr);
return NULL;
}
}
if ((key = pgp_ask_for_key (buf, q->mailbox,
KEYFLAG_CANENCRYPT, PGP_PUBRING)) == NULL) {
p_delete(&keylist);
- address_delete (&tmp);
- address_delete (&addr);
+ address_list_wipe(&tmp);
+ address_list_wipe(&addr);
return NULL;
}
}
keylist_used = m_strlen(keylist);
pgp_free_key (&key);
- address_delete (&addr);
+ address_list_wipe(&addr);
}
- address_delete (&tmp);
+ address_list_wipe(&tmp);
return (keylist);
}
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);
- unlink (tempfile);
fclose (fpout);
+ unlink (tempfile);
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);
- unlink (tempfile);
fclose (fpout);
+ unlink (tempfile);
fclose (pgperr);
+ unlink (pgperrfile);
return NULL;
}
return (NULL);
}
- t = mutt_new_body ();
+ t = body_new();
t->type = TYPEMULTIPART;
t->subtype = m_strdup("encrypted");
t->encoding = ENC7BIT;
t->use_disp = 0;
t->disposition = DISPINLINE;
- mutt_generate_boundary (&t->parameter);
- mutt_set_parameter ("protocol", "application/pgp-encrypted", &t->parameter);
+ parameter_set_boundary(&t->parameter);
+ parameter_setval(&t->parameter, "protocol", "application/pgp-encrypted");
- t->parts = mutt_new_body ();
+ t->parts = body_new();
t->parts->type = TYPEAPPLICATION;
t->parts->subtype = m_strdup("pgp-encrypted");
t->parts->encoding = ENC7BIT;
- t->parts->next = mutt_new_body ();
+ t->parts->next = body_new();
t->parts->next->type = TYPEAPPLICATION;
t->parts->next->subtype = m_strdup("octet-stream");
t->parts->next->encoding = ENC7BIT;
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);
return NULL;
else
from_charset = Charset;
- if (!mutt_is_us_ascii (body_charset)) {
+ if (!charset_is_us_ascii (body_charset)) {
int c;
- FGETCONV *fc;
+ fgetconv_t *fc;
if (flags & ENCRYPT)
send_charset = "us-ascii";
safe_fclose (&fp);
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);
+ fclose (pgpin);
unlink (pgpinfile);
if (pgpout) {
fclose (pgpout);
unlink (pgpoutfile);
}
+ if (pgperr) {
+ fclose(pgperr);
+ unlink(pgperrfile);
+ }
return NULL;
}
return NULL;
}
- b = mutt_new_body ();
+ b = body_new();
b->encoding = ENC7BIT;
b->type = TYPETEXT;
b->subtype = m_strdup("plain");
- mutt_set_parameter ("x-action",
- flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed",
- &b->parameter);
- mutt_set_parameter ("charset", send_charset, &b->parameter);
+ parameter_setval(&b->parameter, "x-action",
+ flags & ENCRYPT ? "pgp-encrypted" : "pgp-signed");
+ parameter_setval(&b->parameter, "charset", send_charset);
b->filename = m_strdup(pgpoutfile);
-#if 0
- /* The following is intended to give a clue to some completely brain-dead
- * "mail environments" which are typically used by large corporations.
- */
-
- b->d_filename = m_strdup("msg.pgp");
- b->use_disp = 1;
-
-#endif
-
b->disposition = DISPINLINE;
b->unlink = 1;