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

No issues found

Incomplete coverage

Tool Failure ID Location Function Message Data
clang-analyzer no-output-found e-mail-formatter-print.c Message(text='Unable to locate XML output from invoke-clang-analyzer') None
clang-analyzer no-output-found e-mail-formatter-print.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-print.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 #include "e-mail-formatter-print.h"
 20 
 21 #include <camel/camel.h>
 22 
 23 #include "e-mail-format-extensions.h"
 24 #include "e-mail-part-attachment.h"
 25 #include "e-mail-formatter-extension.h"
 26 #include "e-mail-formatter-utils.h"
 27 #include "e-mail-part.h"
 28 
 29 #include <gdk/gdk.h>
 30 #include <glib/gi18n.h>
 31 
 32 static gpointer e_mail_formatter_print_parent_class = 0;
 33 
 34 static void
 35 write_attachments_list (EMailFormatter *formatter,
 36                         EMailFormatterContext *context,
 37                         GSList *attachments,
 38                         CamelStream *stream,
 39                         GCancellable *cancellable)
 40 {
 41 	GString *str;
 42 	GSList *iter;
 43 
 44 	if (!attachments)
 45 		return;
 46 
 47 	str = g_string_new (
 48 		"<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" "
 49 		"class=\"attachments-list\" >\n");
 50 	g_string_append_printf (
 51 		str,
 52 		"<tr><th colspan=\"2\"><h1>%s</h1></td></tr>\n"
 53 		"<tr><th>%s</th><th>%s</th></tr>\n",
 54 		_("Attachments"), _("Name"), _("Size"));
 55 
 56 	for (iter = attachments; iter; iter = iter->next) {
 57 		EMailPartAttachment *part = iter->data;
 58 		EAttachment *attachment;
 59 		GFileInfo *fi;
 60 		gchar *name, *size;
 61 
 62 		if (!part)
 63 			continue;
 64 
 65 		attachment = part->attachment;
 66 		fi = e_attachment_get_file_info (attachment);
 67 		if (!fi)
 68 			continue;
 69 
 70 		if (e_attachment_get_description (attachment) &&
 71                     *e_attachment_get_description (attachment)) {
 72 			name = g_strdup_printf (
 73 				"%s (%s)",
 74 				e_attachment_get_description (attachment),
 75 				g_file_info_get_display_name (fi));
 76 		} else {
 77 			name = g_strdup (g_file_info_get_display_name (fi));
 78 		}
 79 
 80 		size = g_format_size (g_file_info_get_size (fi));
 81 
 82 		g_string_append_printf (
 83 			str, "<tr><td>%s</td><td>%s</td></tr>\n",
 84 			name, size);
 85 
 86 		g_free (name);
 87 		g_free (size);
 88 	}
 89 
 90 	g_string_append (str, "</table>\n");
 91 
 92 	camel_stream_write_string (stream, str->str, cancellable, NULL);
 93 	g_string_free (str, TRUE);
 94 }
 95 
 96 static void
 97 mail_formatter_print_run (EMailFormatter *formatter,
 98                           EMailFormatterContext *context,
 99                           CamelStream *stream,
100                           GCancellable *cancellable)
101 {
102 	GSList *iter;
103 	GSList *attachments;
104 
105 	context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
106 
107 	camel_stream_write_string (
108 		stream,
109 		"<!DOCTYPE HTML>\n<html>\n"
110 		"<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n"
111 		"<title>Evolution Mail Display</title>\n"
112 		"<link type=\"text/css\" rel=\"stylesheet\" media=\"print\" "
113 		"href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview-print.css\" />\n"
114 		"</head>\n"
115 		"<body style=\"background: #FFF; color: #000;\">",
116 		cancellable, NULL);
117 
118 	attachments = NULL;
119 	for (iter = context->parts; iter; iter = g_slist_next (iter)) {
120 
121 		EMailPart *part;
122 		gboolean ok;
123 
124 		if (g_cancellable_is_cancelled (cancellable))
125 			break;
126 
127 		part = iter->data;
128 		if (!part)
129 			continue;
130 
131 		if (part->is_hidden && !part->is_error) {
132 			if (g_str_has_suffix (part->id, ".rfc822")) {
133 				iter = e_mail_formatter_find_rfc822_end_iter (iter);
134 			}
135 
136 			continue;
137 		}
138 
139 		if (!part->mime_type)
140 			continue;
141 
142 		if (part->is_attachment) {
143 			if (part->cid != NULL)
144 				continue;
145 
146 			attachments = g_slist_append (attachments, part);
147 		}
148 
149 		ok = e_mail_formatter_format_as (
150 			formatter, context, part, stream,
151 			part->mime_type, cancellable);
152 
153 		/* If the written part was message/rfc822 then
154 		 * jump to the end of the message, because content
155 		 * of the whole message has been formatted by
156 		 * message_rfc822 formatter */
157 		if (ok && g_str_has_suffix (part->id, ".rfc822")) {
158 			iter = e_mail_formatter_find_rfc822_end_iter (iter);
159 
160 			continue;
161 		}
162 	}
163 
164 	write_attachments_list (formatter, context, attachments, stream, cancellable);
165 
166 	g_slist_free (attachments);
167 
168 	camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
169 }
170 
171 static void
172 mail_formatter_set_style (EMailFormatter *formatter,
173                           GtkStyle *style,
174                           GtkStateType state)
175 {
176 	EMailFormatterClass *formatter_class;
177 
178 	/* White background */
179 	GdkColor body_color = { 0, G_MAXUINT16, G_MAXUINT16, G_MAXUINT16 };
180 	/* Black text */
181 	GdkColor text_color = { 0, 0, 0, 0 };
182 
183 	g_object_freeze_notify (G_OBJECT (formatter));
184 
185 	/* Set the other colors */
186 	formatter_class = E_MAIL_FORMATTER_CLASS (e_mail_formatter_print_parent_class);
187 	formatter_class->set_style (formatter, style, state);
188 
189 	e_mail_formatter_set_color (
190 		formatter, E_MAIL_FORMATTER_COLOR_FRAME, &body_color);
191 	e_mail_formatter_set_color (
192 		formatter, E_MAIL_FORMATTER_COLOR_CONTENT, &body_color);
193 	e_mail_formatter_set_color (
194 		formatter, E_MAIL_FORMATTER_COLOR_TEXT, &text_color);
195 
196 	g_object_thaw_notify (G_OBJECT (formatter));
197 }
198 
199 static void
200 e_mail_formatter_print_init (EMailFormatterPrint *formatter)
201 {
202 
203 }
204 
205 static void
206 e_mail_formatter_print_finalize (GObject *object)
207 {
208 	/* Chain up to parent's finalize() */
209 	G_OBJECT_CLASS (e_mail_formatter_print_parent_class)->finalize (object);
210 }
211 
212 static void
213 e_mail_formatter_print_class_init (EMailFormatterPrintClass *class)
214 {
215 	GObjectClass *object_class;
216 	EMailFormatterClass *formatter_class;
217 
218 	e_mail_formatter_print_parent_class = g_type_class_peek_parent (class);
219 
220 	formatter_class = E_MAIL_FORMATTER_CLASS (class);
221 	formatter_class->run = mail_formatter_print_run;
222 	formatter_class->set_style = mail_formatter_set_style;
223 
224 	object_class = G_OBJECT_CLASS (class);
225 	object_class->finalize = e_mail_formatter_print_finalize;
226 }
227 
228 static void
229 e_mail_formatter_print_base_init (EMailFormatterPrintClass *class)
230 {
231 	e_mail_formatter_print_internal_extensions_load (
232 		E_MAIL_EXTENSION_REGISTRY (
233 			E_MAIL_FORMATTER_CLASS (class)->extension_registry));
234 
235 	E_MAIL_FORMATTER_CLASS (class)->text_html_flags =
236 		CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
237 		CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
238 		CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES;
239 }
240 
241 EMailFormatter *
242 e_mail_formatter_print_new (void)
243 {
244 	return g_object_new (E_TYPE_MAIL_FORMATTER_PRINT, NULL);
245 }
246 
247 GType
248 e_mail_formatter_print_get_type (void)
249 {
250 	static GType type = 0;
251 
252 	if (G_UNLIKELY (type == 0)) {
253 		const GTypeInfo type_info = {
254 			sizeof (EMailFormatterClass),
255 			(GBaseInitFunc) e_mail_formatter_print_base_init,
256 			(GBaseFinalizeFunc) NULL,
257 			(GClassInitFunc) e_mail_formatter_print_class_init,
258 			(GClassFinalizeFunc) NULL,
259 			NULL,	/* class_data */
260 			sizeof (EMailFormatterPrint),
261 			0,	/* n_preallocs */
262 			(GInstanceInitFunc) e_mail_formatter_print_init,
263 			NULL	/* value_table */
264 		};
265 
266 		type = g_type_register_static (
267 			E_TYPE_MAIL_FORMATTER,
268 			"EMailFormatterPrint", &type_info, 0);
269 	}
270 
271 	return type;
272 }