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)
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);
}
}
- 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);
if (!buf[0])
return (-1);
-
+
/* This is an undocumented feature of ELM pointed out to me by Felix von
* Leitner <leitner@prz.fu-berlin.de>
*/
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)
#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
#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 */
#include "mailbox.h"
#include "mx.h"
+#ifdef _PGPPATH
+#include "pgp.h"
+#endif
+
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#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:
}
-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"))
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;
}
{
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);
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 **);
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))
{
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;