No issues found
Tool | Failure ID | Location | Function | Message | Data |
---|---|---|---|---|---|
clang-analyzer | no-output-found | e-mail-formatter-quote-headers.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None | |
clang-analyzer | no-output-found | e-mail-formatter-quote-headers.c | Message(text='Unable to locate XML output from invoke-clang-analyzer') | None |
1 /*
2 * e-mail-formatter-quote-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 _EMailFormatterQuoteHeaders {
39 GObject parent;
40 } EMailFormatterQuoteHeaders;
41
42 typedef struct _EMailFormatterQuoteHeadersClass {
43 GObjectClass parent_class;
44 } EMailFormatterQuoteHeadersClass;
45
46 static const gchar *formatter_mime_types[] = { "application/vnd.evolution.headers", NULL };
47
48 static void e_mail_formatter_quote_formatter_extension_interface_init
49 (EMailFormatterExtensionInterface *iface);
50 static void e_mail_formatter_quote_mail_extension_interface_init
51 (EMailExtensionInterface *iface);
52
53 G_DEFINE_TYPE_EXTENDED (
54 EMailFormatterQuoteHeaders,
55 e_mail_formatter_quote_headers,
56 G_TYPE_OBJECT,
57 0,
58 G_IMPLEMENT_INTERFACE (
59 E_TYPE_MAIL_EXTENSION,
60 e_mail_formatter_quote_mail_extension_interface_init)
61 G_IMPLEMENT_INTERFACE (
62 E_TYPE_MAIL_FORMATTER_EXTENSION,
63 e_mail_formatter_quote_formatter_extension_interface_init))
64
65 static void
66 emfqe_format_text_header (EMailFormatter *emf,
67 GString *buffer,
68 const gchar *label,
69 const gchar *value,
70 guint32 flags,
71 gint is_html)
72 {
73 const gchar *html;
74 gchar *mhtml = NULL;
75
76 if (value == NULL)
77 return;
78
79 while (*value == ' ')
80 value++;
81
82 if (!is_html)
83 html = mhtml = camel_text_to_html (value, 0, 0);
84 else
85 html = value;
86
87 if (flags & E_MAIL_FORMATTER_HEADER_FLAG_BOLD)
88 g_string_append_printf (
89 buffer, "<b>%s</b>: %s<br>", label, html);
90 else
91 g_string_append_printf (
92 buffer, "%s: %s<br>", label, html);
93
94 g_free (mhtml);
95 }
96
97 /* XXX: This is copied in e-mail-formatter-utils.c */
98 static const gchar *addrspec_hdrs[] = {
99 "Sender", "From", "Reply-To", "To", "Cc", "Bcc",
100 "Resent-Sender", "Resent-From", "Resent-Reply-To",
101 "Resent-To", "Resent-Cc", "Resent-Bcc", NULL
102 };
103
104 static void
105 emfqe_format_header (EMailFormatter *formatter,
106 GString *buffer,
107 CamelMedium *part,
108 struct _camel_header_raw *header,
109 guint32 flags,
110 const gchar *charset)
111 {
112 CamelMimeMessage *msg = (CamelMimeMessage *) part;
113 gchar *name, *buf, *value = NULL;
114 const gchar *txt, *label;
115 gboolean addrspec = FALSE;
116 gint is_html = FALSE;
117 gint i;
118
119 name = g_alloca (strlen (header->name) + 1);
120 strcpy (name, header->name);
121 e_mail_formatter_canon_header_name (name);
122
123 /* Never quote Bcc headers */
124 if (g_str_equal (name, "Bcc") || g_str_equal (name, "Resent-Bcc"))
125 return;
126
127 for (i = 0; addrspec_hdrs[i]; i++) {
128 if (!strcmp (name, addrspec_hdrs[i])) {
129 addrspec = TRUE;
130 break;
131 }
132 }
133
134 label = _(name);
135
136 if (addrspec) {
137 struct _camel_header_address *addrs;
138 GString *html;
139
140 if (!(txt = camel_medium_get_header (part, name)))
141 return;
142
143 buf = camel_header_unfold (txt);
144 addrs = camel_header_address_decode (
145 txt, e_mail_formatter_get_charset (formatter) ?
146 e_mail_formatter_get_charset (formatter) :
147 e_mail_formatter_get_default_charset (formatter));
148 if (addrs == NULL) {
149 g_free (buf);
150 return;
151 }
152
153 g_free (buf);
154
155 html = g_string_new ("");
156 e_mail_formatter_format_address (formatter, html,
157 addrs, name, FALSE, FALSE);
158 camel_header_address_unref (addrs);
159 txt = value = html->str;
160 g_string_free (html, FALSE);
161 flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
162 is_html = TRUE;
163 } else if (!strcmp (name, "Subject")) {
164 txt = camel_mime_message_get_subject (msg);
165 label = _("Subject");
166 flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
167 } else if (!strcmp (name, "X-Evolution-Mailer")) { /* pseudo-header */
168 if (!(txt = camel_medium_get_header (part, "x-mailer")))
169 if (!(txt = camel_medium_get_header (part, "user-agent")))
170 if (!(txt = camel_medium_get_header (part, "x-newsreader")))
171 if (!(txt = camel_medium_get_header (part, "x-mimeole")))
172 return;
173
174 txt = value = camel_header_format_ctext (txt, charset);
175
176 label = _("Mailer");
177 flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
178 } else if (!strcmp (name, "Date") || !strcmp (name, "Resent-Date")) {
179 if (!(txt = camel_medium_get_header (part, name)))
180 return;
181
182 flags |= E_MAIL_FORMATTER_HEADER_FLAG_BOLD;
183 } else {
184 txt = camel_medium_get_header (part, name);
185 buf = camel_header_unfold (txt);
186 txt = value = camel_header_decode_string (txt, charset);
187 g_free (buf);
188 }
189
190 emfqe_format_text_header (formatter, buffer, label, txt, flags, is_html);
191
192 g_free (value);
193 }
194
195 static gboolean
196 emqfe_headers_format (EMailFormatterExtension *extension,
197 EMailFormatter *formatter,
198 EMailFormatterContext *context,
199 EMailPart *part,
200 CamelStream *stream,
201 GCancellable *cancellable)
202 {
203 CamelContentType *ct;
204 const gchar *charset;
205 GList *iter;
206 GString *buffer;
207 const GQueue *default_headers;
208
209 if (!part)
210 return FALSE;
211
212 ct = camel_mime_part_get_content_type ((CamelMimePart *) part->part);
213 charset = camel_content_type_param (ct, "charset");
214 charset = camel_iconv_charset_name (charset);
215
216 buffer = g_string_new ("");
217
218 /* dump selected headers */
219 default_headers = e_mail_formatter_get_headers (formatter);
220 for (iter = default_headers->head; iter; iter = iter->next) {
221 struct _camel_header_raw *raw_header;
222 EMailFormatterHeader *h = iter->data;
223 guint32 flags;
224
225 flags = h->flags & ~E_MAIL_FORMATTER_HEADER_FLAG_HTML;
226 flags |= E_MAIL_FORMATTER_HEADER_FLAG_NOELIPSIZE;
227
228 for (raw_header = part->part->headers; raw_header; raw_header = raw_header->next) {
229
230 if (g_strcmp0 (raw_header->name, h->name) == 0) {
231
232 emfqe_format_header (
233 formatter, buffer, (CamelMedium *) part->part,
234 raw_header, flags, charset);
235 break;
236 }
237 }
238 }
239
240 g_string_append (buffer, "<br>\n");
241
242 camel_stream_write_string (stream, buffer->str, cancellable, NULL);
243
244 g_string_free (buffer, TRUE);
245
246 return TRUE;
247 }
248
249 static const gchar *
250 emqfe_headers_get_display_name (EMailFormatterExtension *extension)
251 {
252 return NULL;
253 }
254
255 static const gchar *
256 emqfe_headers_get_description (EMailFormatterExtension *extension)
257 {
258 return NULL;
259 }
260
261 static const gchar **
262 emqfe_headers_mime_types (EMailExtension *extension)
263 {
264 return formatter_mime_types;
265 }
266
267 static void
268 e_mail_formatter_quote_headers_class_init (EMailFormatterQuoteHeadersClass *class)
269 {
270 }
271
272 static void
273 e_mail_formatter_quote_formatter_extension_interface_init (EMailFormatterExtensionInterface *iface)
274 {
275 iface->format = emqfe_headers_format;
276 iface->get_display_name = emqfe_headers_get_display_name;
277 iface->get_description = emqfe_headers_get_description;
278 }
279
280 static void
281 e_mail_formatter_quote_mail_extension_interface_init (EMailExtensionInterface *iface)
282 {
283 iface->mime_types = emqfe_headers_mime_types;
284 }
285
286 static void
287 e_mail_formatter_quote_headers_init (EMailFormatterQuoteHeaders *formatter)
288 {
289
290 }