evolution-3.6.4/em-format/e-mail-formatter-source.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-formatter-source.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-formatter-source.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  * evolution-source.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-formatter-extension.h>
 26 #include <em-format/e-mail-formatter.h>
 27 #include <em-format/e-mail-inline-filter.h>
 28 #include <e-util/e-util.h>
 29 
 30 #include <glib/gi18n-lib.h>
 31 #include <camel/camel.h>
 32 
 33 typedef struct _EMailFormatterSource {
 34 	GObject parent;
 35 } EMailFormatterSource;
 36 
 37 typedef struct _EMailFormatterSourceClass {
 38 	GObjectClass parent_class;
 39 } EMailFormatterSourceClass;
 40 
 41 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
 42 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
 43 
 44 G_DEFINE_TYPE_EXTENDED (
 45 	EMailFormatterSource,
 46 	e_mail_formatter_source,
 47 	G_TYPE_OBJECT,
 48 	0,
 49 	G_IMPLEMENT_INTERFACE (
 50 		E_TYPE_MAIL_EXTENSION,
 51 		e_mail_formatter_mail_extension_interface_init)
 52 	G_IMPLEMENT_INTERFACE (
 53 		E_TYPE_MAIL_FORMATTER_EXTENSION,
 54 		e_mail_formatter_formatter_extension_interface_init)
 55 )
 56 
 57 static const gchar *formatter_mime_types[] = { "application/vnd.evolution.source", NULL };
 58 
 59 static gboolean
 60 emfe_source_format (EMailFormatterExtension *extension,
 61                     EMailFormatter *formatter,
 62                     EMailFormatterContext *context,
 63                     EMailPart *part,
 64                     CamelStream *stream,
 65                     GCancellable *cancellable)
 66 {
 67 	GString *buffer;
 68 	CamelStream *filtered_stream;
 69 	CamelMimeFilter *filter;
 70 	CamelDataWrapper *dw = (CamelDataWrapper *) part->part;
 71 
 72 	filtered_stream = camel_stream_filter_new (stream);
 73 
 74 	filter = camel_mime_filter_tohtml_new (
 75 		CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
 76 		CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
 77 		CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT, 0);
 78 	camel_stream_filter_add (
 79 		CAMEL_STREAM_FILTER (filtered_stream), filter);
 80 	g_object_unref (filter);
 81 
 82 	buffer = g_string_new ("");
 83 
 84 	if (CAMEL_IS_MIME_MESSAGE (part->part)) {
 85 		g_string_append_printf (
 86 			buffer,
 87 			"<div class=\"part-container\" "
 88 			"style=\"border: 0; background: #%06x; color: #%06x;\" >",
 89 			e_color_to_value ((GdkColor *)
 90 				e_mail_formatter_get_color (
 91 					formatter, E_MAIL_FORMATTER_COLOR_BODY)),
 92 			e_color_to_value ((GdkColor *)
 93 				e_mail_formatter_get_color (
 94 					formatter, E_MAIL_FORMATTER_COLOR_TEXT)));
 95 	} else {
 96 		g_string_append_printf (
 97 			buffer,
 98 			"<div class=\"part-container\" "
 99 			"style=\"border-color: #%06x; background: #%06x; color: #%06x;\">"
100 			"<div class=\"part-container-inner-margin pre\">\n",
101 			e_color_to_value ((GdkColor *)
102 				e_mail_formatter_get_color (
103 					formatter, E_MAIL_FORMATTER_COLOR_FRAME)),
104 			e_color_to_value ((GdkColor *)
105 				e_mail_formatter_get_color (
106 					formatter, E_MAIL_FORMATTER_COLOR_BODY)),
107 			e_color_to_value ((GdkColor *)
108 				e_mail_formatter_get_color (
109 					formatter, E_MAIL_FORMATTER_COLOR_TEXT)));
110 	}
111 
112 	camel_stream_write_string (
113 		stream, buffer->str, cancellable, NULL);
114 	camel_stream_write_string (
115 		stream, "<code class=\"pre\">", cancellable, NULL);
116 
117 	camel_data_wrapper_write_to_stream_sync (
118 		dw, filtered_stream,
119 		cancellable, NULL);
120 	camel_stream_flush (filtered_stream, cancellable, NULL);
121 	g_object_unref (filtered_stream);
122 
123 	camel_stream_write_string (
124 		stream, "</code>", cancellable, NULL);
125 
126 	g_string_free (buffer, TRUE);
127 
128 	if (CAMEL_IS_MIME_MESSAGE (part->part)) {
129 		camel_stream_write_string (stream, "</div>", cancellable, NULL);
130 	} else {
131 		camel_stream_write_string (stream, "</div></div>", cancellable, NULL);
132 	}
133 
134 	return TRUE;
135 }
136 
137 static const gchar *
138 emfe_source_get_display_name (EMailFormatterExtension *extension)
139 {
140 	return _("Source");
141 }
142 
143 static const gchar *
144 emfe_source_get_description (EMailFormatterExtension *extension)
145 {
146 	return _("Display source of a MIME part");
147 }
148 
149 static const gchar **
150 emfe_source_mime_types (EMailExtension *extension)
151 {
152 	return formatter_mime_types;
153 }
154 
155 static void
156 e_mail_formatter_source_class_init (EMailFormatterSourceClass *class)
157 {
158 }
159 
160 static void
161 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
162 {
163 	iface->format = emfe_source_format;
164 	iface->get_display_name = emfe_source_get_display_name;
165 	iface->get_description = emfe_source_get_description;
166 }
167 
168 static void
169 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
170 {
171 	iface->mime_types = emfe_source_mime_types;
172 }
173 
174 static void
175 e_mail_formatter_source_init (EMailFormatterSource *formatter)
176 {
177 
178 }