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>
38 int mutt_is_multipart_signed(BODY * b)
42 if (!b || b->type != TYPEMULTIPART || !b->subtype
43 || mime_which_token(b->subtype, -1) != MIME_SIGNED)
46 if (!(p = parameter_getval(b->parameter, "protocol")))
49 switch (mime_which_token(p, -1)) {
50 case MIME_MULTIPART_MIXED:
53 case MIME_APPLICATION_PGP_SIGNATURE:
56 case MIME_APPLICATION_X_PKCS7_SIGNATURE:
59 case MIME_APPLICATION_PKCS7_SIGNATURE:
67 int mutt_is_multipart_encrypted (BODY * b)
71 if (!b || b->type != TYPEMULTIPART || !b->subtype
72 || mime_which_token(b->subtype, -1) != MIME_ENCRYPTED
73 || !(p = parameter_getval(b->parameter, "protocol"))
74 || mime_which_token(p, -1) != MIME_APPLICATION_PGP_ENCRYPTED)
80 int mutt_is_application_pgp (BODY * m)
84 int subtype = mime_which_token(m->subtype, -1);
86 if (m->type == TYPEAPPLICATION) {
87 if (subtype == MIME_PGP || subtype == MIME_X_PGP_MESSAGE) {
90 tok = mime_which_token(parameter_getval(m->parameter, "x-action"), -1);
91 if (tok == MIME_SIGN || tok == MIME_SIGNCLEAR)
94 tok = mime_which_token(parameter_getval(m->parameter, "format"), -1);
95 if (tok == MIME_KEYS_ONLY)
99 t |= PGPENCRYPT; /* not necessarily correct, but... */
102 if (subtype == MIME_PGP_SIGNED)
105 if (subtype == MIME_PGP_KEYS)
109 if (m->type == TYPETEXT && subtype == MIME_PLAIN) {
112 if ((p = parameter_getval(m->parameter, "x-action"))) {
113 int tok = mime_which_token(p, -1);
115 case MIME_PGP_SIGNED:
119 case MIME_PGP_ENCRYPTED:
133 return t ? t | PGPINLINE : 0;
138 int mutt_is_application_smime (BODY * m)
141 int len, complain = 0;
146 if ((m->type & TYPEAPPLICATION) && m->subtype) {
147 int subtype = mime_which_token(m->subtype, -1);
149 /* S/MIME MIME types don't need x- anymore, see RFC2311 */
150 if (subtype == MIME_X_PKCS7_MIME || subtype == MIME_PKCS7_MIME) {
151 t = parameter_getval(m->parameter, "smime-type");
154 switch (mime_which_token(t, -1)) {
155 case MIME_ENVELOPED_DATA:
158 case MIME_SIGNED_DATA:
159 return SMIMESIGN | SMIMEOPAQUE;
169 if (subtype == MIME_OCTET_STREAM)
172 t = parameter_getval(m->parameter, "name");
180 mutt_message(_("S/MIME messages with no hints on content are unsupported."));
184 /* no .p7c, .p10 support yet. */
186 len = m_strlen(t) - 4;
187 if (len > 0 && t[len] == '.'
188 && tolower((unsigned char)t[len + 1]) == 'p'
189 && t[len + 2] == '7')
191 switch (t[len + 3]) {
193 /* Not sure if this is the correct thing to do, but
194 it's required for compatibility with Outlook */
195 return SMIMESIGN | SMIMEOPAQUE;
198 return SMIMESIGN | SMIMEOPAQUE;