/*
- * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
- * Copyright (C) 1998,1999 Thomas Roessler <roessler@does-not-exist.org>
+ * Copyright (C) 1996-7,2000 Michael R. Elkins <me@mutt.org>
+ * Copyright (C) 1998-2005 Thomas Roessler <roessler@does-not-exist.org>
* Copyright (C) 2004 g10 Code GmbH
*
* This program is free software; you can redistribute it and/or modify
int lineno = 0;
size_t linelen;
- while ((line = mutt_read_line (line, &linelen, fpin, &lineno)) != NULL)
+ while ((line = mutt_read_line (line, &linelen, fpin, &lineno, 0)) != NULL)
{
if (regexec (PgpGoodSign.rx, line, 0, NULL, 0) == 0)
{
short maybe_goodsig = 1;
short have_any_sigs = 0;
+ char *gpgcharset = NULL;
char body_charset[STRING];
mutt_get_body_charset (body_charset, sizeof (body_charset), m);
clearsign = 1;
needpass = 0;
}
- else if (!option (OPTDONTHANDLEPGPKEYS) &&
- mutt_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15) == 0)
+ else if (!mutt_strcmp ("PUBLIC KEY BLOCK-----\n", buf + 15))
{
needpass = 0;
- pgp_keyblock =1;
+ pgp_keyblock = 1;
}
else
{
&& (mutt_strcmp ("-----END PGP SIGNATURE-----\n", buf) == 0
|| mutt_strcmp ("-----END PGP PUBLIC KEY BLOCK-----\n",buf) == 0)))
break;
+ /* remember optional Charset: armor header as defined by RfC4880 */
+ if (mutt_strncmp ("Charset: ", buf, 9) == 0)
+ {
+ size_t l = 0;
+ gpgcharset = safe_strdup (buf + 9);
+ if ((l = mutt_strlen (gpgcharset)) > 0 && gpgcharset[l-1] == '\n')
+ gpgcharset[l-1] = 0;
+ if (mutt_check_charset (gpgcharset, 0) < 0)
+ mutt_str_replace (&gpgcharset, "UTF-8");
+ }
}
/* leave tmpfp open in case we still need it - but flush it! */
state_attach_puts (_("[-- End of PGP output --]\n\n"), s);
}
+ if (pgp_use_gpg_agent())
+ mutt_need_hard_redraw ();
}
/* treat empty result as sign of failure */
}
/*
- * Now, copy cleartext to the screen. NOTE - we expect that PGP
- * outputs utf-8 cleartext. This may not always be true, but it
- * seems to be a reasonable guess.
+ * Now, copy cleartext to the screen.
*/
if(s->flags & M_DISPLAY)
{
FGETCONV *fc;
int c;
+ char *expected_charset = gpgcharset && *gpgcharset ? gpgcharset : "utf-8";
+
+ dprint(4,(debugfile,"pgp: recoding inline from [%s] to [%s]\n",
+ expected_charset, Charset));
+
rewind (pgpout);
state_set_prefix (s);
- fc = fgetconv_open (pgpout, "utf-8", Charset, 0);
+ fc = fgetconv_open (pgpout, expected_charset, Charset, M_ICONV_HOOK_FROM);
while ((c = fgetconv (fc)) != EOF)
state_prefix_putc (c, s);
fgetconv_close (&fc);
state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s);
}
}
+#if 0
else
{
+ /* why would we want to display this at all? */
/* XXX - we may wish to recode here */
if (s->prefix)
state_puts (s->prefix, s);
state_puts (buf, s);
}
+#endif
}
rc = 0;
safe_fclose (&pgpout);
mutt_unlink (outfile);
}
-
+
+ FREE(&gpgcharset);
+
if (needpass == -1)
{
state_attach_puts (_("[-- Error: could not find beginning of PGP message! --]\n\n"), s);
fseeko (s->fpin, sigbdy->offset, 0);
mutt_copy_bytes (s->fpin, fp, sigbdy->length);
- fclose (fp);
+ safe_fclose (&fp);
mutt_mktemp(pgperrfile);
if(!(pgperr = safe_fopen(pgperrfile, "w+")))
if (Context->hdrs[Context->v2r[i]]->security & PGPENCRYPT
&& !pgp_valid_passphrase())
{
- fclose (fpout);
+ safe_fclose (&fpout);
goto bailout;
}
mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
mutt_parse_mime_message (Context, h);
if (h->security & PGPENCRYPT && !pgp_valid_passphrase())
{
- fclose (fpout);
+ safe_fclose (&fpout);
goto bailout;
}
mutt_copy_message (fpout, Context, h, M_CM_DECODE|M_CM_CHARCONV, 0);
}
- fclose (fpout);
+ safe_fclose (&fpout);
mutt_endwin (NULL);
pgp_invoke_import (tempfname);
mutt_any_key_to_continue (NULL);
mutt_body_handler (top, &s);
- fclose (tempfp);
+ safe_fclose (&tempfp);
pgp_invoke_import (tempfname);
mutt_any_key_to_continue (NULL);
if((pgptmp = safe_fopen (pgptmpfile, "w")) == NULL)
{
mutt_perror (pgptmpfile);
- fclose(pgperr);
+ safe_fclose (&pgperr);
return NULL;
}
fseeko (s->fpin, a->offset, 0);
mutt_copy_bytes (s->fpin, pgptmp, a->length);
- fclose (pgptmp);
+ safe_fclose (&pgptmp);
if ((thepid = pgp_invoke_decrypt (&pgpin, &pgpout, NULL, -1, -1,
fileno (pgperr), pgptmpfile)) == -1)
{
- fclose (pgperr);
+ safe_fclose (&pgperr);
unlink (pgptmpfile);
if (s->flags & M_DISPLAY)
state_attach_puts (_("[-- Error: could not create a PGP subprocess! --]\n\n"), s);
if (!pgp_use_gpg_agent())
fputs (PgpPass, pgpin);
fputc ('\n', pgpin);
- fclose(pgpin);
+ safe_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);
+ safe_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);
+ safe_fclose (&pgperr);
fflush (fpout);
rewind (fpout);
-
+
+ if (pgp_use_gpg_agent())
+ mutt_need_hard_redraw ();
+
if (fgetc (fpout) == EOF)
{
mutt_error _("Decryption failed");
rc = -1;
}
- fclose (fpout);
+ safe_fclose (&fpout);
mutt_unlink(tempfile);
return rc;
if ((sfp = safe_fopen(signedfile, "w")) == NULL)
{
mutt_perror(signedfile);
- fclose(fp);
+ safe_fclose (&fp);
unlink(sigfile);
return NULL;
}
mutt_write_mime_header (a, sfp);
fputc ('\n', sfp);
mutt_write_mime_body (a, sfp);
- fclose(sfp);
+ safe_fclose (&sfp);
if ((thepid = pgp_invoke_sign (&pgpin, &pgpout, &pgperr,
-1, -1, -1, signedfile)) == -1)
{
mutt_perror _("Can't open PGP subprocess!");
- fclose(fp);
+ safe_fclose (&fp);
unlink(sigfile);
unlink(signedfile);
return NULL;
if (!pgp_use_gpg_agent())
fputs(PgpPass, pgpin);
fputc('\n', pgpin);
- fclose(pgpin);
+ safe_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);
+ safe_fclose (&pgperr);
+ safe_fclose (&pgpout);
unlink (signedfile);
if (fclose (fp) != 0)
*/
char *pgp_findKeys (ADDRESS *to, ADDRESS *cc, ADDRESS *bcc)
{
- char *keyID, *keylist = NULL, *t;
+ char *keyID, *keylist = NULL;
size_t keylist_size = 0;
size_t keylist_used = 0;
ADDRESS *tmp = NULL, *addr = NULL;
default: abort ();
}
- *last = rfc822_cpy_adr (p);
+ *last = rfc822_cpy_adr (p, 0);
while (*last)
last = &((*last)->next);
}
}
/* check for e-mail address */
- if ((t = strchr (keyID, '@')) &&
+ if (strchr (keyID, '@') &&
(addr = rfc822_parse_adrlist (NULL, keyID)))
{
if (fqdn) rfc822_qualify (addr, fqdn);
{
mutt_perror (pgperrfile);
unlink(tempfile);
- fclose(fpout);
+ safe_fclose (&fpout);
return NULL;
}
unlink (pgperrfile);
{
mutt_perror(pgpinfile);
unlink(tempfile);
- fclose(fpout);
- fclose(pgperr);
+ safe_fclose (&fpout);
+ safe_fclose (&pgperr);
return NULL;
}
mutt_write_mime_header (a, fptmp);
fputc ('\n', fptmp);
mutt_write_mime_body (a, fptmp);
- fclose(fptmp);
+ safe_fclose (&fptmp);
if ((thepid = pgp_invoke_encrypt (&pgpin, NULL, NULL, -1,
fileno (fpout), fileno (pgperr),
pgpinfile, keylist, sign)) == -1)
{
- fclose (pgperr);
+ safe_fclose (&pgperr);
unlink(pgpinfile);
return (NULL);
}
fputs (PgpPass, pgpin);
fputc ('\n', pgpin);
}
- fclose(pgpin);
+ safe_fclose (&pgpin);
if(mutt_wait_filter (thepid) && option(OPTPGPCHECKEXIT))
empty=1;
rewind (fpout);
if(!empty)
empty = (fgetc (fpout) == EOF);
- fclose (fpout);
+ safe_fclose (&fpout);
fflush (pgperr);
rewind (pgperr);
err = 1;
fputs (buf, stdout);
}
- fclose (pgperr);
+ safe_fclose (&pgperr);
/* pause if there is any error output from PGP */
if (err)
if ((pgpin = safe_fopen (pgpinfile, "w")) == NULL)
{
mutt_perror (pgpinfile);
- fclose (fp);
+ safe_fclose (&fp);
return NULL;
}
mutt_copy_stream (fp, pgpin);
}
safe_fclose (&fp);
- fclose (pgpin);
+ safe_fclose (&pgpin);
mutt_mktemp (pgpoutfile);
mutt_mktemp (pgperrfile);
unlink (pgpinfile);
if (pgpout)
{
- fclose (pgpout);
+ safe_fclose (&pgpout);
unlink (pgpoutfile);
}
return NULL;
pgpinfile, keylist, flags)) == -1)
{
mutt_perror _("Can't invoke PGP");
- fclose (pgpout);
- fclose (pgperr);
+ safe_fclose (&pgpout);
+ safe_fclose (&pgperr);
mutt_unlink (pgpinfile);
unlink (pgpoutfile);
return NULL;
*PgpPass = 0;
if (flags & SIGN)
fprintf (pgpin, "%s\n", PgpPass);
- fclose (pgpin);
+ safe_fclose (&pgpin);
if(mutt_wait_filter (thepid) && option(OPTPGPCHECKEXIT))
empty=1;
if(!empty)
empty = (fgetc (pgpout) == EOF);
- fclose (pgpout);
+ safe_fclose (&pgpout);
err = 0;
fputs (buff, stdout);
}
- fclose (pgperr);
+ safe_fclose (&pgperr);
if (err)
mutt_any_key_to_continue (NULL);