From 73311dac5b730c0cab529c0143043bb350c3c3d1 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 26 Mar 2002 20:34:23 +0000 Subject: [PATCH] OK, I'm giving up: pgp_create_traditional now creates text/plain; x-mutt-action={pgp-encrypt,pgp-sign}. --- commands.c | 2 +- crypt.c | 7 ++++++- handler.c | 7 ++++++- pgp.c | 42 ++++++++++++++++++++++++++++++++---------- pgpinvoke.c | 4 ++-- sendlib.c | 2 +- 6 files changed, 48 insertions(+), 16 deletions(-) diff --git a/commands.c b/commands.c index d9bcb7190..85874b042 100644 --- a/commands.c +++ b/commands.c @@ -627,7 +627,7 @@ static void set_copy_flags (HEADER *hdr, int decode, int decrypt, int *cmflags, *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_PGP; } - else if (mutt_is_application_pgp(hdr->content) & ENCRYPT) + else if (mutt_is_application_pgp (hdr->content) & ENCRYPT) decode = 1; #endif #if defined(HAVE_PGP) && defined(HAVE_SMIME) diff --git a/crypt.c b/crypt.c index 244ba4ca0..ceb23e747 100644 --- a/crypt.c +++ b/crypt.c @@ -180,7 +180,7 @@ int mutt_protect (HEADER *msg, char *keylist) if (msg->security & APPLICATION_PGP) { if ((msg->content->type == TYPETEXT) && - !mutt_strcasecmp (msg->content->subtype, "plain") && + !ascii_strcasecmp (msg->content->subtype, "plain") && ((flags & ENCRYPT) || (msg->content->content && msg->content->content->hibin == 0))) { if ((i = query_quadoption (OPT_PGPTRADITIONAL, _("Create an application/pgp message?"))) == -1) @@ -360,6 +360,11 @@ int crypt_query (BODY *m) if (t && m->badsig) t |= BADSIGN; #endif } +#ifdef HAVE_PGP + else if (m->type == TYPETEXT) + t |= mutt_is_application_pgp (m); +#endif + if (m->type == TYPEMULTIPART) { diff --git a/handler.c b/handler.c index a09ed403c..7b8e2df51 100644 --- a/handler.c +++ b/handler.c @@ -1785,6 +1785,11 @@ void mutt_body_handler (BODY *b, STATE *s) /* avoid copying this part twice since removing the transfer-encoding is * the only operation needed. */ +#ifdef HAVE_PGP + if (mutt_is_application_pgp (b)) + handler = pgp_application_pgp_handler; + else +#endif if (ascii_strcasecmp ("flowed", mutt_get_parameter ("format", b->parameter)) == 0) handler = text_plain_flowed_handler; else @@ -1854,7 +1859,7 @@ void mutt_body_handler (BODY *b, STATE *s) else if (b->type == TYPEAPPLICATION) { #ifdef HAVE_PGP - if (mutt_is_application_pgp(b)) + if (mutt_is_application_pgp (b)) handler = pgp_application_pgp_handler; #endif /* HAVE_PGP */ #ifdef HAVE_SMIME diff --git a/pgp.c b/pgp.c index 5f4b36500..920ebd05e 100644 --- a/pgp.c +++ b/pgp.c @@ -441,7 +441,7 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) if (tagged_only && !b->tagged) return 0; - + mutt_mktemp (tempfile); if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0) { @@ -454,7 +454,7 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) unlink (tempfile); return 0; } - + while (fgets (buf, sizeof (buf), tfp)) { if (mutt_strncmp ("-----BEGIN PGP ", buf, 15) == 0) @@ -465,7 +465,6 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) sgn = 1; } } - safe_fclose (&tfp); unlink (tempfile); @@ -486,12 +485,18 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only) int pgp_check_traditional (FILE *fp, BODY *b, int tagged_only) { int rv = 0; + int r; for (; b; b = b->next) { if (is_multipart (b)) rv = pgp_check_traditional (fp, b->parts, tagged_only) || rv; else if (b->type == TYPETEXT) - rv = pgp_check_traditional_one_body (fp, b, tagged_only) || rv; + { + if ((r = mutt_is_application_pgp (b))) + rv = rv || r; + else + rv = pgp_check_traditional_one_body (fp, b, tagged_only) || rv; + } } return rv; @@ -537,6 +542,14 @@ int mutt_is_application_pgp (BODY *m) if (!ascii_strcasecmp (m->subtype, "pgp-keys")) t |= PGPKEY; } + else if (m->type == TYPETEXT && ascii_strcasecmp ("plain", m->subtype) == 0) + { + if ((p = mutt_get_parameter ("x-mutt-action", m->parameter)) && + !ascii_strcasecmp ("pgp-sign", p)) + t |= PGPSIGN; + else if (p && !ascii_strcasecmp ("pgp-encrypt", p)) + t |= PGPENCRYPT; + } return t; } @@ -1264,6 +1277,8 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) char pgpoutfile[_POSIX_PATH_MAX]; char pgperrfile[_POSIX_PATH_MAX]; char pgpinfile[_POSIX_PATH_MAX]; + + char send_charset[STRING]; FILE *pgpout = NULL, *pgperr = NULL, *pgpin = NULL; FILE *fp; @@ -1274,6 +1289,11 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) char buff[STRING]; pid_t thepid; + + if (a->type != TYPETEXT) + return NULL; + if (ascii_strcasecmp (a->subtype, "plain")) + return NULL; if ((fp = fopen (a->filename, "r")) == NULL) { @@ -1362,13 +1382,15 @@ BODY *pgp_traditional_encryptsign (BODY *a, int flags, char *keylist) b->encoding = ENC7BIT; - b->type = TYPEAPPLICATION; - b->subtype = safe_strdup ("pgp"); - - mutt_set_parameter ("format", "text", &b->parameter); - mutt_set_parameter ("x-action", flags & ENCRYPT ? "encrypt" : "sign", + b->type = TYPETEXT; + b->subtype = safe_strdup ("plain"); + + mutt_set_parameter ("x-mutt-action", flags & ENCRYPT ? "pgp-encrypt" : "pgp-sign", &b->parameter); - + mutt_set_parameter ("charset", mutt_get_body_charset (send_charset, + sizeof (send_charset), a), + &b->parameter); + b->filename = safe_strdup (pgpoutfile); /* The following is intended to give a clue to some completely brain-dead diff --git a/pgpinvoke.c b/pgpinvoke.c index 250278542..c84afdf57 100644 --- a/pgpinvoke.c +++ b/pgpinvoke.c @@ -244,8 +244,8 @@ pid_t pgp_invoke_traditional (FILE **pgpin, FILE **pgpout, FILE **pgperr, { if (flags & ENCRYPT) return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, - flags & PGPSIGN ? 1 : 0, fname, NULL, PgpSignAs, uids, - flags & PGPSIGN ? PgpEncryptSignCommand : PgpEncryptOnlyCommand); + flags & SIGN ? 1 : 0, fname, NULL, PgpSignAs, uids, + flags & SIGN ? PgpEncryptSignCommand : PgpEncryptOnlyCommand); else return pgp_invoke (pgpin, pgpout, pgperr, pgpinfd, pgpoutfd, pgperrfd, 1, fname, NULL, PgpSignAs, NULL, diff --git a/sendlib.c b/sendlib.c index 3a12709a7..d5e082c97 100644 --- a/sendlib.c +++ b/sendlib.c @@ -500,7 +500,7 @@ int mutt_write_mime_body (BODY *a, FILE *f) if (a->type == TYPETEXT && (!a->noconv)) fc = fgetconv_open (fpin, Charset, - mutt_get_body_charset (send_charset, sizeof (send_charset), a), + mutt_get_body_charset (send_charset, sizeof (send_charset), a), M_ICONV_HOOK_TO); else fc = fgetconv_open (fpin, 0, 0, 0); -- 2.40.0