evolution-3.6.4/em-format/e-mail-formatter-text-plain.c

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-formatter-text-plain.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-formatter-text-plain.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-formatter-text-plain.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 <em-format/e-mail-part-utils.h>
 29 #include <e-util/e-util.h>
 30 
 31 #include <glib/gi18n-lib.h>
 32 #include <camel/camel.h>
 33 
 34 static const gchar *formatter_mime_types[] = { "text/plain",
 35 					       "text/*",
 36 					       "message/*",
 37 					       "application/vnd.evolution.plaintext",
 38 					       NULL };
 39 
 40 typedef struct _EMailFormatterTextPlain {
 41 	GObject parent;
 42 } EMailFormatterTextPlain;
 43 
 44 typedef struct _EMailFormatterTextPlainClass {
 45 	GObjectClass parent_class;
 46 } EMailFormatterTextPlainClass;
 47 
 48 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
 49 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
 50 
 51 G_DEFINE_TYPE_EXTENDED (
 52 	EMailFormatterTextPlain,
 53 	e_mail_formatter_text_plain,
 54 	G_TYPE_OBJECT,
 55 	0,
 56 	G_IMPLEMENT_INTERFACE (
 57 		E_TYPE_MAIL_EXTENSION,
 58 		e_mail_formatter_mail_extension_interface_init)
 59 	G_IMPLEMENT_INTERFACE (
 60 		E_TYPE_MAIL_FORMATTER_EXTENSION,
 61 		e_mail_formatter_formatter_extension_interface_init));
 62 
 63 static gboolean
 64 emfe_text_plain_format (EMailFormatterExtension *extension,
 65                         EMailFormatter *formatter,
 66                         EMailFormatterContext *context,
 67                         EMailPart *part,
 68                         CamelStream *stream,
 69                         GCancellable *cancellable)
 70 {
 71 	CamelDataWrapper *dw;
 72 	CamelStream *filtered_stream;
 73 	CamelMimeFilter *html_filter;
 74 	gchar *content;
 75 	const gchar *format;
 76 	guint32 filter_flags;
 77 	guint32 rgb;
 78 
 79 	if (g_cancellable_is_cancelled (cancellable))
 80 		return FALSE;
 81 
 82 	if ((context->mode == E_MAIL_FORMATTER_MODE_RAW) ||
 83 	    (context->mode == E_MAIL_FORMATTER_MODE_PRINTING)) {
 84 
 85 		if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
 86 			gchar *header;
 87 			header = e_mail_formatter_get_html_header (formatter);
 88 			camel_stream_write_string (stream, header, cancellable, NULL);
 89 			g_free (header);
 90 
 91 			/* No need for body margins within <iframe> */
 92 			camel_stream_write_string (
 93 				stream,
 94 				"<style>body{ margin: 0; }</style>",
 95 				cancellable, NULL);
 96 		}
 97 
 98 		filter_flags = e_mail_formatter_get_text_format_flags (formatter);
 99 
100 		dw = camel_medium_get_content (CAMEL_MEDIUM (part->part));
101 		if (!dw)
102 			return FALSE;
103 
104 		/* Check for RFC 2646 flowed text. */
105 		if (camel_content_type_is (dw->mime_type, "text", "plain")
106 		&& (format = camel_content_type_param (dw->mime_type, "format"))
107 		&& !g_ascii_strcasecmp (format, "flowed"))
108 			filter_flags |= CAMEL_MIME_FILTER_TOHTML_FORMAT_FLOWED;
109 
110 		rgb = e_color_to_value ((GdkColor *)
111 			e_mail_formatter_get_color (
112 				formatter, E_MAIL_FORMATTER_COLOR_CITATION));
113 
114 		filtered_stream = camel_stream_filter_new (stream);
115 		html_filter = camel_mime_filter_tohtml_new (filter_flags, rgb);
116 		camel_stream_filter_add (
117 			CAMEL_STREAM_FILTER (filtered_stream), html_filter);
118 		g_object_unref (html_filter);
119 
120 		content = g_strdup_printf (
121 			"<div class=\"part-container pre\" style=\""
122 			"border: none; padding: 8px; margin: 0; "
123 			"background-color: #%06x; color: #%06x;\">\n",
124 			e_color_to_value ((GdkColor *)
125 				e_mail_formatter_get_color (
126 					formatter, E_MAIL_FORMATTER_COLOR_CONTENT)),
127 			e_color_to_value ((GdkColor *)
128 				e_mail_formatter_get_color (
129 					formatter, E_MAIL_FORMATTER_COLOR_TEXT)));
130 
131 		camel_stream_write_string (stream, content, cancellable, NULL);
132 		e_mail_formatter_format_text (formatter, part, filtered_stream, cancellable);
133 		camel_stream_flush (filtered_stream, cancellable, NULL);
134 
135 		g_object_unref (filtered_stream);
136 		g_free (content);
137 
138 		camel_stream_write_string (stream, "</div>\n", cancellable, NULL);
139 
140 		if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
141 			camel_stream_write_string (
142 				stream, "</body></html>",
143 				cancellable, NULL);
144 		}
145 
146 		return TRUE;
147 
148 	} else {
149 		gchar *uri, *str;
150 		const gchar *default_charset, *charset;
151 
152 		default_charset = e_mail_formatter_get_default_charset (formatter);
153 		charset = e_mail_formatter_get_charset (formatter);
154 
155 		if (!default_charset)
156 			default_charset = "";
157 		if (!charset)
158 			charset = "";
159 
160 		uri = e_mail_part_build_uri (
161 			context->folder, context->message_uid,
162 			"part_id", G_TYPE_STRING, part->id,
163 			"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
164 			"formatter_default_charset", G_TYPE_STRING, default_charset,
165 			"formatter_charset", G_TYPE_STRING, charset,
166 			NULL);
167 
168 		str = g_strdup_printf (
169 			"<div class=\"part-container-nostyle\" >"
170 			"<iframe width=\"100%%\" height=\"10\""
171 			" id=\"%s.iframe\" name=\"%s\" "
172 			" frameborder=\"0\" src=\"%s\" "
173 			" style=\"border: 1px solid #%06x; background-color: #%06x;\">"
174 			"</iframe>"
175 			"</div>",
176 			part->id, part->id, uri,
177 			e_color_to_value ((GdkColor *)
178 				e_mail_formatter_get_color (
179 					formatter, E_MAIL_FORMATTER_COLOR_FRAME)),
180 			e_color_to_value ((GdkColor *)
181 				e_mail_formatter_get_color (
182 					formatter, E_MAIL_FORMATTER_COLOR_CONTENT)));
183 
184 		camel_stream_write_string (stream, str, cancellable, NULL);
185 
186 		g_free (str);
187 		g_free (uri);
188 	}
189 
190 	return TRUE;
191 }
192 
193 static const gchar *
194 emfe_text_plain_get_display_name (EMailFormatterExtension *extension)
195 {
196 	return _("Plain Text");
197 }
198 
199 static const gchar *
200 emfe_text_plain_get_description (EMailFormatterExtension *extension)
201 {
202 	return _("Format part as plain text");
203 }
204 
205 static const gchar **
206 emfe_text_plain_mime_types (EMailExtension *extension)
207 {
208 	return formatter_mime_types;
209 }
210 
211 static void
212 e_mail_formatter_text_plain_class_init (EMailFormatterTextPlainClass *class)
213 {
214 }
215 
216 static void
217 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
218 {
219 	iface->format = emfe_text_plain_format;
220 	iface->get_display_name = emfe_text_plain_get_display_name;
221 	iface->get_description = emfe_text_plain_get_description;
222 }
223 
224 static void
225 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
226 {
227 	iface->mime_types = emfe_text_plain_mime_types;
228 }
229 
230 static void
231 e_mail_formatter_text_plain_init (EMailFormatterTextPlain *formatter)
232 {
233 
234 }