No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-itip.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-itip.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-formatter-itip.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-itip.h"
20
21 #ifdef HAVE_CONFIG_H
22 #include <config.h>
23 #endif
24
25 #include <glib/gi18n-lib.h>
26
27 #include <em-format/e-mail-formatter-extension.h>
28 #include <em-format/e-mail-formatter.h>
29 #include <em-format/e-mail-part-utils.h>
30 #include <libebackend/libebackend.h>
31
32 #include "itip-view.h"
33 #include "e-mail-part-itip.h"
34
35 #define d(x)
36
37 typedef struct _EMailFormatterItip {
38 EExtension parent;
39 } EMailFormatterItip;
40
41 typedef struct _EMailFormatterItipClass {
42 EExtensionClass parent_class;
43 } EMailFormatterItipClass;
44
45 GType e_mail_formatter_itip_get_type (void);
46 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
47 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
48
49 G_DEFINE_DYNAMIC_TYPE_EXTENDED (
50 EMailFormatterItip,
51 e_mail_formatter_itip,
52 E_TYPE_EXTENSION,
53 0,
54 G_IMPLEMENT_INTERFACE_DYNAMIC (
55 E_TYPE_MAIL_EXTENSION,
56 e_mail_formatter_mail_extension_interface_init)
57 G_IMPLEMENT_INTERFACE_DYNAMIC (
58 E_TYPE_MAIL_FORMATTER_EXTENSION,
59 e_mail_formatter_formatter_extension_interface_init));
60
61 static const gchar * formatter_mime_types[] = { "text/calendar",
62 "application/ics",
63 NULL };
64
65 static gboolean
66 emfe_itip_format (EMailFormatterExtension *extension,
67 EMailFormatter *formatter,
68 EMailFormatterContext *context,
69 EMailPart *part,
70 CamelStream *stream,
71 GCancellable *cancellable)
72 {
73 GString *buffer;
74 EMailPartItip *itip_part;
75
76 g_return_val_if_fail (E_MAIL_PART_IS (part, EMailPartItip), FALSE);
77 itip_part = (EMailPartItip *) part;
78
79 if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
80 buffer = g_string_sized_new (1024);
81
82 itip_part->view = itip_view_new (itip_part, itip_part->registry);
83
84 itip_view_init_view (itip_part->view);
85 itip_view_write_for_printing (itip_part->view, buffer);
86
87 } else if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
88 buffer = g_string_sized_new (2048);
89
90 itip_view_write (formatter, buffer);
91
92 } else {
93 const gchar *default_charset, *charset;
94 gchar *uri;
95
96 /* mark message as containing calendar, thus it will show the
97 * icon in message list now on */
98 if (context->message_uid && context->folder &&
99 !camel_folder_get_message_user_flag (
100 context->folder, context->message_uid, "$has_cal")) {
101
102 camel_folder_set_message_user_flag (
103 context->folder, context->message_uid,
104 "$has_cal", TRUE);
105 }
106
107 itip_part->folder = g_object_ref (context->folder);
108 itip_part->uid = g_strdup (context->message_uid);
109 itip_part->msg = g_object_ref (context->message);
110
111 default_charset = e_mail_formatter_get_default_charset (formatter);
112 charset = e_mail_formatter_get_charset (formatter);
113
114 if (!default_charset)
115 default_charset = "";
116 if (!charset)
117 charset = "";
118
119 uri = e_mail_part_build_uri (
120 context->folder, context->message_uid,
121 "part_id", G_TYPE_STRING, part->id,
122 "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
123 "formatter_default_charset", G_TYPE_STRING, default_charset,
124 "formatter_charset", G_TYPE_STRING, charset,
125 NULL);
126
127 buffer = g_string_sized_new (256);
128 g_string_append_printf (
129 buffer,
130 "<div class=\"part-container\" "
131 "style=\"border: none; background: none;\">"
132 "<iframe width=\"100%%\" height=\"auto\""
133 " frameborder=\"0\" src=\"%s\" name=\"%s\" id=\"%s\"></iframe>"
134 "</div>",
135 uri, part->id, part->id);
136
137 g_free (uri);
138 }
139
140 camel_stream_write_string (stream, buffer->str, cancellable, NULL);
141
142 g_string_free (buffer, TRUE);
143
144 return TRUE;
145 }
146
147 static const gchar *
148 emfe_itip_get_display_name (EMailFormatterExtension *extension)
149 {
150 return _("ITIP");
151 }
152
153 static const gchar *
154 emfe_itip_get_description (EMailFormatterExtension *extension)
155 {
156 return _("Display part as an invitation");
157 }
158
159 static const gchar **
160 emfe_itip_mime_types (EMailExtension *extension)
161 {
162 return formatter_mime_types;
163 }
164
165 static void
166 e_mail_formatter_itip_constructed (GObject *object)
167 {
168 EExtensible *extensible;
169 EMailExtensionRegistry *reg;
170
171 extensible = e_extension_get_extensible (E_EXTENSION (object));
172 reg = E_MAIL_EXTENSION_REGISTRY (extensible);
173
174 e_mail_extension_registry_add_extension (reg, E_MAIL_EXTENSION (object));
175 }
176
177 static void
178 e_mail_formatter_itip_finalize (GObject *object)
179 {
180 EExtensible *extensible;
181 EMailExtensionRegistry *reg;
182
183 extensible = e_extension_get_extensible (E_EXTENSION (object));
184 reg = E_MAIL_EXTENSION_REGISTRY (extensible);
185
186 e_mail_extension_registry_remove_extension (reg, E_MAIL_EXTENSION (object));
187 }
188
189 static void
190 e_mail_formatter_itip_class_init (EMailFormatterItipClass *class)
191 {
192 GObjectClass *object_class;
193 EExtensionClass *extension_class;
194
195 object_class = G_OBJECT_CLASS (class);
196 object_class->constructed = e_mail_formatter_itip_constructed;
197 object_class->finalize = e_mail_formatter_itip_finalize;
198
199 extension_class = E_EXTENSION_CLASS (class);
200 extension_class->extensible_type = E_TYPE_MAIL_FORMATTER_EXTENSION_REGISTRY;
201 }
202
203 static void
204 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
205 {
206 iface->format = emfe_itip_format;
207 iface->get_display_name = emfe_itip_get_display_name;
208 iface->get_description = emfe_itip_get_description;
209 }
210
211 static void
212 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
213 {
214 iface->mime_types = emfe_itip_mime_types;
215 }
216
217 static void
218 e_mail_formatter_itip_init (EMailFormatterItip *formatter)
219 {
220 }
221
222 void
223 e_mail_formatter_itip_type_register (GTypeModule *type_module)
224 {
225 e_mail_formatter_itip_register_type (type_module);
226 }
227
228 static void
229 e_mail_formatter_itip_class_finalize (EMailFormatterItipClass *class)
230 {
231
232 }