2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
20 * Copyright notice from original mutt:
21 * Copyright (C) 1996,1997 Michael R. Elkins <me@mutt.org>
22 * Copyright (C) 1999-2000 Thomas Roessler <roessler@does-not-exist.org>
23 * Copyright (C) 2001 Thomas Roessler <roessler@does-not-exist.org>
24 * Oliver Ehli <elmy@acm.org>
25 * Copyright (C) 2003 Werner Koch <wk@gnupg.org>
26 * Copyright (C) 2004 g10code GmbH
28 * This file is part of mutt-ng, see http://www.muttng.org/.
29 * It's licensed under the GNU General Public License,
30 * please see the file GPL in the top level source directory.
33 #include <lib-lib/lib-lib.h>
35 #include <lib-crypt/crypt.h>
39 int mutt_is_multipart_signed(BODY * b)
43 if (!b || b->type != TYPEMULTIPART || !b->subtype
44 || mime_which_token(b->subtype, -1) != MIME_SIGNED)
47 if (!(p = parameter_getval(b->parameter, "protocol")))
50 switch (mime_which_token(p, -1)) {
51 case MIME_MULTIPART_MIXED:
54 case MIME_APPLICATION_PGP_SIGNATURE:
57 case MIME_APPLICATION_X_PKCS7_SIGNATURE:
60 case MIME_APPLICATION_PKCS7_SIGNATURE:
68 int mutt_is_multipart_encrypted (BODY * b)
72 if (!b || b->type != TYPEMULTIPART || !b->subtype
73 || mime_which_token(b->subtype, -1) != MIME_ENCRYPTED
74 || !(p = parameter_getval(b->parameter, "protocol"))
75 || mime_which_token(p, -1) != MIME_APPLICATION_PGP_ENCRYPTED)
81 int mutt_is_application_pgp (BODY * m)
85 int subtype = mime_which_token(m->subtype, -1);
87 if (m->type == TYPEAPPLICATION) {
88 if (subtype == MIME_PGP || subtype == MIME_X_PGP_MESSAGE) {
91 tok = mime_which_token(parameter_getval(m->parameter, "x-action"), -1);
92 if (tok == MIME_SIGN || tok == MIME_SIGNCLEAR)
95 tok = mime_which_token(parameter_getval(m->parameter, "format"), -1);
96 if (tok == MIME_KEYS_ONLY)
100 t |= PGPENCRYPT; /* not necessarily correct, but... */
103 if (subtype == MIME_PGP_SIGNED)
106 if (subtype == MIME_PGP_KEYS)
110 if (m->type == TYPETEXT && subtype == MIME_PLAIN) {
113 if ((p = parameter_getval(m->parameter, "x-action"))) {
114 int tok = mime_which_token(p, -1);
116 case MIME_PGP_SIGNED:
120 case MIME_PGP_ENCRYPT:
134 return t ? t | PGPINLINE : 0;
139 int mutt_is_application_smime (BODY * m)
142 int len, complain = 0;
147 if ((m->type & TYPEAPPLICATION) && m->subtype) {
148 int subtype = mime_which_token(m->subtype, -1);
150 /* S/MIME MIME types don't need x- anymore, see RFC2311 */
151 if (subtype == MIME_X_PKCS7_MIME || subtype == MIME_PKCS7_MIME) {
152 t = parameter_getval(m->parameter, "smime-type");
155 switch (mime_which_token(t, -1)) {
156 case MIME_ENVELOPED_DATA:
159 case MIME_SIGNED_DATA:
160 return SMIMESIGN | SMIMEOPAQUE;
170 if (subtype == MIME_OCTET_STREAM)
173 t = parameter_getval(m->parameter, "name");
181 mutt_message(_("S/MIME messages with no hints on content are unsupported."));
185 /* no .p7c, .p10 support yet. */
187 len = m_strlen(t) - 4;
188 if (len > 0 && t[len] == '.'
189 && tolower((unsigned char)t[len + 1]) == 'p'
190 && t[len + 2] == '7')
192 switch (t[len + 3]) {
194 /* Not sure if this is the correct thing to do, but
195 it's required for compatibility with Outlook */
196 return (SMIMESIGN | SMIMEOPAQUE);
199 return (SMIMESIGN | SMIMEOPAQUE);