Updated Spanish translation
[evolution.git] / em-format / e-mail-parser-headers.c
blob76b846464d278077970c9c67ca649c926bb9d306
1 /*
2 * e-mail-parser-headers.c
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.
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.
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/>
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
23 #include "e-mail-format-extensions.h"
25 #include <glib/gi18n-lib.h>
27 #include <em-format/e-mail-parser-extension.h>
28 #include <em-format/e-mail-parser.h>
29 #include <libemail-engine/e-mail-utils.h>
30 #include <e-util/e-util.h>
32 #include <camel/camel.h>
34 #include <string.h>
36 typedef struct _EMailParserHeaders {
37 GObject parent;
38 } EMailParserHeaders;
40 typedef struct _EMailParserHeadersClass {
41 GObjectClass parent_class;
42 } EMailParserHeadersClass;
44 static void e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface);
45 static void e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface);
47 G_DEFINE_TYPE_EXTENDED (
48 EMailParserHeaders,
49 e_mail_parser_headers,
50 G_TYPE_OBJECT,
52 G_IMPLEMENT_INTERFACE (
53 E_TYPE_MAIL_EXTENSION,
54 e_mail_parser_mail_extension_interface_init)
55 G_IMPLEMENT_INTERFACE (
56 E_TYPE_MAIL_PARSER_EXTENSION,
57 e_mail_parser_parser_extension_interface_init));
59 static const gchar *parser_mime_types[] = { "application/vnd.evolution.headers", NULL };
61 static void
62 empe_headers_bind_dom (EMailPart *part,
63 WebKitDOMElement *element)
65 WebKitDOMDocument *document;
66 WebKitDOMElement *photo;
67 gchar *addr, *uri;
68 gboolean only_local;
70 document = webkit_dom_node_get_owner_document (WEBKIT_DOM_NODE (element));
71 photo = webkit_dom_document_get_element_by_id (document, "__evo-contact-photo");
73 /* Contact photos disabled, the <img> tag is not there */
74 if (!photo)
75 return;
77 addr = webkit_dom_element_get_attribute (photo, "data-mailaddr");
78 only_local = webkit_dom_element_has_attribute (photo, "data-onlylocal");
80 uri = g_strdup_printf ("mail://contact-photo?mailaddr=%s%s",
81 addr, only_local ? "&only-local-photo=1" : "");
83 webkit_dom_html_image_element_set_src (
84 WEBKIT_DOM_HTML_IMAGE_ELEMENT (photo), uri);
86 g_free (addr);
87 g_free (uri);
90 static GSList *
91 empe_headers_parse (EMailParserExtension *extension,
92 EMailParser *parser,
93 CamelMimePart *part,
94 GString *part_id,
95 GCancellable *cancellable)
97 EMailPart *mail_part;
98 gint len;
100 if (g_cancellable_is_cancelled (cancellable))
101 return NULL;
103 len = part_id->len;
104 g_string_append (part_id, ".headers");
106 mail_part = e_mail_part_new (part, part_id->str);
107 mail_part->mime_type = g_strdup ("application/vnd.evolution.headers");
108 mail_part->bind_func = empe_headers_bind_dom;
109 g_string_truncate (part_id, len);
111 return g_slist_append (NULL, mail_part);
114 static const gchar **
115 empe_headers_mime_types (EMailExtension *extension)
117 return parser_mime_types;
120 static void
121 e_mail_parser_headers_class_init (EMailParserHeadersClass *klass)
123 e_mail_parser_headers_parent_class = g_type_class_peek_parent (klass);
126 static void
127 e_mail_parser_parser_extension_interface_init (EMailParserExtensionInterface *iface)
129 iface->parse = empe_headers_parse;
132 static void
133 e_mail_parser_mail_extension_interface_init (EMailExtensionInterface *iface)
135 iface->mime_types = empe_headers_mime_types;
138 static void
139 e_mail_parser_headers_init (EMailParserHeaders *parser)