evolution-3.6.4/em-format/e-mail-parser-application-smime.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-application-smime.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-application-smime.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
Failure running clang-analyzer ('no-output-found')
Message
Unable to locate XML output from invoke-clang-analyzer
  1 /*
  2  * e-mail-parser-application-xpkcs7mime.c
  3  *
  4  * This program is free software; you can redistribute it and/or
  5  * modify it under the terms of the GNU Lesser General Public
  6  * License as published by the Free Software Foundation; either
  7  * version 2 of the License, or (at your option) version 3.
  8  *
  9  * This program is distributed in the hope that it will be useful,
 10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 12  * Lesser General Public License for more details.
 13  *
 14  * You should have received a copy of the GNU Lesser General Public
 15  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 16  *
 17  */
 18 
 19 #ifdef HAVE_CONFIG_H
 20 #include <config.h>
 21 #endif
 22 
 23 #include "e-mail-format-extensions.h"
 24 
 25 #include <glib-object.h>
 26 #include <glib/gi18n-lib.h>
 27 
 28 #include <em-format/e-mail-parser-extension.h>
 29 #include <em-format/e-mail-parser.h>
 30 #include <em-format/e-mail-part-utils.h>
 31 #include <e-util/e-util.h>
 32 
 33 #include <camel/camel.h>
 34 
 35 #include <string.h>
 36 
 37 typedef struct _EMailParserApplicationSMIME {
 38 	GObject parent;
 39 } EMailParserApplicationSMIME;
 40 
 41 typedef struct _EMailParserAppplicationSMIMEClass {
 42 	GObjectClass parent_class;
 43 } EMailParserApplicationSMIMEClass;
 44 
 45 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 46 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 47 
 48 G_DEFINE_TYPE_EXTENDED (
 49 	EMailParserApplicationSMIME,
 50 	e_mail_parser_application_smime,
 51 	G_TYPE_OBJECT,
 52 	0,
 53 	G_IMPLEMENT_INTERFACE (
 54 		E_TYPE_MAIL_EXTENSION,
 55 		e_mail_parser_mail_extension_interface_init)
 56 	G_IMPLEMENT_INTERFACE (
 57 		E_TYPE_MAIL_PARSER_EXTENSION,
 58 		e_mail_parser_parser_extension_interface_init));
 59 
 60 static const gchar * parser_mime_types[] = { "application/xpkcs7mime",
 61 					    "application/x-pkcs7-mime",
 62 					    "application/pkcs7-mime",
 63 					    "application/pkcs7-signature",
 64 					    "application/xpkcs7-signature",
 65 					    "application/x-pkcs7-signature",
 66 					    NULL };
 67 
 68 static GSList *
 69 empe_app_smime_parse (EMailParserExtension *extension,
 70                        EMailParser *parser,
 71                        CamelMimePart *part,
 72                        GString *part_id,
 73                        GCancellable *cancellable)
 74 {
 75 	CamelCipherContext *context;
 76 	CamelMimePart *opart;
 77 	CamelCipherValidity *valid;
 78 	GError *local_error = NULL;
 79 	GSList *parts, *iter;
 80 	CamelContentType *ct;
 81 
 82 	if (g_cancellable_is_cancelled (cancellable))
 83 		return NULL;
 84 
 85 	ct = camel_mime_part_get_content_type (part);
 86 	if (camel_content_type_is (ct, "application", "pkcs7-signature") ||
 87 	    camel_content_type_is (ct, "application", "xpkcs7-signature") ||
 88 	    camel_content_type_is (ct, "application", "x-pkcs7-signature")) {
 89 		return g_slist_alloc ();
 90 	}
 91 
 92 	context = camel_smime_context_new (e_mail_parser_get_session (parser));
 93 
 94 	opart = camel_mime_part_new ();
 95 	valid = camel_cipher_context_decrypt_sync (
 96 		context, part, opart,
 97 		cancellable, &local_error);
 98 
 99 	e_mail_part_preserve_charset_in_content_type (part, opart);
100 
101 	if (local_error != NULL) {
102 		parts = e_mail_parser_error (
103 			parser, cancellable,
104 			_("Could not parse S/MIME message: %s"),
105 			local_error->message);
106 		g_error_free (local_error);
107 
108 	} else {
109 		gint len = part_id->len;
110 
111 		g_string_append (part_id, ".encrypted");
112 
113 		parts = e_mail_parser_parse_part (
114 			parser, opart, part_id, cancellable);
115 
116 		g_string_truncate (part_id, len);
117 
118 		/* Update validity flags of all the involved subp-arts */
119 		for (iter = parts; iter; iter = iter->next) {
120 
121 			EMailPart *mail_part = iter->data;
122 			if (!mail_part)
123 				continue;
124 
125 			e_mail_part_update_validity (
126 				mail_part, valid,
127 				E_MAIL_PART_VALIDITY_ENCRYPTED |
128 				E_MAIL_PART_VALIDITY_SMIME);
129 
130 		}
131 
132 		/* Add a widget with details about the encryption, but only when
133 		 * the encrypted isn't itself secured, in that case it has created
134 		 * the button itself */
135 		if (!e_mail_part_is_secured (opart)) {
136 			GSList *button;
137 			EMailPart *mail_part;
138 			g_string_append (part_id, ".encrypted.button");
139 
140 			button = e_mail_parser_parse_part_as (
141 					parser, part, part_id,
142 					"application/vnd.evolution.widget.secure-button",
143 					cancellable);
144 			if (button && button->data) {
145 				mail_part = button->data;
146 
147 				e_mail_part_update_validity (
148 					mail_part, valid,
149 					E_MAIL_PART_VALIDITY_ENCRYPTED |
150 					E_MAIL_PART_VALIDITY_SMIME);
151 			}
152 
153 			parts = g_slist_concat (parts, button);
154 
155 			g_string_truncate (part_id, len);
156 		}
157 
158 		camel_cipher_validity_free (valid);
159 	}
160 
161 	g_object_unref (opart);
162 	g_object_unref (context);
163 
164 	return parts;
165 }
166 
167 static guint32
168 empe_app_smime_get_flags (EMailParserExtension *extension)
169 {
170 	return E_MAIL_PARSER_EXTENSION_INLINE;
171 }
172 
173 static const gchar **
174 empe_application_smime_mime_types (EMailExtension *extension)
175 {
176 	return parser_mime_types;
177 }
178 
179 static void
180 e_mail_parser_application_smime_class_init (EMailParserApplicationSMIMEClass *class)
181 {
182 }
183 
184 static void
185 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *interface)
186 {
187 	interface->parse = empe_app_smime_parse;
188 	interface->get_flags = empe_app_smime_get_flags;
189 }
190 
191 static void
192 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *interface)
193 {
194 	interface->mime_types = empe_application_smime_mime_types;
195 }
196 
197 static void
198 e_mail_parser_application_smime_init (EMailParserApplicationSMIME *parser)
199 {
200 
201 }