evolution-3.6.4/em-format/e-mail-parser-inlinepgp-signed.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-inlinepgp-signed.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-inlinepgp-signed.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-inlinepgp-signed.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 <em-format/e-mail-parser-extension.h>
 26 #include <em-format/e-mail-parser.h>
 27 #include <em-format/e-mail-part-utils.h>
 28 #include <e-util/e-util.h>
 29 
 30 #include <glib/gi18n-lib.h>
 31 #include <camel/camel.h>
 32 
 33 #include <string.h>
 34 
 35 typedef struct _EMailParserInlinePGPSigned {
 36 	GObject parent;
 37 } EMailParserInlinePGPSigned;
 38 
 39 typedef struct _EMailParserInlinePGPSignedClass {
 40 	GObjectClass parent_class;
 41 } EMailParserInlinePGPSignedClass;
 42 
 43 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 44 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 45 
 46 G_DEFINE_TYPE_EXTENDED (
 47 	EMailParserInlinePGPSigned,
 48 	e_mail_parser_inline_pgp_signed,
 49 	G_TYPE_OBJECT,
 50 	0,
 51 	G_IMPLEMENT_INTERFACE (
 52 		E_TYPE_MAIL_EXTENSION,
 53 		e_mail_parser_mail_extension_interface_init)
 54 	G_IMPLEMENT_INTERFACE (
 55 		E_TYPE_MAIL_PARSER_EXTENSION,
 56 		e_mail_parser_parser_extension_interface_init));
 57 
 58 static const gchar * parser_mime_types[] = { "application/x-inlinepgp-signed",
 59 					    NULL };
 60 
 61 static GSList *
 62 empe_inlinepgp_signed_parse (EMailParserExtension *extension,
 63                              EMailParser *parser,
 64                              CamelMimePart *part,
 65                              GString *part_id,
 66                              GCancellable *cancellable)
 67 {
 68 	CamelStream *filtered_stream;
 69 	CamelMimeFilterPgp *pgp_filter;
 70 	CamelContentType *content_type;
 71 	CamelCipherContext *cipher;
 72 	CamelCipherValidity *valid;
 73 	CamelDataWrapper *dw;
 74 	CamelMimePart *opart;
 75 	CamelStream *ostream;
 76 	gchar *type;
 77 	gint len;
 78 	GError *local_error = NULL;
 79 	GByteArray *ba;
 80 	GSList *parts, *iter;
 81 
 82 	if (g_cancellable_is_cancelled (cancellable) ||
 83 	    /* avoid recursion */
 84 	    (part_id->str && part_id->len > 17 && g_str_has_suffix (part_id->str, ".inlinepgp_signed")))
 85 		return NULL;
 86 
 87 	cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));
 88 
 89 	/* Verify the signature of the message */
 90 	valid = camel_cipher_context_verify_sync (
 91 		cipher, part, cancellable, &local_error);
 92 
 93 	if (local_error != NULL) {
 94 		parts = e_mail_parser_error (
 95 			parser, cancellable,
 96 			_("Error verifying signature: %s"),
 97 			local_error->message);
 98 
 99 		g_error_free (local_error);
100 
101 		parts = g_slist_concat (
102 			parts,
103 			e_mail_parser_parse_part_as (
104 				parser, part, part_id,
105 				"application/vnd.evolution.source",
106 				cancellable));
107 
108 		g_object_unref (cipher);
109 		return parts;
110 	}
111 
112 	/* Setup output stream */
113 	ostream = camel_stream_mem_new ();
114 	filtered_stream = camel_stream_filter_new (ostream);
115 
116 	/* Add PGP header / footer filter */
117 	pgp_filter = (CamelMimeFilterPgp *) camel_mime_filter_pgp_new ();
118 	camel_stream_filter_add (
119 		CAMEL_STREAM_FILTER (filtered_stream),
120 		CAMEL_MIME_FILTER (pgp_filter));
121 	g_object_unref (pgp_filter);
122 
123 	/* Pass through the filters that have been setup */
124 	dw = camel_medium_get_content ((CamelMedium *) part);
125 	camel_data_wrapper_decode_to_stream_sync (
126 		dw, (CamelStream *) filtered_stream, cancellable, NULL);
127 	camel_stream_flush ((CamelStream *) filtered_stream, cancellable, NULL);
128 	g_object_unref (filtered_stream);
129 
130 	/* Create a new text/plain MIME part containing the signed
131 	 * content preserving the original part's Content-Type params. */
132 	content_type = camel_mime_part_get_content_type (part);
133 	type = camel_content_type_format (content_type);
134 	content_type = camel_content_type_decode (type);
135 	g_free (type);
136 
137 	g_free (content_type->type);
138 	content_type->type = g_strdup ("text");
139 	g_free (content_type->subtype);
140 	content_type->subtype = g_strdup ("plain");
141 	type = camel_content_type_format (content_type);
142 	camel_content_type_unref (content_type);
143 
144 	ba = camel_stream_mem_get_byte_array ((CamelStreamMem *) ostream);
145 	opart = camel_mime_part_new ();
146 	camel_mime_part_set_content (opart, (gchar *) ba->data, ba->len, type);
147 	g_free (type);
148 
149 	len = part_id->len;
150 	g_string_append (part_id, ".inlinepgp_signed");
151 
152 	parts = e_mail_parser_parse_part (
153 		parser, opart, part_id, cancellable);
154 
155 	for (iter = parts; iter; iter = iter->next) {
156 		EMailPart *mail_part;
157 
158 		mail_part = iter->data;
159 		if (!mail_part)
160 			continue;
161 
162 		e_mail_part_update_validity (
163 			mail_part, valid,
164 			E_MAIL_PART_VALIDITY_SIGNED |
165 			E_MAIL_PART_VALIDITY_PGP);
166 	}
167 
168 	g_string_truncate (part_id, len);
169 
170 	/* Add a widget with details about the encryption, but only when
171 	 * the encrypted isn't itself secured, in that case it has created
172 	 * the button itself */
173 	if (!e_mail_part_is_secured (opart)) {
174 		GSList *button;
175 		EMailPart *mail_part;
176 		g_string_append (part_id, ".inlinepgp_signed.button");
177 
178 		button = e_mail_parser_parse_part_as (
179 			parser, part, part_id,
180 			"application/vnd.evolution.widget.secure-button",
181 			cancellable);
182 		if (button && button->data) {
183 			mail_part = button->data;
184 
185 			e_mail_part_update_validity (
186 				mail_part, valid,
187 				E_MAIL_PART_VALIDITY_SIGNED |
188 				E_MAIL_PART_VALIDITY_PGP);
189 		}
190 
191 		parts = g_slist_concat (parts, button);
192 
193 		g_string_truncate (part_id, len);
194 	}
195 
196 	/* Clean Up */
197 	camel_cipher_validity_free (valid);
198 	g_object_unref (opart);
199 	g_object_unref (ostream);
200 	g_object_unref (cipher);
201 
202 	return parts;
203 }
204 
205 static const gchar **
206 empe_inlinepgp_signed_mime_types (EMailExtension *extension)
207 {
208 	return parser_mime_types;
209 }
210 
211 static void
212 e_mail_parser_inline_pgp_signed_class_init (EMailParserInlinePGPSignedClass *class)
213 {
214 }
215 
216 static void
217 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
218 {
219 	iface->parse = empe_inlinepgp_signed_parse;
220 }
221 
222 static void
223 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
224 {
225 	iface->mime_types = empe_inlinepgp_signed_mime_types;
226 }
227 
228 static void
229 e_mail_parser_inline_pgp_signed_init (EMailParserInlinePGPSigned *parser)
230 {
231 
232 }