No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-message-rfc822.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-message-rfc822.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-formatter-message-rfc822.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 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include "e-mail-format-extensions.h"
24
25 #include <glib/gi18n-lib.h>
26 #include <glib-object.h>
27
28 #include <em-format/e-mail-formatter-extension.h>
29 #include <em-format/e-mail-formatter.h>
30 #include <em-format/e-mail-part-list.h>
31 #include <em-format/e-mail-part-utils.h>
32 #include <e-util/e-util.h>
33
34 #include <camel/camel.h>
35
36 #include <string.h>
37
38 static const gchar * formatter_mime_types[] = { "message/rfc822",
39 "application/vnd.evolution.rfc822.end",
40 NULL };
41
42 typedef struct _EMailFormatterMessageRFC822 {
43 GObject parent;
44 } EMailFormatterMessageRFC822;
45
46 typedef struct _EMailFormatterMessageRFC822Class {
47 GObjectClass parent_class;
48 } EMailFormatterMessageRFC822Class;
49
50 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
51 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
52
53 G_DEFINE_TYPE_EXTENDED (
54 EMailFormatterMessageRFC822,
55 e_mail_formatter_message_rfc822,
56 G_TYPE_OBJECT,
57 0,
58 G_IMPLEMENT_INTERFACE (
59 E_TYPE_MAIL_EXTENSION,
60 e_mail_formatter_mail_extension_interface_init)
61 G_IMPLEMENT_INTERFACE (
62 E_TYPE_MAIL_FORMATTER_EXTENSION,
63 e_mail_formatter_formatter_extension_interface_init));
64
65 static gboolean
66 emfe_message_rfc822_format (EMailFormatterExtension *extension,
67 EMailFormatter *formatter,
68 EMailFormatterContext *context,
69 EMailPart *part,
70 CamelStream *stream,
71 GCancellable *cancellable)
72 {
73 if (g_cancellable_is_cancelled (cancellable))
74 return FALSE;
75
76 if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
77 GSList *iter;
78 gchar *header, *end;
79
80 header = e_mail_formatter_get_html_header (formatter);
81 camel_stream_write_string (stream, header, cancellable, NULL);
82 g_free (header);
83
84 /* Print content of the message normally */
85 context->mode = E_MAIL_FORMATTER_MODE_NORMAL;
86
87 iter = e_mail_part_list_get_iter (context->parts, part->id);
88
89 end = g_strconcat (part->id, ".end", NULL);
90 for (iter = iter->next; iter; iter = g_slist_next (iter)) {
91 EMailPart * p = iter->data;
92 if (!p)
93 continue;
94
95 /* Check for nested rfc822 messages */
96 if (g_str_has_suffix (p->id, ".rfc822")) {
97 gchar *sub_end = g_strconcat (p->id, ".end", NULL);
98
99 while (iter) {
100 p = iter->data;
101 if (!p) {
102 iter = iter->next;
103 continue;
104 }
105
106 if (g_strcmp0 (p->id, sub_end) == 0) {
107 break;
108 }
109
110 iter = iter->next;
111 }
112 g_free (sub_end);
113 continue;
114 }
115 if ((g_strcmp0 (p->id, end) == 0))
116 break;
117
118 if (p->is_hidden)
119 continue;
120
121 e_mail_formatter_format_as (
122 formatter, context, p,
123 stream, NULL, cancellable);
124
125 }
126
127 g_free (end);
128
129 context->mode = E_MAIL_FORMATTER_MODE_RAW;
130
131 camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
132
133 } else if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
134
135 GSList *iter;
136 gchar *end;
137
138 /* Part is EMailPartAttachment */
139 iter = e_mail_part_list_get_iter (context->parts, part->id);
140 iter = g_slist_next (iter);
141
142 if (!iter || !iter->next || !iter->data)
143 return FALSE;
144
145 part = iter->data;
146 end = g_strconcat (part->id, ".end", NULL);
147
148 for (iter = iter->next; iter; iter = g_slist_next (iter)) {
149 EMailPart * p = iter->data;
150 if (!p)
151 continue;
152
153 /* Skip attachment bar */
154 if (g_str_has_suffix (part->id, ".attachment-bar"))
155 continue;
156
157 /* Check for nested rfc822 messages */
158 if (g_str_has_suffix (p->id, ".rfc822")) {
159 gchar *sub_end = g_strconcat (p->id, ".end", NULL);
160
161 while (iter) {
162 p = iter->data;
163 if (!p) {
164 iter = iter->next;
165 continue;
166 }
167
168 if (g_strcmp0 (p->id, sub_end) == 0) {
169 break;
170 }
171
172 iter = iter->next;
173 }
174 g_free (sub_end);
175 continue;
176 }
177
178 if ((g_strcmp0 (p->id, end) == 0))
179 break;
180
181 if (p->is_hidden)
182 continue;
183
184 e_mail_formatter_format_as (
185 formatter, context, p,
186 stream, NULL, cancellable);
187 }
188
189 g_free (end);
190
191 } else {
192 gchar *str;
193 gchar *uri;
194 const gchar *default_charset, *charset;
195 EMailPart *p;
196 GSList *iter;
197
198 iter = e_mail_part_list_get_iter (context->parts, part->id);
199 if (!iter || !iter->next)
200 return FALSE;
201
202 default_charset = e_mail_formatter_get_default_charset (formatter);
203 charset = e_mail_formatter_get_charset (formatter);
204
205 if (!default_charset)
206 default_charset = "";
207 if (!charset)
208 charset = "";
209
210 p = iter->data;
211
212 uri = e_mail_part_build_uri (
213 context->folder, context->message_uid,
214 "part_id", G_TYPE_STRING, p->id,
215 "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW,
216 "headers_collapsable", G_TYPE_INT, 0,
217 "formatter_default_charset", G_TYPE_STRING, default_charset,
218 "formatter_charset", G_TYPE_STRING, charset,
219 NULL);
220
221 str = g_strdup_printf (
222 "<div class=\"part-container\" style=\"border-color: #%06x; "
223 "background-color: #%06x;\">\n"
224 "<iframe width=\"100%%\" height=\"10\""
225 " id=\"%s.iframe\" "
226 " frameborder=\"0\" src=\"%s\" name=\"%s\"></iframe>"
227 "</div>",
228 e_color_to_value ((GdkColor *)
229 e_mail_formatter_get_color (
230 formatter, E_MAIL_FORMATTER_COLOR_FRAME)),
231 e_color_to_value ((GdkColor *)
232 e_mail_formatter_get_color (
233 formatter, E_MAIL_FORMATTER_COLOR_BODY)),
234 part->id, uri, part->id);
235
236 camel_stream_write_string (stream, str, cancellable, NULL);
237
238 g_free (str);
239 g_free (uri);
240 }
241
242 return TRUE;
243 }
244
245 static const gchar *
246 emfe_message_rfc822_get_display_name (EMailFormatterExtension *extension)
247 {
248 return _("RFC822 message");
249 }
250
251 static const gchar *
252 emfe_message_rfc822_get_description (EMailFormatterExtension *extension)
253 {
254 return _("Format part as an RFC822 message");
255 }
256
257 static const gchar **
258 emfe_message_rfc822_mime_types (EMailExtension *extension)
259 {
260 return formatter_mime_types;
261 }
262
263 static void
264 e_mail_formatter_message_rfc822_class_init (EMailFormatterMessageRFC822Class *class)
265 {
266 }
267
268 static void
269 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
270 {
271 iface->format = emfe_message_rfc822_format;
272 iface->get_display_name = emfe_message_rfc822_get_display_name;
273 iface->get_description = emfe_message_rfc822_get_description;
274 }
275
276 static void
277 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
278 {
279 iface->mime_types = emfe_message_rfc822_mime_types;
280 }
281
282 static void
283 e_mail_formatter_message_rfc822_init (EMailFormatterMessageRFC822 *formatter)
284 {
285
286 }