evolution-3.6.4/em-format/e-mail-parser-multipart-related.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-multipart-related.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-multipart-related.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-multipart-related.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 <camel/camel.h>
 31 
 32 #include <string.h>
 33 
 34 typedef struct _EMailParserMultipartRelated {
 35 	GObject parent;
 36 } EMailParserMultipartRelated;
 37 
 38 typedef struct _EMailParserMultipartRelatedClass {
 39 	GObjectClass parent_class;
 40 } EMailParserMultipartRelatedClass;
 41 
 42 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 43 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 44 
 45 G_DEFINE_TYPE_EXTENDED (
 46 	EMailParserMultipartRelated,
 47 	e_mail_parser_multipart_related,
 48 	G_TYPE_OBJECT,
 49 	0,
 50 	G_IMPLEMENT_INTERFACE (
 51 		E_TYPE_MAIL_EXTENSION,
 52 		e_mail_parser_mail_extension_interface_init)
 53 	G_IMPLEMENT_INTERFACE (
 54 		E_TYPE_MAIL_PARSER_EXTENSION,
 55 		e_mail_parser_parser_extension_interface_init));
 56 
 57 static const gchar * parser_mime_types[] = { "multipart/related",
 58 					    NULL };
 59 
 60 static GSList *
 61 empe_mp_related_parse (EMailParserExtension *extension,
 62                        EMailParser *parser,
 63                        CamelMimePart *part,
 64                        GString *part_id,
 65                        GCancellable *cancellable)
 66 {
 67 	CamelMultipart *mp;
 68 	CamelMimePart *body_part, *display_part = NULL;
 69 	CamelContentType *display_content_type;
 70 	gchar *html_body = NULL;
 71 	gint i, nparts, partidlen, displayid = 0;
 72 	GSList *parts;
 73 
 74 	if (g_cancellable_is_cancelled (cancellable))
 75 		return NULL;
 76 
 77 	mp = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) part);
 78 
 79 	if (!CAMEL_IS_MULTIPART (mp)) {
 80 		return e_mail_parser_parse_part_as (
 81 				parser, part, part_id,
 82 				"application/vnd.evolution.source", cancellable);
 83 	}
 84 
 85 	display_part = e_mail_part_get_related_display_part (part, &displayid);
 86 
 87 	if (display_part == NULL) {
 88 		return e_mail_parser_parse_part_as (
 89 				parser, part, part_id, "multipart/mixed",
 90 				cancellable);
 91 	}
 92 
 93 	display_content_type = camel_mime_part_get_content_type (display_part);
 94 	if (display_content_type &&
 95 	    camel_content_type_is (display_content_type, "text", "html")) {
 96 		CamelDataWrapper *dw;
 97 
 98 		dw = camel_medium_get_content ((CamelMedium *) display_part);
 99 		if (dw) {
100 			CamelStream *mem = camel_stream_mem_new ();
101 			GByteArray *bytes;
102 
103 			camel_data_wrapper_decode_to_stream_sync (dw, mem, cancellable, NULL);
104 			camel_stream_close (mem, cancellable, NULL);
105 
106 			bytes = camel_stream_mem_get_byte_array	(CAMEL_STREAM_MEM (mem));
107 			if (bytes && bytes->len)
108 				html_body = g_strndup ((const gchar *) bytes->data, bytes->len);
109 
110 			g_object_unref (mem);
111 		}
112 	}
113 
114 	/* The to-be-displayed part goes first */
115 	partidlen = part_id->len;
116 	g_string_append_printf (part_id, ".related.%d", displayid);
117 
118 	parts = e_mail_parser_parse_part (
119 			parser, display_part, part_id, cancellable);
120 
121 	g_string_truncate (part_id, partidlen);
122 
123 	/* Process the related parts */
124 	nparts = camel_multipart_get_number (mp);
125 	for (i = 0; i < nparts; i++) {
126 		GSList *list, *iter;
127 		body_part = camel_multipart_get_part (mp, i);
128 		list = NULL;
129 
130 		if (body_part == display_part)
131 			continue;
132 
133 		g_string_append_printf (part_id, ".related.%d", i);
134 
135 		list = e_mail_parser_parse_part (
136 				parser, body_part, part_id, cancellable);
137 
138 		g_string_truncate (part_id, partidlen);
139 
140 		for (iter = list; iter; iter = iter->next) {
141 			EMailPart *mail_part;
142 
143 			mail_part = iter->data;
144 			if (!mail_part)
145 				continue;
146 
147 			/* Don't render the part on it's own! */
148 			if (e_mail_part_utils_body_refers (html_body, mail_part->cid))
149 				mail_part->is_hidden = TRUE;
150 		}
151 
152 		parts = g_slist_concat (parts, list);
153 	}
154 
155 	g_free (html_body);
156 
157 	return parts;
158 }
159 
160 static const gchar **
161 empe_mp_related_mime_types (EMailExtension *extension)
162 {
163 	return parser_mime_types;
164 }
165 
166 static void
167 e_mail_parser_multipart_related_class_init (EMailParserMultipartRelatedClass *class)
168 {
169 }
170 
171 static void
172 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
173 {
174 	iface->parse = empe_mp_related_parse;
175 }
176 
177 static void
178 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
179 {
180 	iface->mime_types = empe_mp_related_mime_types;
181 }
182 
183 static void
184 e_mail_parser_multipart_related_init (EMailParserMultipartRelated *parser)
185 {
186 
187 }