evolution-3.6.4/modules/text-highlight/e-mail-parser-text-highlight.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-parser-text-highlight.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-parser-text-highlight.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 #ifdef HAVE_CONFIG_H
 17 #include <config.h>
 18 #endif
 19 
 20 #include <string.h>
 21 #include <gtk/gtk.h>
 22 #include <glib/gi18n.h>
 23 #include <camel/camel.h>
 24 
 25 #include "e-mail-parser-text-highlight.h"
 26 #include "languages.h"
 27 
 28 #include <em-format/e-mail-extension-registry.h>
 29 #include <em-format/e-mail-parser-extension.h>
 30 #include <em-format/e-mail-part.h>
 31 #include <em-format/e-mail-part-utils.h>
 32 
 33 #include <libebackend/libebackend.h>
 34 
 35 #define d(x)
 36 
 37 typedef struct _EMailParserTextHighlight {
 38 	EExtension parent;
 39 } EMailParserTextHighlight;
 40 
 41 typedef struct _EMailParserTextHighlightClass {
 42 	EExtensionClass parent_class;
 43 } EMailParserTextHighlightClass;
 44 
 45 GType e_mail_parser_text_highlight_get_type (void);
 46 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
 47 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
 48 
 49 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
 50 	EMailParserTextHighlight,
 51 	e_mail_parser_text_highlight,
 52 	E_TYPE_EXTENSION,
 53 	0,
 54 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 55 		E_TYPE_MAIL_EXTENSION,
 56 		e_mail_parser_mail_extension_interface_init)
 57 	G_IMPLEMENT_INTERFACE_DYNAMIC (
 58 		E_TYPE_MAIL_PARSER_EXTENSION,
 59 		e_mail_parser_parser_extension_interface_init));
 60 
 61 static GSList *
 62 empe_text_highlight_parse (EMailParserExtension *extension,
 63                            EMailParser *parser,
 64                            CamelMimePart *part,
 65                            GString *part_id,
 66                            GCancellable *cancellable)
 67 {
 68 	GSList *parts;
 69 	gint len;
 70 	CamelContentType *ct;
 71 
 72 	/* Prevent recursion */
 73 	if (strstr (part_id->str, ".text-highlight") != NULL) {
 74 		return NULL;
 75 	}
 76 
 77 	/* Don't parse text/html if it's not an attachment */
 78 	ct = camel_mime_part_get_content_type (part);
 79 	if (camel_content_type_is (ct, "text", "html")) {
 80 		const CamelContentDisposition *disp;
 81 
 82 		disp = camel_mime_part_get_content_disposition (part);
 83 		if (!disp || (g_strcmp0 (disp->disposition, "attachment") != 0)) {
 84 			return NULL;
 85 		}
 86 	}
 87 
 88 	len = part_id->len;
 89 	g_string_append (part_id, ".text-highlight");
 90 
 91 	/* All source codes and scripts are in general plain texts,
 92 	 * so let text/plain parser handle it. */
 93 	parts = e_mail_parser_parse_part_as (
 94 			parser, part, part_id, "text/plain", cancellable);
 95 
 96 	g_string_truncate (part_id, len);
 97 
 98 	return parts;
 99 }
100 
101 static const gchar **
102 empe_mime_types (EMailExtension *extension)
103 {
104 	return get_mime_types ();
105 }
106 
107 void
108 e_mail_parser_text_highlight_type_register (GTypeModule *type_module)
109 {
110 	e_mail_parser_text_highlight_register_type (type_module);
111 }
112 
113 static void
114 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
115 {
116 	iface->mime_types = empe_mime_types;
117 }
118 
119 static void
120 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
121 {
122 	iface->parse = empe_text_highlight_parse;
123 }
124 
125 static void
126 e_mail_parser_text_highlight_constructed (GObject *object)
127 {
128 	EExtensible *extensible;
129 	EMailExtensionRegistry *reg;
130 
131 	extensible = e_extension_get_extensible (E_EXTENSION (object));
132 	reg = E_MAIL_EXTENSION_REGISTRY (extensible);
133 
134 	e_mail_extension_registry_add_extension (reg, E_MAIL_EXTENSION (object));
135 }
136 
137 static void
138 e_mail_parser_text_highlight_class_init (EMailParserTextHighlightClass *class)
139 {
140 	GObjectClass *object_class;
141 	EExtensionClass *extension_class;
142 
143 	object_class = G_OBJECT_CLASS (class);
144 	object_class->constructed = e_mail_parser_text_highlight_constructed;
145 
146 	extension_class = E_EXTENSION_CLASS (class);
147 	extension_class->extensible_type = E_TYPE_MAIL_PARSER_EXTENSION_REGISTRY;
148 }
149 
150 void
151 e_mail_parser_text_highlight_class_finalize (EMailParserTextHighlightClass *class)
152 {
153 }
154 
155 static void
156 e_mail_parser_text_highlight_init (EMailParserTextHighlight *parser)
157 {
158 
159 }