~ubuntu-branches/ubuntu/wily/evolution/wily

« back to all changes in this revision

Viewing changes to em-format/e-mail-formatter-print.c

  • Committer: Package Import Robot
  • Author(s): Mathieu Trudel-Lapierre
  • Date: 2012-07-03 23:07:40 UTC
  • mfrom: (1.1.92)
  • Revision ID: package-import@ubuntu.com-20120703230740-0hjh6kfpxsyb88gx
Tags: 3.5.3.1-0ubuntu1
* New upstream release 3.5.3.1.
* debian/control:
  - Add libwebkitgtk-3.0-dev, libjavascriptcoregtk-3.0-dev >= 1.8.0 to build
    dependencies.
  - Adjust Build-Depends for the new minimum versions required for EDS 3.5.
  - Also update evolution's Depends to require evolution-data-server >= 3.5,
    and << 3.6.
* debian/rules:
  - Update ELIBDIR to point to /usr/lib/evolution/3.6 now, as per the base
    version defined in configure.
  - Build all plugins rather than enabling experimental specifically; we can
    sort them to other packages after.
  - Drop the binary-install/evolution-common target.
* debian/patches/01_ubuntu_signature.patch: dropped; upstream code has changed
  sufficiently that it would pretty much need a rewrite; and Evolution is no
  longer the default shipped mail client on Desktop.
* debian/patches/04_delay_alarm_notifier.patch: refreshed.
* debian/patches/89_remove_component_id_registration.patch: dropped: we don't
  have UNE anymore and component ID registration has been moved to GSettings.
* debian/patches/10_revert_libevolution_avoid-version.patch: refreshed.
* debian/patches/91_add_u1_email_translations.patch: refreshed.
* debian/evolution-common.install:
  - Drop debian/signature.py.
  - Don't install /usr/share/mime-info; it's not built anymore.
* debian/signature.py: dropped; since we dropped the Ubuntu signature patch.
* debian/evolution.install: don't try to install files in /etc/gconf; evo
  has migrated to GSettings so there are no such files anymore.
* debian/evolution.install,
  debian/evolution-plugins.install,
  debian/evolution-plugins-experimental.install: remove the plugins that were
  converted to modules. Modules are already installed by libevolution.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 (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"));
 
54
 
 
55
        for (iter = attachments; iter; iter = iter->next) {
 
56
                EMailPartAttachment *part = iter->data;
 
57
                EAttachment *attachment;
 
58
                GFileInfo *fi;
 
59
                gchar *name, *size;
 
60
 
 
61
                if (!part)
 
62
                        continue;
 
63
 
 
64
                attachment = part->attachment;
 
65
                fi = e_attachment_get_file_info (attachment);
 
66
                if (!fi)
 
67
                        continue;
 
68
 
 
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));
 
74
                } else {
 
75
                        name = g_strdup (g_file_info_get_display_name (fi));
 
76
                }
 
77
 
 
78
                size = g_format_size (g_file_info_get_size (fi));
 
79
 
 
80
                g_string_append_printf (str, "<tr><td>%s</td><td>%s</td></tr>\n",
 
81
                        name, size);
 
82
 
 
83
                g_free (name);
 
84
                g_free (size);
 
85
        }
 
86
 
 
87
        g_string_append (str, "</table>\n");
 
88
 
 
89
        camel_stream_write_string (stream, str->str, cancellable, NULL);
 
90
        g_string_free (str, TRUE);
 
91
}
 
92
 
 
93
static void
 
94
mail_formatter_print_run (EMailFormatter *formatter,
 
95
                          EMailFormatterContext *context,
 
96
                          CamelStream *stream,
 
97
                          GCancellable *cancellable)
 
98
{
 
99
        GSList *iter;
 
100
        GSList *attachments;
 
101
 
 
102
        context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
 
103
 
 
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"
 
110
                "</head>\n"
 
111
                "<body style=\"background: #FFF; color: #000;\">",
 
112
                cancellable, NULL);
 
113
 
 
114
        attachments = NULL;
 
