No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-print-headers.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-print-headers.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-formatter-print-headers.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
27 #include <em-format/e-mail-formatter-extension.h>
28 #include <em-format/e-mail-formatter.h>
29 #include <em-format/e-mail-formatter-utils.h>
30 #include <em-format/e-mail-inline-filter.h>
31 #include <libemail-engine/e-mail-utils.h>
32 #include <e-util/e-util.h>
33
34 #include <camel/camel.h>
35
36 #include <string.h>
37
38 typedef struct _EMailFormatterPrintHeaders {
39 GObject parent;
40 } EMailFormatterPrintHeaders;
41
42 typedef struct _EMailFormatterPrintHeadersClass {
43 GObjectClass parent_class;
44 } EMailFormatterPrintHeadersClass;
45
46 static const gchar *formatter_mime_types[] = { "application/vnd.evolution.headers", NULL };
47
48 static void e_mail_formatter_print_formatter_extension_interface_init
49 (EMailFormatterExtensionInterface *iface);
50 static void e_mail_formatter_print_mail_extension_interface_init
51 (EMailExtensionInterface *iface);
52
53 G_DEFINE_TYPE_EXTENDED (
54 EMailFormatterPrintHeaders,
55 e_mail_formatter_print_headers,
56 G_TYPE_OBJECT,
57 0,
58 G_IMPLEMENT_INTERFACE (
59 E_TYPE_MAIL_EXTENSION,
60 e_mail_formatter_print_mail_extension_interface_init)
61 G_IMPLEMENT_INTERFACE (
62 E_TYPE_MAIL_FORMATTER_EXTENSION,
63 e_mail_formatter_print_formatter_extension_interface_init))
64
65 static gboolean
66 emfpe_headers_format (EMailFormatterExtension *extension,
67 EMailFormatter *formatter,
68 EMailFormatterContext *context,
69 EMailPart *part,
70 CamelStream *stream,
71 GCancellable *cancellable)
72 {
73 struct _camel_header_raw raw_header;
74 GString *str, *tmp;
75 gchar *subject;
76 const gchar *buf;
77 GSList *parts_iter;
78 GList *iter;
79 gint attachments_count;
80 gchar *part_id_prefix;
81 const GQueue *headers;
82
83 buf = camel_medium_get_header (CAMEL_MEDIUM (part->part), "subject");
84 subject = camel_header_decode_string (buf, "UTF-8");
85 str = g_string_new ("");
86 g_string_append_printf (str, "<h1>%s</h1>\n", subject);
87 g_free (subject);
88
89 g_string_append (
90 str,
91 "<table border=\"0\" cellspacing=\"5\" "
92 "cellpadding=\"0\" class=\"printing-header\">\n");
93
94 headers = e_mail_formatter_get_headers (formatter);
95 for (iter = headers->head; iter; iter = iter->next) {
96
97 EMailFormatterHeader *header = iter->data;
98 raw_header.name = header->name;
99
100 /* Skip 'Subject' header, it's already displayed. */
101 if (g_ascii_strncasecmp (header->name, "Subject", 7) == 0)
102 continue;
103
104 if (header->value && *header->value) {
105 raw_header.value = header->value;
106 e_mail_formatter_format_header (formatter, str,
107 CAMEL_MEDIUM (part->part), &raw_header,
108 header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS,
109 "UTF-8");
110 } else {
111 raw_header.value = g_strdup (camel_medium_get_header (
112 CAMEL_MEDIUM (context->message), header->name));
113
114 if (raw_header.value && *raw_header.value) {
115 e_mail_formatter_format_header (formatter, str,
116 CAMEL_MEDIUM (part->part), &raw_header,
117 header->flags | E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS,
118 "UTF-8");
119 }
120
121 if (raw_header.value)
122 g_free (raw_header.value);
123 }
124 }
125
126 /* Get prefix of this PURI */
127 part_id_prefix = g_strndup (part->id, g_strrstr (part->id, ".") - part->id);
128
129 /* Add encryption/signature header */
130 raw_header.name = _("Security");
131 tmp = g_string_new ("");
132 /* Find first secured part. */
133 for (parts_iter = context->parts; parts_iter; parts_iter = parts_iter->next) {
134
135 EMailPart *mail_part = parts_iter->data;
136 if (mail_part == NULL)
137 continue;
138
139 if (mail_part->validity_type == 0)
140 continue;
141
142 if (!g_str_has_prefix (mail_part->id, part_id_prefix))
143 continue;
144
145 if ((mail_part->validity_type & E_MAIL_PART_VALIDITY_PGP) &&
146 (mail_part->validity_type & E_MAIL_PART_VALIDITY_SIGNED)) {
147 g_string_append (tmp, _("GPG signed"));
148 }
149 if ((mail_part->validity_type & E_MAIL_PART_VALIDITY_PGP) &&
150 (mail_part->validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED)) {
151 if (tmp->len > 0) g_string_append (tmp, ", ");
152 g_string_append (tmp, _("GPG encrpyted"));
153 }
154 if ((mail_part->validity_type & E_MAIL_PART_VALIDITY_SMIME) &&
155 (mail_part->validity_type & E_MAIL_PART_VALIDITY_SIGNED)) {
156
157 if (tmp->len > 0) g_string_append (tmp, ", ");
158 g_string_append (tmp, _("S/MIME signed"));
159 }
160 if ((mail_part->validity_type & E_MAIL_PART_VALIDITY_SMIME) &&
161 (mail_part->validity_type & E_MAIL_PART_VALIDITY_ENCRYPTED)) {
162
163 if (tmp->len > 0) g_string_append (tmp, ", ");
164 g_string_append (tmp, _("S/MIME encrpyted"));
165 }
166
167 break;
168 }
169
170 if (tmp->len > 0) {
171 raw_header.value = tmp->str;
172 e_mail_formatter_format_header (
173 formatter, str, CAMEL_MEDIUM (part->part), &raw_header,
174 E_MAIL_FORMATTER_HEADER_FLAG_BOLD |
175 E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8");
176 }
177 g_string_free (tmp, TRUE);
178
179 /* Count attachments and display the number as a header */
180 attachments_count = 0;
181
182 for (parts_iter = context->parts; parts_iter; parts_iter = parts_iter->next) {
183
184 EMailPart *mail_part = parts_iter->data;
185 if (!mail_part)
186 continue;
187
188 if (!g_str_has_prefix (mail_part->id, part_id_prefix))
189 continue;
190
191 if (mail_part->is_attachment && !mail_part->cid &&
192 !mail_part->is_hidden) {
193 attachments_count++;
194 }
195 }
196
197 if (attachments_count > 0) {
198 raw_header.name = _("Attachments");
199 raw_header.value = g_strdup_printf ("%d", attachments_count);
200 e_mail_formatter_format_header (
201 formatter, str, CAMEL_MEDIUM (part->part), &raw_header,
202 E_MAIL_FORMATTER_HEADER_FLAG_BOLD |
203 E_MAIL_FORMATTER_HEADER_FLAG_NOLINKS, "UTF-8");
204 g_free (raw_header.value);
205 }
206
207 g_string_append (str, "</table>");
208
209 camel_stream_write_string (stream, str->str, cancellable, NULL);
210 g_string_free (str, TRUE);
211 g_free (part_id_prefix);
212
213 return TRUE;
214 }
215
216 static const gchar *
217 emfpe_headers_get_display_name (EMailFormatterExtension *extension)
218 {
219 return NULL;
220 }
221
222 static const gchar *
223 emfpe_headers_get_description (EMailFormatterExtension *extension)
224 {
225 return NULL;
226 }
227
228 static const gchar **
229 emfpe_headers_mime_types (EMailExtension *extension)
230 {
231 return formatter_mime_types;
232 }
233
234 static void
235 e_mail_formatter_print_headers_class_init (EMailFormatterPrintHeadersClass *class)
236 {
237 }
238
239 static void
240 e_mail_formatter_print_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
241 {
242 iface->format = emfpe_headers_format;
243 iface->get_display_name = emfpe_headers_get_display_name;
244 iface->get_description = emfpe_headers_get_description;
245 }
246
247 static void
248 e_mail_formatter_print_mail_extension_interface_init (EMailExtensionInterface *iface)
249 {
250 iface->mime_types = emfpe_headers_mime_types;
251 }
252
253 static void
254 e_mail_formatter_print_headers_init (EMailFormatterPrintHeaders *formatter)
255 {
256
257 }