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);
93 if (tok == MIME_SIGN || tok == MIME_SIGNCLEAR)
96 tok = mime_which_token(parameter_getval(m->parameter, "format"), -1);
97 if (tok == MIME_KEYS_ONLY)
101 t |= PGPENCRYPT; /* not necessarily correct, but... */
104 if (subtype == MIME_PGP_SIGNED)
107 if (subtype == MIME_PGP_KEYS)
111 if (m->type == TYPETEXT && subtype == MIME_PLAIN) {
114 if ((p = parameter_getval(m->parameter, "x-mutt-action"))
115 || (p = parameter_getval(m->parameter, "x-action"))
116 || (p = parameter_getval(m->parameter, "action")))
118 int tok = mime_which_token(p, -1);
124 case MIME_PGP_ENCRYPT:
138 return t ? t | PGPINLINE : 0;
143 int mutt_is_application_smime (BODY * m)
146 int len, complain = 0;
151 if ((m->type & TYPEAPPLICATION) && m->subtype) {
152 int subtype = mime_which_token(m->subtype, -1);
154 /* S/MIME MIME types don't need x- anymore, see RFC2311 */
155 if (subtype == MIME_X_PKCS7_MIME || subtype == MIME_PKCS7_MIME) {
156 t = parameter_getval(m->parameter, "smime-type");
159 switch (mime_which_token(t, -1)) {
160 case MIME_ENVELOPED_DATA:
163 case MIME_SIGNED_DATA:
164 return SMIMESIGN | SMIMEOPAQUE;
174 if (subtype == MIME_OCTET_STREAM)
177 t = parameter_getval(m->parameter, "name");
185 mutt_message(_("S/MIME messages with no hints on content are unsupported."));
189 /* no .p7c, .p10 support yet. */
191 len = m_strlen(t) - 4;
192 if (len > 0 && t[len] == '.'
193 && tolower((unsigned char)t[len + 1]) == 'p'
194 && t[len + 2] == '7')
196 switch (t[len + 3]) {
198 /* Not sure if this is the correct thing to do, but
199 it's required for compatibility with Outlook */
200 return (SMIMESIGN | SMIMEOPAQUE);
203 return (SMIMESIGN | SMIMEOPAQUE);