2
* e-mail-formatter-print.c
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.
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.
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/>
19
#include "e-mail-formatter-print.h"
21
#include <camel/camel.h>
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"
30
#include <glib/gi18n.h>
32
static gpointer e_mail_formatter_print_parent_class = 0;
35
write_attachments_list (EMailFormatter *formatter,
36
EMailFormatterContext *context,
39
GCancellable *cancellable)
48
"<table border=\"0\" cellspacing=\"5\" cellpadding=\"0\" "
49
"class=\"attachments-list\" >\n");
50
g_string_append_printf (str,
51
"<tr><th colspan=\"2\"><h1>%s</h1></td></tr>\n"
52
"<tr><th>%s</th><th>%s</th></tr>\n",
53
_("Attachments"), _("Name"), _("Size"));
55
for (iter = attachments; iter; iter = iter->next) {
56
EMailPartAttachment *part = iter->data;
57
EAttachment *attachment;
64
attachment = part->attachment;
65
fi = e_attachment_get_file_info (attachment);
69
if (e_attachment_get_description (attachment) &&
70
*e_attachment_get_description (attachment)) {
71
name = g_strdup_printf ("%s (%s)",
72
e_attachment_get_description (attachment),
73
g_file_info_get_display_name (fi));
75
name = g_strdup (g_file_info_get_display_name (fi));
78
size = g_format_size (g_file_info_get_size (fi));
80
g_string_append_printf (str, "<tr><td>%s</td><td>%s</td></tr>\n",
87
g_string_append (str, "</table>\n");
89
camel_stream_write_string (stream, str->str, cancellable, NULL);
90
g_string_free (str, TRUE);
94
mail_formatter_print_run (EMailFormatter *formatter,
95
EMailFormatterContext *context,
97
GCancellable *cancellable)
102
context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
104
camel_stream_write_string (stream,
105
"<!DOCTYPE HTML>\n<html>\n"
106
"<head>\n<meta name=\"generator\" content=\"Evolution Mail Component\" />\n"
107
"<title>Evolution Mail Display</title>\n"
108
"<link type=\"text/css\" rel=\"stylesheet\" media=\"print\" "
109
"href=\"evo-file://" EVOLUTION_PRIVDATADIR "/theme/webview-print.css\" />\n"
111
"<body style=\"background: #FFF; color: #000;\">",
115
for (iter = context->parts; iter; iter = g_slist_next (iter)) {
120
if (g_cancellable_is_cancelled (cancellable))
127
if (part->is_hidden && !part->is_error) {
128
if (g_str_has_suffix (part->id, ".rfc822")) {
129
iter = e_mail_formatter_find_rfc822_end_iter (iter);
135
if (!part->mime_type)
138
if (part->is_attachment) {
139
if (part->cid != NULL)
142
attachments = g_slist_append (attachments, part);
145
ok = e_mail_formatter_format_as (
146
formatter, context, part, stream,
147
part->mime_type, cancellable);
149
/* If the written part was message/rfc822 then
150
* jump to the end of the message, because content
151
* of the whole message has been formatted by
152
* message_rfc822 formatter */
153
if (ok && g_str_has_suffix (part->id, ".rfc822")) {
154
iter = e_mail_formatter_find_rfc822_end_iter (iter);
160
write_attachments_list (formatter, context, attachments, stream, cancellable);
162
camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
166
mail_formatter_set_style (EMailFormatter *formatter,
170
EMailFormatterClass *formatter_class;
172
/* White background */
173
GdkColor body_color = { 0, G_MAXUINT16, G_MAXUINT16, G_MAXUINT16 };
175
GdkColor text_color = { 0, 0, 0, 0 };
177
g_object_freeze_notify (G_OBJECT (formatter));
179
/* Set the other colors */
180
formatter_class = E_MAIL_FORMATTER_CLASS (e_mail_formatter_print_parent_class);
181
formatter_class->set_style (formatter, style, state);
183
e_mail_formatter_set_color (
184
formatter, E_MAIL_FORMATTER_COLOR_FRAME, &body_color);
185
e_mail_formatter_set_color (
186
formatter, E_MAIL_FORMATTER_COLOR_CONTENT, &body_color);
187
e_mail_formatter_set_color (
188
formatter, E_MAIL_FORMATTER_COLOR_TEXT, &text_color);
190
g_object_thaw_notify (G_OBJECT (formatter));
194
e_mail_formatter_print_init (EMailFormatterPrint *formatter)
200
e_mail_formatter_print_finalize (GObject *object)
202
/* Chain up to parent's finalize() */
203
G_OBJECT_CLASS (e_mail_formatter_print_parent_class)->finalize (object);
207
e_mail_formatter_print_class_init (EMailFormatterPrintClass *class)
209
GObjectClass *object_class;
210
EMailFormatterClass *formatter_class;
212
e_mail_formatter_print_parent_class = g_type_class_peek_parent (class);
214
formatter_class = E_MAIL_FORMATTER_CLASS (class);
215
formatter_class->run = mail_formatter_print_run;
216
formatter_class->set_style = mail_formatter_set_style;
218
object_class = G_OBJECT_CLASS (class);
219
object_class->finalize = e_mail_formatter_print_finalize;
223
e_mail_formatter_print_base_init (EMailFormatterPrintClass *class)
225
e_mail_formatter_print_internal_extensions_load (
226
E_MAIL_EXTENSION_REGISTRY (
227
E_MAIL_FORMATTER_CLASS (class)->extension_registry));
229
E_MAIL_FORMATTER_CLASS (class)->text_html_flags =
230
CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
231
CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS |
232
CAMEL_MIME_FILTER_TOHTML_CONVERT_ADDRESSES;
236
e_mail_formatter_print_new (void)
238
return g_object_new (E_TYPE_MAIL_FORMATTER_PRINT, NULL);
242
e_mail_formatter_print_get_type (void)
244
static GType type = 0;
246
if (G_UNLIKELY (type == 0)) {
247
const GTypeInfo type_info = {
248
sizeof (EMailFormatterClass),
249
(GBaseInitFunc) e_mail_formatter_print_base_init,
250
(GBaseFinalizeFunc) NULL,
251
(GClassInitFunc) e_mail_formatter_print_class_init,
252
(GClassFinalizeFunc) NULL,
253
NULL, /* class_data */
254
sizeof (EMailFormatterPrint),
256
(GInstanceInitFunc) e_mail_formatter_print_init,
257
NULL /* value_table */
260
type = g_type_register_static (E_TYPE_MAIL_FORMATTER,
261
"EMailFormatterPrint", &type_info, 0);