115
        for (iter = context->parts; iter; iter = g_slist_next (iter)) {
 
116
 
 
117
                EMailPart *part;
 
118
                gboolean ok;
 
119
 
 
120
                if (g_cancellable_is_cancelled (cancellable))
 
121
                        break;
 
122
 
 
123
                part = iter->data;
 
124
                if (!part)
 
125
                        continue;
 
126
 
 
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);
 
130
                        }
 
131
 
 
132
                        continue;
 
133
                }
 
134
 
 
135
                if (!part->mime_type)
 
136
                        continue;
 
137
 
 
138
                if (part->is_attachment) {
 
139
                        if (part->cid != NULL)
 
140
                                continue;
 
141
 
 
142
                        attachments = g_slist_append (attachments, part);
 
143
                }
 
144
 
 
145
                ok = e_mail_formatter_format_as (
 
146
                        formatter, context, part, stream,
 
147
                        part->mime_type, cancellable);
 
148
 
 
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);
 
155
 
 
156
                        continue;
 
157
                }
 
158
        }
 
159
 
 
160
        write_attachments_list (formatter, context, attachments, stream, cancellable);
 
161
 
 
162
        camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
 
163
}
 
164
 
 
165
static void
 
166
mail_formatter_set_style (EMailFormatter *formatter,
 
167
                          GtkStyle *style,
 
168
                          GtkStateType state)
 
169
{
 
170
        EMailFormatterClass *formatter_class;
 
171
 
 
172
        /* White background */
 
173
        GdkColor body_color = { 0, G_MAXUINT16, G_MAXUINT16, G_MAXUINT16 };
 
174
        /* Black text */
 
175
        GdkColor text_color = { 0, 0, 0, 0 };
 
176
 
 
177
        g_object_freeze_notify (G_OBJECT (formatter));
 
178
 
 
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);
 
182
 
 
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);
 
189
 
 
190
        g_object_thaw_notify (G_OBJECT (formatter));
 
191
}
 
192
 
 
193
static void
 
194
e_mail_formatter_print_init (EMailFormatterPrint *formatter)
 
195
{
 
196
 
 
197
}
 
198
 
 
199
static void
 
200
e_mail_formatter_print_finalize (GObject *object)
 
201
{
 
202
        /* Chain up to parent's finalize() */
 
203
        G_OBJECT_CLASS (e_mail_formatter_print_parent_class)->finalize (object);
 
204
}
 
205
 
 
206
static void
 
207
e_mail_formatter_print_class_init (EMailFormatterPrintClass *class)
 
208
{
 
209
        GObjectClass *object_class;
 
210
        EMailFormatterClass *formatter_class;
 
211
 
 
212
        e_mail_formatter_print_parent_class = g_type_class_peek_parent (class);
 
213
 
 
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;
 
217
 
 
218
        object_class = G_OBJECT_CLASS (class);
 
219
        object_class->finalize = e_mail_formatter_print_finalize;
 
220
}
 
221
 
 
222
static void
 
223
e_mail_formatter_print_base_init (EMailFormatterPrintClass *class)
 
224
{
 
225
        e_mail_formatter_print_internal_extensions_load (
 
226
                E_MAIL_EXTENSION_REGISTRY (
 
227
                        E_MAIL_FORMATTER_CLASS (class)->extension_registry));
 
228
 
 
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;
 
233
}
 
234
 
 
235
EMailFormatter *
 
236
e_mail_formatter_print_new (void)
 
237
{
 
238
        return g_object_new (E_TYPE_MAIL_FORMATTER_PRINT, NULL);
 
239
}
 
240
 
 
241
GType
 
242
e_mail_formatter_print_get_type (void)
 
243
{
 
244
        static GType type = 0;
 
245
 
 
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),
 
255
                        0,      /* n_preallocs */
 
256
                        (GInstanceInitFunc) e_mail_formatter_print_init,
 
257
                        NULL    /* value_table */
 
258
                };
 
259
 
 
260
                type = g_type_register_static (E_TYPE_MAIL_FORMATTER,
 
261
                                "EMailFormatterPrint", &type_info, 0);
 
262
        }
 
263
 
 
264
        return type;
 
265
}
 
266