Commit 05012506 authored by Kevin J. McCarthy's avatar Kevin J. McCarthy

Fix attachment check_traditional and extract_keys operations. (see #3728)

Add helpers and iterate over the actx->idx instead of the BODY structure.
parent 2a735859
......@@ -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;
}
......
......@@ -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);
......
......@@ -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)
......
......@@ -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)
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment