summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin McCarthy <kevin@8t8.us>2017-08-10 18:18:26 -0700
committerKevin McCarthy <kevin@8t8.us>2017-08-10 18:18:26 -0700
commit050125068504624fa7e70972df8f8e35122349eb (patch)
tree429a6bc269b8b7000afa1f58aa553342a31649dd
parent2a7358593861d9c721a2866ef8edb3fac6389a70 (diff)
Fix attachment check_traditional and extract_keys operations. (see #3728)
Add helpers and iterate over the actx->idx instead of the BODY structure.
-rw-r--r--crypt-gpgme.c16
-rw-r--r--crypt-gpgme.h2
-rw-r--r--crypt-mod-pgp-classic.c4
-rw-r--r--crypt-mod-pgp-gpgme.c4
-rw-r--r--crypt-mod.h2
-rw-r--r--cryptglue.c4
-rw-r--r--mutt_crypt.h2
-rw-r--r--pgp.c16
-rw-r--r--recvattach.c39
9 files changed, 58 insertions, 31 deletions
diff --git a/crypt-gpgme.c b/crypt-gpgme.c
index 14d420e9..7283e109 100644
--- a/crypt-gpgme.c
+++ b/crypt-gpgme.c
@@ -2162,7 +2162,7 @@ static int line_compare(const char *a, size_t n, const char *b)
* Implementation of `pgp_check_traditional'.
*/
-static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
+static int pgp_check_traditional_one_body (FILE *fp, BODY *b)
{
char tempfile[_POSIX_PATH_MAX];
char buf[HUGE_STRING];
@@ -2174,9 +2174,6 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
if (b->type != TYPETEXT)
return 0;
- if (tagged_only && !b->tagged)
- return 0;
-
mutt_mktemp (tempfile, sizeof (tempfile));
if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0)
{
@@ -2221,21 +2218,24 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
return 1;
}
-int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only)
+int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int just_one)
{
int rv = 0;
int r;
for (; b; b = b->next)
{
- if (is_multipart (b))
- rv = (pgp_gpgme_check_traditional (fp, b->parts, tagged_only) || rv);
+ if (!just_one && is_multipart (b))
+ rv = (pgp_gpgme_check_traditional (fp, b->parts, 0) || rv);
else if (b->type == TYPETEXT)
{
if ((r = mutt_is_application_pgp (b)))
rv = (rv || r);
else
- rv = (pgp_check_traditional_one_body (fp, b, tagged_only) || rv);
+ rv = (pgp_check_traditional_one_body (fp, b) || rv);
}
+
+ if (just_one)
+ break;
}
return rv;
}
diff --git a/crypt-gpgme.h b/crypt-gpgme.h
index 78a98410..bb283a50 100644
--- a/crypt-gpgme.h
+++ b/crypt-gpgme.h
@@ -33,7 +33,7 @@ BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist);
int pgp_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur);
int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur);
-int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only);
+int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int just_one);
void pgp_gpgme_invoke_import (const char* fname);
int pgp_gpgme_application_handler (BODY *m, STATE *s);
diff --git a/crypt-mod-pgp-classic.c b/crypt-mod-pgp-classic.c
index cb7f873c..37dd1771 100644
--- a/crypt-mod-pgp-classic.c
+++ b/crypt-mod-pgp-classic.c
@@ -76,9 +76,9 @@ static BODY *crypt_mod_pgp_make_key_attachment (char *tempf)
return pgp_make_key_attachment (tempf);
}
-static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
+static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int just_one)
{
- return pgp_check_traditional (fp, b, tagged_only);
+ return pgp_check_traditional (fp, b, just_one);
}
static BODY *crypt_mod_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist)
diff --git a/crypt-mod-pgp-gpgme.c b/crypt-mod-pgp-gpgme.c
index a3ed1cec..b56fcdba 100644
--- a/crypt-mod-pgp-gpgme.c
+++ b/crypt-mod-pgp-gpgme.c
@@ -60,9 +60,9 @@ static int crypt_mod_pgp_encrypted_handler (BODY *m, STATE *s)
return pgp_gpgme_encrypted_handler (m, s);
}
-static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
+static int crypt_mod_pgp_check_traditional (FILE *fp, BODY *b, int just_one)
{
- return pgp_gpgme_check_traditional (fp, b, tagged_only);
+ return pgp_gpgme_check_traditional (fp, b, just_one);
}
static void crypt_mod_pgp_invoke_import (const char *fname)
diff --git a/crypt-mod.h b/crypt-mod.h
index da914029..617f830d 100644
--- a/crypt-mod.h
+++ b/crypt-mod.h
@@ -39,7 +39,7 @@ typedef int (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s);
typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS *addr);
typedef int (*crypt_func_pgp_check_traditional_t) (FILE *fp, BODY *b,
- int tagged_only);
+ int just_one);
typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY *a, int flags,
char *keylist);
typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf);
diff --git a/cryptglue.c b/cryptglue.c
index fbe51bd7..c9fdd9f2 100644
--- a/cryptglue.c
+++ b/cryptglue.c
@@ -172,10 +172,10 @@ void crypt_pgp_invoke_getkeys (ADDRESS *addr)
}
/* Check for a traditional PGP message in body B. */
-int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
+int crypt_pgp_check_traditional (FILE *fp, BODY *b, int just_one)
{
if (CRYPT_MOD_CALL_CHECK (PGP, pgp_check_traditional))
- return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, tagged_only);
+ return (CRYPT_MOD_CALL (PGP, pgp_check_traditional)) (fp, b, just_one);
return 0;
}
diff --git a/mutt_crypt.h b/mutt_crypt.h
index 07c406d3..b6086111 100644
--- a/mutt_crypt.h
+++ b/mutt_crypt.h
@@ -212,7 +212,7 @@ pgp_key_t crypt_pgp_ask_for_key (char *tag, char *whatfor,
short abilities, pgp_ring_t keyring);
/* Check for a traditional PGP message in body B. */
-int crypt_pgp_check_traditional (FILE *fp, BODY *b, int tagged_only);
+int crypt_pgp_check_traditional (FILE *fp, BODY *b, int just_one);
/* fixme: needs documentation. */
BODY *crypt_pgp_traditional_encryptsign (BODY *a, int flags, char *keylist);
diff --git a/pgp.c b/pgp.c
index 653905f0..5c98e81c 100644
--- a/pgp.c
+++ b/pgp.c
@@ -615,7 +615,7 @@ out:
return rc;
}
-static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
+static int pgp_check_traditional_one_body (FILE *fp, BODY *b)
{
char tempfile[_POSIX_PATH_MAX];
char buf[HUGE_STRING];
@@ -628,9 +628,6 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
if (b->type != TYPETEXT)
return 0;
- if (tagged_only && !b->tagged)
- return 0;
-
mutt_mktemp (tempfile, sizeof (tempfile));
if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0)
{
@@ -675,21 +672,24 @@ static int pgp_check_traditional_one_body (FILE *fp, BODY *b, int tagged_only)
return 1;
}
-int pgp_check_traditional (FILE *fp, BODY *b, int tagged_only)
+int pgp_check_traditional (FILE *fp, BODY *b, int just_one)
{
int rv = 0;
int r;
for (; b; b = b->next)
{
- if (is_multipart (b))
- rv = pgp_check_traditional (fp, b->parts, tagged_only) || rv;
+ if (!just_one && is_multipart (b))
+ rv = pgp_check_traditional (fp, b->parts, 0) || rv;
else if (b->type == TYPETEXT)
{
if ((r = mutt_is_application_pgp (b)))
rv = rv || r;
else
- rv = pgp_check_traditional_one_body (fp, b, tagged_only) || rv;
+ rv = pgp_check_traditional_one_body (fp, b) || rv;
}
+
+ if (just_one)
+ break;
}
return rv;
diff --git a/recvattach.c b/recvattach.c
index 7137a763..acfafc26 100644
--- a/recvattach.c
+++ b/recvattach.c
@@ -800,6 +800,36 @@ void mutt_print_attachment_list (ATTACH_CONTEXT *actx, FILE *fp, int tag, BODY *
print_attachment_list (actx, fp, tag, top, &state);
}
+static void recvattach_extract_pgp_keys (ATTACH_CONTEXT *actx, MUTTMENU *menu)
+{
+ int i;
+
+ if (!menu->tagprefix)
+ crypt_pgp_extract_keys_from_attachment_list (CURATTACH->fp, 0, CURATTACH->content);
+ else
+ {
+ for (i = 0; i < actx->idxlen; i++)
+ if (actx->idx[i]->content->tagged)
+ crypt_pgp_extract_keys_from_attachment_list (actx->idx[i]->fp, 0,
+ actx->idx[i]->content);
+ }
+}
+
+static int recvattach_pgp_check_traditional (ATTACH_CONTEXT *actx, MUTTMENU *menu)
+{
+ int i, rv = 0;
+
+ if (!menu->tagprefix)
+ rv = crypt_pgp_check_traditional (CURATTACH->fp, CURATTACH->content, 1);
+ else
+ {
+ for (i = 0; i < actx->idxlen; i++)
+ if (actx->idx[i]->content->tagged)
+ rv = rv || crypt_pgp_check_traditional (actx->idx[i]->fp, actx->idx[i]->content, 1);
+ }
+
+ return rv;
+}
int
mutt_attach_display_loop (MUTTMENU *menu, int op, HEADER *hdr,
@@ -1133,17 +1163,14 @@ void mutt_view_attachments (HEADER *hdr)
case OP_EXTRACT_KEYS:
if ((WithCrypto & APPLICATION_PGP))
{
- crypt_pgp_extract_keys_from_attachment_list (fp, menu->tagprefix,
- menu->tagprefix ? cur : CURATTACH->content);
+ recvattach_extract_pgp_keys (actx, menu);
menu->redraw = REDRAW_FULL;
}
break;
case OP_CHECK_TRADITIONAL:
- if ((WithCrypto & APPLICATION_PGP)
- && crypt_pgp_check_traditional (fp, menu->tagprefix ? cur
- : CURATTACH->content,
- menu->tagprefix))
+ if ((WithCrypto & APPLICATION_PGP) &&
+ recvattach_pgp_check_traditional (actx, menu))
{
hdr->security = crypt_query (cur);
menu->redraw = REDRAW_FULL;