evolution-3.6.4/modules/itip-formatter/e-mail-parser-itip.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-itip.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-itip.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  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		JP Rosevear <jpr@novell.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <string.h>
 28 #include <gtk/gtk.h>
 29 #include <glib/gi18n.h>
 30 
 31 #include "e-mail-parser-itip.h"
 32 
 33 #include <em-format/e-mail-extension-registry.h>
 34 #include <em-format/e-mail-parser-extension.h>
 35 #include <em-format/e-mail-part.h>
 36 
 37 #include <misc/e-attachment.h>
 38 
 39 #include "e-mail-part-itip.h"
 40 #include "itip-view.h"
 41 #include <shell/e-shell.h>
 42 
 43 #define CONF_KEY_DELETE "delete-processed"
 44 
 45 #define d(x)
 46 
 47 typedef struct _EMailParserItip {
 48 	EExtension parent;
 49 } EMailParserItip;
 50 
 51 typedef struct _EMailParserItipClass {
 52 	EExtensionClass parent_class;
 53 } EMailParserItipClass;
 54 
 55 GType e_mail_parser_itip_get_type (void);
 56 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 57 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 58 
 59 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
 60 	EMailParserItip,
 61 	e_mail_parser_itip,
 62 	E_TYPE_EXTENSION,
 63 	0,
 64 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 65 		E_TYPE_MAIL_EXTENSION,
 66 		e_mail_parser_mail_extension_interface_init)
 67 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 68 		E_TYPE_MAIL_PARSER_EXTENSION,
 69 		e_mail_parser_parser_extension_interface_init));
 70 
 71 static const gchar * parser_mime_types[] = { "text/calendar",
 72 					     "application/ics",
 73 					     NULL };
 74 
 75 static void
 76 mail_part_itip_free (EMailPart *mail_part)
 77 {
 78 	EMailPartItip *pitip = (EMailPartItip *) mail_part;
 79 	gint i;
 80 
 81 	g_cancellable_cancel (pitip->cancellable);
 82 	g_clear_object (&pitip->cancellable);
 83 	g_clear_object (&pitip->registry);
 84 
 85 	for (i = 0; i < E_CAL_CLIENT_SOURCE_TYPE_LAST; i++) {
 86 		if (pitip->clients[i]) {
 87 			g_hash_table_destroy (pitip->clients[i]);
 88 			pitip->clients[i] = NULL;
 89 		}
 90 	}
 91 
 92 	g_free (pitip->vcalendar);
 93 	pitip->vcalendar = NULL;
 94 
 95 	if (pitip->comp) {
 96 		g_object_unref (pitip->comp);
 97 		pitip->comp = NULL;
 98 	}
 99 
100 	if (pitip->top_level) {
101 		icalcomponent_free (pitip->top_level);
102 		pitip->top_level = NULL;
103 	}
104 
105 	if (pitip->main_comp) {
106 		icalcomponent_free (pitip->main_comp);
107 		pitip->main_comp = NULL;
108 	}
109 	pitip->ical_comp = NULL;
110 
111 	g_free (pitip->calendar_uid);
112 	pitip->calendar_uid = NULL;
113 
114 	g_free (pitip->from_address);
115 	pitip->from_address = NULL;
116 	g_free (pitip->from_name);
117 	pitip->from_name = NULL;
118 	g_free (pitip->to_address);
119 	pitip->to_address = NULL;
120 	g_free (pitip->to_name);
121 	pitip->to_name = NULL;
122 	g_free (pitip->delegator_address);
123 	pitip->delegator_address = NULL;
124 	g_free (pitip->delegator_name);
125 	pitip->delegator_name = NULL;
126 	g_free (pitip->my_address);
127 	pitip->my_address = NULL;
128 	g_free (pitip->uid);
129 	g_hash_table_destroy (pitip->real_comps);
130 
131 	g_clear_object (&pitip->view);
132 }
133 
134 /******************************************************************************/
135 
136 static void
137 bind_itip_view (EMailPart *part,
138                 WebKitDOMElement *element)
139 {
140 	GString *buffer;
141 	WebKitDOMDocument *document;
142 	ItipView *view;
143 	EMailPartItip *pitip;
144 
145 	if (!WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (element)) {
146 
147 		WebKitDOMNodeList *nodes;
148 		guint length, i;
149 
150 		nodes = webkit_dom_element_get_elements_by_tag_name (
151 				element, "iframe");
152 		length = webkit_dom_node_list_get_length (nodes);
153 		for (i = 0; i < length; i++) {
154 
155 			element = WEBKIT_DOM_ELEMENT (
156 					webkit_dom_node_list_item (nodes, i));
157 			break;
158 		}
159 
160 	}
161 
162 	g_return_if_fail (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT (element));
163 
164 	buffer = g_string_new ("");
165 	document = webkit_dom_html_iframe_element_get_content_document (
166 			WEBKIT_DOM_HTML_IFRAME_ELEMENT (element));
167 	pitip = E_MAIL_PART_ITIP (part);
168 
169 	view = itip_view_new (pitip, pitip->registry);
170 	g_object_set_data_full (
171 		G_OBJECT (element), "view", view,
172 		(GDestroyNotify) g_object_unref);
173 
174 	itip_view_create_dom_bindings (
175 		view, webkit_dom_document_get_document_element (document));
176 
177 	itip_view_init_view (view);
178 	g_string_free (buffer, TRUE);
179 }
180 
181 /*******************************************************************************/
182 
183 static GSList *
184 empe_itip_parse (EMailParserExtension *extension,
185                  EMailParser *parser,
186                  CamelMimePart *part,
187                  GString *part_id,
188                  GCancellable *cancellable)
189 {
190 	EShell *shell;
191 	GSettings *settings;
192 	EMailPartItip *itip_part;
193 	CamelDataWrapper *content;
194 	CamelStream *stream;
195 	GByteArray *byte_array;
196 	gint len;
197 	const CamelContentDisposition *disposition;
198 	GSList *parts;
199 
200 	len = part_id->len;
201 	g_string_append_printf (part_id, ".itip");
202 
203 	settings = g_settings_new ("org.gnome.evolution.plugin.itip");
204 	shell = e_shell_get_default ();
205 
206 	itip_part = (EMailPartItip *) e_mail_part_subclass_new (
207 					part, part_id->str, sizeof (EMailPartItip),
208 					(GFreeFunc)	mail_part_itip_free);
209 	itip_part->parent.mime_type = g_strdup ("text/calendar");
210 	itip_part->parent.bind_func = bind_itip_view;
211 	itip_part->parent.force_collapse = TRUE;
212 	itip_part->delete_message = g_settings_get_boolean (settings, CONF_KEY_DELETE);
213 	itip_part->has_organizer = FALSE;
214 	itip_part->no_reply_wanted = FALSE;
215 	itip_part->part = part;
216 	itip_part->cancellable = g_cancellable_new ();
217 	itip_part->real_comps = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);
218 	itip_part->registry = g_object_ref (e_shell_get_registry (shell));
219 
220 	g_object_unref (settings);
221 
222 	/* This is non-gui thread. Download the part for using in the main thread */
223 	content = camel_medium_get_content ((CamelMedium *) part);
224 
225 	byte_array = g_byte_array_new ();
226 	stream = camel_stream_mem_new_with_byte_array (byte_array);
227 	camel_data_wrapper_decode_to_stream_sync (content, stream, NULL, NULL);
228 
229 	if (byte_array->len == 0)
230 		itip_part->vcalendar = NULL;
231 	else
232 		itip_part->vcalendar = g_strndup (
233 			(gchar *) byte_array->data, byte_array->len);
234 
235 	g_object_unref (stream);
236 
237 	parts = g_slist_append (NULL, itip_part);
238 
239 	disposition = camel_mime_part_get_content_disposition (part);
240 	if (disposition &&
241 	    (g_strcmp0 (disposition->disposition, "attachment") == 0)) {
242 		parts = e_mail_parser_wrap_as_attachment (
243 			parser, part, parts, part_id, cancellable);
244 	}
245 
246 	g_string_truncate (part_id, len);
247 
248 	return parts;
249 }
250 
251 static guint32
252 empe_itip_get_flags (EMailParserExtension *extension)
253 {
254 	return E_MAIL_PARSER_EXTENSION_INLINE_DISPOSITION;
255 }
256 
257 static const gchar **
258 empe_mime_types (EMailExtension *extension)
259 {
260 	return parser_mime_types;
261 }
262 
263 void
264 e_mail_parser_itip_type_register (GTypeModule *type_module)
265 {
266 	e_mail_parser_itip_register_type (type_module);
267 }
268 
269 static void
270 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
271 {
272 	iface->mime_types = empe_mime_types;
273 }
274 
275 static void
276 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
277 {
278 	iface->parse = empe_itip_parse;
279 	iface->get_flags = empe_itip_get_flags;
280 }
281 
282 static void
283 e_mail_parser_itip_constructed (GObject *object)
284 {
285 	EExtensible *extensible;
286 	EMailExtensionRegistry *reg;
287 
288 	extensible = e_extension_get_extensible (E_EXTENSION (object));
289 	reg = E_MAIL_EXTENSION_REGISTRY (extensible);
290 
291 	e_mail_extension_registry_add_extension (reg, E_MAIL_EXTENSION (object));
292 }
293 
294 static void
295 e_mail_parser_itip_finalize (GObject *object)
296 {
297 	EExtensible *extensible;
298 	EMailExtensionRegistry *reg;
299 
300 	extensible = e_extension_get_extensible (E_EXTENSION (object));
301 	reg = E_MAIL_EXTENSION_REGISTRY (extensible);
302 
303 	e_mail_extension_registry_remove_extension (reg, E_MAIL_EXTENSION (object));
304 }
305 
306 static void
307 e_mail_parser_itip_class_init (EMailParserItipClass *class)
308 {
309 	GObjectClass *object_class;
310 	EExtensionClass *extension_class;
311 
312 	object_class = G_OBJECT_CLASS (class);
313 	object_class->constructed = e_mail_parser_itip_constructed;
314 	object_class->finalize = e_mail_parser_itip_finalize;
315 
316 	extension_class = E_EXTENSION_CLASS (class);
317 	extension_class->extensible_type = E_TYPE_MAIL_PARSER_EXTENSION_REGISTRY;
318 }
319 
320 static void
321 e_mail_parser_itip_class_finalize (EMailParserItipClass *class)
322 {
323 
324 }
325 
326 static void
327 e_mail_parser_itip_init (EMailParserItip *self)
328 {
329 }