1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
|
/*
* e-mail-formatter-itip.c
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with the program; if not, see <http://www.gnu.org/licenses/>
*
*/
#include "e-mail-formatter-itip.h"
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <glib/gi18n-lib.h>
#include <em-format/e-mail-formatter-extension.h>
#include <em-format/e-mail-formatter.h>
#include <em-format/e-mail-part-utils.h>
#include <libebackend/libebackend.h>
#include "itip-view.h"
#include "e-mail-part-itip.h"
#define d(x)
typedef GObject EMailFormatterItip;
typedef GObjectClass EMailFormatterItipClass;
typedef EExtension EMailFormatterItipLoader;
typedef EExtensionClass EMailFormatterItipLoaderClass;
GType e_mail_formatter_itip_get_type (void);
GType e_mail_formatter_itip_loader_get_type (void);
static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
G_DEFINE_DYNAMIC_TYPE_EXTENDED (
EMailFormatterItip,
e_mail_formatter_itip,
G_TYPE_OBJECT,
0,
G_IMPLEMENT_INTERFACE_DYNAMIC (
E_TYPE_MAIL_FORMATTER_EXTENSION,
e_mail_formatter_formatter_extension_interface_init));
G_DEFINE_DYNAMIC_TYPE (
EMailFormatterItipLoader,
e_mail_formatter_itip_loader,
E_TYPE_EXTENSION)
static const gchar *formatter_mime_types[] = {
"text/calendar",
"application/ics",
NULL
};
static gboolean
emfe_itip_format (EMailFormatterExtension *extension,
EMailFormatter *formatter,
EMailFormatterContext *context,
EMailPart *part,
CamelStream *stream,
GCancellable *cancellable)
{
GString *buffer;
EMailPartItip *itip_part;
g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartItip), FALSE);
itip_part = (EMailPartItip *) part;
if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
buffer = g_string_sized_new (1024);
itip_part->view = itip_view_new (itip_part, itip_part->registry);
itip_view_init_view (itip_part->view);
itip_view_write_for_printing (itip_part->view, buffer);
} else if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
buffer = g_string_sized_new (2048);
itip_view_write (formatter, buffer);
} else {
CamelFolder *folder;
CamelMimeMessage *message;
const gchar *message_uid;
gchar *uri;
folder = e_mail_part_list_get_folder (context->part_list);
message = e_mail_part_list_get_message (context->part_list);
message_uid = e_mail_part_list_get_message_uid (context->part_list);
/* mark message as containing calendar, thus it will show the
* icon in message list now on */
if (message_uid != NULL && folder != NULL &&
!camel_folder_get_message_user_flag (
folder, message_uid, "$has_cal")) {
camel_folder_set_message_user_flag (
folder, message_uid, "$has_cal", TRUE);
}
itip_part->folder = g_object_ref (folder);
itip_part->uid = g_strdup (message_uid);
itip_part->msg = g_object_ref (message);
uri = e_mail_part_build_uri (
folder, message_uid,
"part_id", G_TYPE_STRING, part->id,
"mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
NULL);
buffer = g_string_sized_new (256);
g_string_append_printf (
buffer,
"<div class=\"part-container\" "
"style=\"border: none; background: none;\">"
"<iframe width=\"100%%\" height=\"auto\""
" frameborder=\"0\" src=\"%s\" name=\"%s\" id=\"%s\"></iframe>"
"</div>",
uri, part->id, part->id);
g_free (uri);
}
camel_stream_write_string (stream, buffer->str, cancellable, NULL);
g_string_free (buffer, TRUE);
return TRUE;
}
static const gchar *
emfe_itip_get_display_name (EMailFormatterExtension *extension)
{
return _("ITIP");
}
static const gchar *
emfe_itip_get_description (EMailFormatterExtension *extension)
{
return _("Display part as an invitation");
}
static void
e_mail_formatter_itip_class_init (EMailFormatterItipClass *class)
{
}
static void
e_mail_formatter_itip_class_finalize (EMailFormatterItipClass *class)
{
}
static void
e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
{
iface->mime_types = formatter_mime_types;
iface->format = emfe_itip_format;
iface->get_display_name = emfe_itip_get_display_name;
iface->get_description = emfe_itip_get_description;
}
static void
e_mail_formatter_itip_init (EMailFormatterItip *formatter)
{
}
static void
mail_formatter_itip_loader_constructed (GObject *object)
{
EExtensible *extensible;
extensible = e_extension_get_extensible (E_EXTENSION (object));
e_mail_extension_registry_add_extension (
E_MAIL_EXTENSION_REGISTRY (extensible),
formatter_mime_types,
e_mail_formatter_itip_get_type ());
}
static void
e_mail_formatter_itip_loader_class_init (EExtensionClass *class)
{
GObjectClass *object_class;
object_class = G_OBJECT_CLASS (class);
object_class->constructed = mail_formatter_itip_loader_constructed;
class->extensible_type = E_TYPE_MAIL_FORMATTER_EXTENSION_REGISTRY;
}
static void
e_mail_formatter_itip_loader_class_finalize (EExtensionClass *class)
{
}
static void
e_mail_formatter_itip_loader_init (EExtension *extension)
{
}
void
e_mail_formatter_itip_type_register (GTypeModule *type_module)
{
e_mail_formatter_itip_register_type (type_module);
e_mail_formatter_itip_loader_register_type (type_module);
}
|