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

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-inlinepgp-encrypted.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-inlinepgp-encrypted.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-encrypted.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 _EMailParserInlinePGPEncrypted {
 36 	GObject parent;
 37 } EMailParserInlinePGPEncrypted;
 38 
 39 typedef struct _EMailParserInlinePGPEncryptedClass {
 40 	GObjectClass parent_class;
 41 } EMailParserInlinePGPEncryptedClass;
 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 	EMailParserInlinePGPEncrypted,
 48 	e_mail_parser_inline_pgp_encrypted,
 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-encrypted",
 59 					    NULL };
 60 
 61 static GSList *
 62 empe_inlinepgp_encrypted_parse (EMailParserExtension *extension,
 63                                 EMailParser *parser,
 64                                 CamelMimePart *part,
 65                                 GString *part_id,
 66                                 GCancellable *cancellable)
 67 {
 68 	CamelCipherContext *cipher;
 69 	CamelCipherValidity *valid;
 70 	CamelMimePart *opart;
 71 	CamelDataWrapper *dw;
 72 	gchar *mime_type;
 73 	gint len;
 74 	GError *local_error = NULL;
 75 	GSList *parts, *iter;
 76 
 77 	if (g_cancellable_is_cancelled (cancellable) ||
 78 	    /* avoid recursion */
 79 	    (part_id->str && part_id->len > 20 && g_str_has_suffix (part_id->str, ".inlinepgp_encrypted")))
 80 		return NULL;
 81 
 82 	cipher = camel_gpg_context_new (e_mail_parser_get_session (parser));
 83 
 84 	opart = camel_mime_part_new ();
 85 
 86 	/* Decrypt the message */
 87 	valid = camel_cipher_context_decrypt_sync (
 88 		cipher, part, opart, cancellable, &local_error);
 89 
 90 	if (local_error != NULL) {
 91 		parts = e_mail_parser_error (
 92 			parser, cancellable,
 93 			_("Could not parse PGP message: %s"),
 94 			local_error->message);
 95 		g_error_free (local_error);
 96 
 97 		parts = g_slist_concat (
 98 			parts,
 99 			e_mail_parser_parse_part_as (parser,
100 				part, part_id,
101 				"application/vnd.evolution.source",
102 				cancellable));
103 
104 		g_object_unref (cipher);
105 		g_object_unref (opart);
106 		return parts;
107 	}
108 
109 	dw = camel_medium_get_content ((CamelMedium *) opart);
110 	mime_type = camel_data_wrapper_get_mime_type (dw);
111 
112 	/* this ensures to show the 'opart' as inlined, if possible */
113 	if (mime_type && g_ascii_strcasecmp (mime_type, "application/octet-stream") == 0) {
114 		const gchar *snoop = e_mail_part_snoop_type (opart);
115 
116 		if (snoop)
117 			camel_data_wrapper_set_mime_type (dw, snoop);
118 	}
119 
120 	e_mail_part_preserve_charset_in_content_type (part, opart);
121 	g_free (mime_type);
122 
123 	/* Pass it off to the real formatter */
124 	len = part_id->len;
125 	g_string_append (part_id, ".inlinepgp_encrypted");
126 
127 	parts = e_mail_parser_parse_part_as (
128 			parser, opart, part_id,
129 			camel_data_wrapper_get_mime_type (dw), cancellable);
130 
131 	g_string_truncate (part_id, len);
132 
133 	for (iter = parts; iter; iter = iter->next) {
134 		EMailPart *mail_part;
135 
136 		mail_part = iter->data;
137 		if (!mail_part)
138 			continue;
139 
140 		e_mail_part_update_validity (
141 			mail_part, valid,
142 			E_MAIL_PART_VALIDITY_ENCRYPTED |
143 			E_MAIL_PART_VALIDITY_PGP);
144 	}
145 
146 	/* Add a widget with details about the encryption, but only when
147 	 * the encrypted isn't itself secured, in that case it has created
148 	 * the button itself */
149 	if (!e_mail_part_is_secured (opart)) {
150 		GSList *button;
151 		EMailPart *mail_part;
152 		g_string_append (part_id, ".inlinepgp_encrypted.button");
153 
154 		button = e_mail_parser_parse_part_as (
155 				parser, part, part_id,
156 				"application/vnd.evolution.widget.secure-button",
157 				cancellable);
158 		if (button && button->data) {
159 			mail_part = button->data;
160 
161 			e_mail_part_update_validity (
162 				mail_part, valid,
163 				E_MAIL_PART_VALIDITY_ENCRYPTED |
164 				E_MAIL_PART_VALIDITY_PGP);
165 		}
166 
167 		parts = g_slist_concat (parts, button);
168 
169 		g_string_truncate (part_id, len);
170 	}
171 
172 	/* Clean Up */
173 	camel_cipher_validity_free (valid);
174 	g_object_unref (opart);
175 	g_object_unref (cipher);
176 
177 	return parts;
178 }
179 
180 static const gchar **
181 empe_inlinepgp_encrypted_mime_types (EMailExtension *extension)
182 {
183 	return parser_mime_types;
184 }
185 
186 static void
187 e_mail_parser_inline_pgp_encrypted_class_init (EMailParserInlinePGPEncryptedClass *class)
188 {
189 }
190 
191 static void
192 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
193 {
194 	iface->parse = empe_inlinepgp_encrypted_parse;
195 }
196 
197 static void
198 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
199 {
200 	iface->mime_types = empe_inlinepgp_encrypted_mime_types;
201 }
202 
203 static void
204 e_mail_parser_inline_pgp_encrypted_init (EMailParserInlinePGPEncrypted *parser)
205 {
206 
207 }