No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-image.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-image.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * image-any.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 <em-format/e-mail-parser-extension.h>
26 #include <em-format/e-mail-formatter-extension.h>
27 #include <em-format/e-mail-part-utils.h>
28 #include <em-format/e-mail-parser.h>
29 #include <em-format/e-mail-formatter.h>
30 #include <em-format/e-mail-inline-filter.h>
31 #include <e-util/e-util.h>
32
33 #include <glib/gi18n-lib.h>
34 #include <camel/camel.h>
35
36 static const gchar *formatter_mime_types[] = { "image/gif", "image/jpeg",
37 "image/png", "image/x-png",
38 "image/x-bmp", "image/bmp",
39 "image/svg", "image/x-cmu-raster",
40 "image/x-ico",
41 "image/x-portable-anymap",
42 "image/x-portable-bitmap",
43 "image/x-portable-graymap",
44 "image/x-portable-pixmap",
45 "image/x-xpixmap",
46 "image/jpg", "image/pjpeg",
47 "image/*", NULL };
48
49 typedef struct _EMailFormatterImage {
50 GObject parent;
51 } EMailFormatterImage;
52
53 typedef struct _EMailFormatterImageClass {
54 GObjectClass parent_class;
55 } EMailFormatterImageClass;
56
57 static void e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface);
58 static void e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface);
59
60 G_DEFINE_TYPE_EXTENDED (
61 EMailFormatterImage,
62 e_mail_formatter_image,
63 G_TYPE_OBJECT,
64 0,
65 G_IMPLEMENT_INTERFACE (
66 E_TYPE_MAIL_EXTENSION,
67 e_mail_formatter_mail_extension_interface_init)
68 G_IMPLEMENT_INTERFACE (
69 E_TYPE_MAIL_FORMATTER_EXTENSION,
70 e_mail_formatter_formatter_extension_interface_init));
71
72 static gboolean
73 emfe_image_format (EMailFormatterExtension *extension,
74 EMailFormatter *formatter,
75 EMailFormatterContext *context,
76 EMailPart *part,
77 CamelStream *stream,
78 GCancellable *cancellable)
79 {
80 gchar *content;
81 CamelDataWrapper *dw;
82 GByteArray *ba;
83 CamelStream *raw_content;
84
85 if (g_cancellable_is_cancelled (cancellable))
86 return FALSE;
87
88 dw = camel_medium_get_content (CAMEL_MEDIUM (part->part));
89 g_return_val_if_fail (dw, FALSE);
90
91 raw_content = camel_stream_mem_new ();
92 camel_data_wrapper_decode_to_stream_sync (dw, raw_content, cancellable, NULL);
93 ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (raw_content));
94
95 if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
96
97 if (!e_mail_formatter_get_animate_images (formatter)) {
98
99 gchar *buff;
100 gsize len;
101
102 e_mail_part_animation_extract_frame (ba, &buff, &len);
103
104 camel_stream_write (stream, buff, len, cancellable, NULL);
105
106 g_free (buff);
107
108 } else {
109
110 camel_stream_write (
111 stream, (gchar *) ba->data,
112 ba->len, cancellable, NULL);
113 }
114
115 } else {
116
117 gchar *buffer;
118
119 if (!e_mail_formatter_get_animate_images (formatter)) {
120
121 gchar *buff;
122 gsize len;
123
124 e_mail_part_animation_extract_frame (ba, &buff, &len);
125
126 content = g_base64_encode ((guchar *) buff, len);
127 g_free (buff);
128
129 } else {
130 content = g_base64_encode ((guchar *) ba->data, ba->len);
131 }
132
133 /* The image is already base64-encrypted so we can directly
134 * paste it to the output */
135 buffer = g_strdup_printf (
136 "<img src=\"data:%s;base64,%s\" style=\"max-width: 100%%;\" />",
137 part->mime_type ? part->mime_type : "image/*", content);
138
139 camel_stream_write_string (stream, buffer, cancellable, NULL);
140 g_free (buffer);
141 g_free (content);
142 }
143
144 g_object_unref (raw_content);
145
146 return TRUE;
147 }
148
149 static const gchar *
150 emfe_image_get_display_name (EMailFormatterExtension *extension)
151 {
152 return _("Regular Image");
153 }
154
155 static const gchar *
156 emfe_image_get_description (EMailFormatterExtension *extension)
157 {
158 return _("Display part as an image");
159 }
160
161 static const gchar **
162 emfe_image_mime_types (EMailExtension *extension)
163 {
164 return formatter_mime_types;
165 }
166
167 static void
168 e_mail_formatter_image_class_init (EMailFormatterImageClass *class)
169 {
170 }
171
172 static void
173 e_mail_formatter_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
174 {
175 iface->format = emfe_image_format;
176 iface->get_display_name = emfe_image_get_display_name;
177 iface->get_description = emfe_image_get_description;
178 }
179
180 static void
181 e_mail_formatter_mail_extension_interface_init (EMailExtensionInterface *iface)
182 {
183 iface->mime_types = emfe_image_mime_types;
184 }
185
186 static void
187 e_mail_formatter_image_init (EMailFormatterImage *formatter)
188 {
189
190 }