From: Thomas Roessler Date: Mon, 7 Sep 1998 20:40:51 +0000 (+0000) Subject: [patch-0.94.5i.tlr.pgp_fixes.1] This patch fixes various X-Git-Tag: mutt-0-94-6i-rel~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18ae85862e640bf145ae27cb20c6e874c9bd8c6d;p=mutt [patch-0.94.5i.tlr.pgp_fixes.1] This patch fixes various pgp-related issues. In particular, mutt won't segfault when trying to decrypt-save messages from the index, and the presence of a PGP-encrypted body part on the attachment menu will no longer confuse the MIME parser. --- diff --git a/commands.c b/commands.c index cef869cf..3718a2b0 100644 --- a/commands.c +++ b/commands.c @@ -512,28 +512,27 @@ void mutt_display_address (ADDRESS *adr) static void set_copy_flags(HEADER *hdr, int decode, int decrypt, int *cmflags, int *chflags) { *cmflags = 0; - *chflags = decode ? CH_XMIT | CH_MIME : CH_UPDATE_LEN; + *chflags = CH_UPDATE_LEN; #ifdef _PGPPATH if(!decode && decrypt && (hdr->pgp & PGPENCRYPT)) { - if(hdr->content->type == TYPEMULTIPART) + if(mutt_is_multipart_encrypted(hdr->content)) { - *chflags |= CH_NONEWLINE; + *chflags = CH_NONEWLINE | CH_XMIT | CH_MIME; *cmflags = M_CM_DECODE_PGP; } - else if((hdr->content->type == TYPEAPPLICATION) && mutt_is_pgp_subtype(hdr->content->subtype)) + else if(mutt_is_application_pgp(hdr->content) & PGPENCRYPT) decode = 1; } #endif if(decode) { - *chflags |= CH_TXTPLAIN; - *cmflags |= M_CM_DECODE; + *chflags = CH_MIME | CH_TXTPLAIN; + *cmflags = M_CM_DECODE; } - } static void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int decrypt) @@ -541,9 +540,10 @@ static void _mutt_save_message (HEADER *h, CONTEXT *ctx, int delete, int decode, int cmflags, chflags; set_copy_flags(h, decode, decrypt, &cmflags, &chflags); - if (decode) + + if (decode || decrypt) mutt_parse_mime_message (Context, h); - + if (mutt_append_message (ctx, Context, h, cmflags, chflags) == 0 && delete) { mutt_set_flag (Context, h, M_DELETE, 1); @@ -597,10 +597,6 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr } } - if((decrypt || decode) && need_passphrase && - !pgp_valid_passphrase()) - return -1; - mutt_pretty_mailbox (buf); if (mutt_enter_fname (prompt, buf, sizeof (buf), redraw, 0) == -1) return (-1); @@ -615,7 +611,7 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr if (!buf[0]) return (-1); - + /* This is an undocumented feature of ELM pointed out to me by Felix von * Leitner */ @@ -633,6 +629,9 @@ int mutt_save_message (HEADER *h, int delete, int decode, int decrypt, int *redr return (-1); } + if(need_passphrase && (decode || decrypt) && !pgp_valid_passphrase()) + return -1; + mutt_message ("Copying to %s...", buf); if (mx_open_mailbox (buf, M_APPEND, &ctx) != NULL) diff --git a/handler.c b/handler.c index 6575a573..eeebed74 100644 --- a/handler.c +++ b/handler.c @@ -934,9 +934,7 @@ int mutt_can_decode (BODY *a) #ifdef _PGPPATH else if (a->type == TYPEAPPLICATION) { - if (mutt_is_pgp_subtype(a->subtype) || - strcasecmp (a->subtype, "pgp-signed") == 0 || - strcasecmp (a->subtype, "pgp-keys") == 0) + if (mutt_is_application_pgp(a)) return (1); } #endif @@ -1241,10 +1239,7 @@ void mutt_body_handler (BODY *b, STATE *s) #ifdef _PGPPATH else if (b->type == TYPEAPPLICATION) { - if (mutt_is_pgp_subtype(b->subtype) || - strcasecmp ("pgp-signed", b->subtype) == 0 || - strcasecmp ("pgp-keys", b->subtype) == 0) - + if (mutt_is_application_pgp(b)) handler = application_pgp_handler; } #endif /* _PGPPATH */ diff --git a/lib.c b/lib.c index 13d2faaf..79d901fa 100644 --- a/lib.c +++ b/lib.c @@ -22,6 +22,10 @@ #include "mailbox.h" #include "mx.h" +#ifdef _PGPPATH +#include "pgp.h" +#endif + #include #include #include @@ -396,16 +400,12 @@ int mutt_needs_mailcap (BODY *m) #ifdef _PGPPATH case TYPEAPPLICATION: - - if (!strcasecmp ("pgp", m->subtype) || - !strcasecmp ("pgp-signed", m->subtype) || - !strcasecmp ("x-pgp-message", m->subtype)) + if(mutt_is_application_pgp(m)) return 0; break; #endif /* _PGPPATH */ - case TYPEMULTIPART: case TYPEMESSAGE: diff --git a/pgp.c b/pgp.c index 0b0fcf5f..58d7348b 100644 --- a/pgp.c +++ b/pgp.c @@ -479,24 +479,38 @@ void application_pgp_handler (BODY *m, STATE *s) } -int mutt_is_pgp_subtype(const char *st) +int mutt_is_multipart_signed(BODY *b) { - if(st) - { - if(!strcasecmp(st, "pgp")) return 1; - if(!strcasecmp(st, "x-pgp-message")) return 1; - } + char *p; - return 0; + if(!b || b->type != TYPEMULTIPART || + !b->subtype || strcasecmp(b->subtype, "signed") || + !(p = mutt_get_parameter("protocol", b->parameter)) || + strcasecmp(p, "application/pgp-signature")) + return 0; + + return PGPSIGN; } + + +int mutt_is_multipart_encrypted(BODY *b) +{ + char *p; + if(!b || b->type != TYPEMULTIPART || + !b->subtype || strcasecmp(b->subtype, "encrypted") || + !(p = mutt_get_parameter("protocol", b->parameter)) || + strcasecmp(p, "application/pgp-encrypted")) + return 0; + + return PGPENCRYPT; +} -int pgp_query (BODY *m) +int mutt_is_application_pgp(BODY *m) { - char *p; int t = 0; - - /* Check for old-style APPLICATION/PGP messages */ + char *p; + if (m->type == TYPEAPPLICATION) { if (!strcasecmp (m->subtype, "pgp") || !strcasecmp (m->subtype, "x-pgp-message")) @@ -521,17 +535,21 @@ int pgp_query (BODY *m) if (!strcasecmp (m->subtype, "pgp-keys")) t |= PGPKEY; } + return t; +} +int pgp_query (BODY *m) +{ + int t = 0; + + t |= mutt_is_application_pgp(m); + /* Check for PGP/MIME messages. */ if (m->type == TYPEMULTIPART) { - if (strcasecmp (m->subtype, "signed") == 0 && - (p = mutt_get_parameter("protocol", m->parameter)) && - strcasecmp (p, "application/pgp-signature") == 0) + if(mutt_is_multipart_signed(m)) t |= PGPSIGN; - else if ((strcasecmp (m->subtype, "encrypted") == 0) && - (p = mutt_get_parameter ("protocol", m->parameter)) && - strcasecmp (p, "application/pgp-encrypted") == 0) + else if (mutt_is_multipart_encrypted(m)) t |= PGPENCRYPT; } @@ -908,7 +926,10 @@ int pgp_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur) { char tempfile[_POSIX_PATH_MAX]; STATE s; - + + if(!mutt_is_multipart_encrypted(b)) + return -1; + memset (&s, 0, sizeof (s)); s.fpin = fpin; mutt_mktemp (tempfile); diff --git a/pgp.h b/pgp.h index 5a69f32a..74384845 100644 --- a/pgp.h +++ b/pgp.h @@ -166,7 +166,9 @@ struct pgp_vinfo *pgp_get_vinfo(enum pgp_ops); int mutt_check_pgp (HEADER *h); int mutt_parse_pgp_hdr (char *, int); -int mutt_is_pgp_subtype(const char *); +int mutt_is_multipart_encrypted(BODY *); +int mutt_is_multipart_signed(BODY *); +int mutt_is_application_pgp(BODY *); int pgp_decrypt_mime (FILE *, FILE **, BODY *, BODY **); int pgp_get_keys (HEADER *, char **); diff --git a/recvattach.c b/recvattach.c index 00a766d7..6969a7a7 100644 --- a/recvattach.c +++ b/recvattach.c @@ -811,7 +811,7 @@ void mutt_view_attachments (HEADER *hdr) return; } - if ((hdr->pgp & PGPENCRYPT) && hdr->content->type == TYPEMULTIPART) + if ((hdr->pgp & PGPENCRYPT) && mutt_is_multipart_encrypted(hdr->content)) { if (pgp_decrypt_mime (msg->fp, &fp, hdr->content->parts->next, &cur)) { diff --git a/sendlib.c b/sendlib.c index 883eb918..6ff67552 100644 --- a/sendlib.c +++ b/sendlib.c @@ -954,14 +954,13 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) if(option(OPTFORWDECRYPT) && (hdr->pgp & PGPENCRYPT)) { - if(hdr->content->type == TYPEMULTIPART) + if(mutt_is_multipart_encrypted(hdr->content)) { chflags |= CH_MIME | CH_NONEWLINE; cmflags = M_CM_DECODE_PGP; pgp &= ~PGPENCRYPT; } - else if((hdr->content->type == TYPEAPPLICATION) && - mutt_is_pgp_subtype(hdr->content->subtype)) + else if(mutt_is_application_pgp(hdr->content) & PGPENCRYPT) { chflags |= CH_MIME | CH_TXTPLAIN; cmflags = M_CM_DECODE;