Bug 790773 - Add message list columns to show Sender/Recipients email addresses only
[evolution.git] / src / modules / text-highlight / e-mail-parser-text-highlight.c
blob277f683e841df2991cfb44bbaaec1eb79cd29c2d
1 /*
2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
9 * for more details.
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
15 #include "evolution-config.h"
17 #include <string.h>
18 #include <gtk/gtk.h>
19 #include <glib/gi18n.h>
20 #include <camel/camel.h>
22 #include "e-mail-parser-text-highlight.h"
23 #include "languages.h"
25 #include <em-format/e-mail-extension-registry.h>
26 #include <em-format/e-mail-parser-extension.h>
27 #include <em-format/e-mail-part.h>
28 #include <em-format/e-mail-part-utils.h>
30 #include <libebackend/libebackend.h>
32 #define d(x)
34 typedef EMailParserExtension EMailParserTextHighlight;
35 typedef EMailParserExtensionClass EMailParserTextHighlightClass;
37 typedef EExtension EMailParserTextHighlightLoader;
38 typedef EExtensionClass EMailParserTextHighlightLoaderClass;
40 GType e_mail_parser_text_highlight_get_type (void);
42 G_DEFINE_DYNAMIC_TYPE (
43 EMailParserTextHighlight,
44 e_mail_parser_text_highlight,
45 E_TYPE_MAIL_PARSER_EXTENSION)
47 static gboolean
48 empe_text_highlight_parse (EMailParserExtension *extension,
49 EMailParser *parser,
50 CamelMimePart *part,
51 GString *part_id,
52 GCancellable *cancellable,
53 GQueue *out_mail_parts)
55 CamelContentType *ct;
56 gboolean handled;
57 gint len;
59 /* Prevent recursion */
60 if (g_str_has_suffix (part_id->str, ".text-highlight"))
61 return FALSE;
63 /* Don't parse text/html if it's not an attachment */
64 ct = camel_mime_part_get_content_type (part);
65 if (camel_content_type_is (ct, "text", "html")) {
66 const CamelContentDisposition *disp;
68 disp = camel_mime_part_get_content_disposition (part);
69 if (!disp || (g_strcmp0 (disp->disposition, "attachment") != 0))
70 return FALSE;
73 len = part_id->len;
74 g_string_append (part_id, ".text-highlight");
76 /* All source codes and scripts are in general plain texts,
77 * so let text/plain parser handle it. */
79 handled = e_mail_parser_parse_part_as (
80 parser, part, part_id, "text/plain",
81 cancellable, out_mail_parts);
83 g_string_truncate (part_id, len);
85 return handled;
88 static void
89 e_mail_parser_text_highlight_class_init (EMailParserExtensionClass *class)
91 class->mime_types = get_mime_types ();
92 class->parse = empe_text_highlight_parse;
95 void
96 e_mail_parser_text_highlight_class_finalize (EMailParserExtensionClass *class)
100 static void
101 e_mail_parser_text_highlight_init (EMailParserExtension *extension)
105 void
106 e_mail_parser_text_highlight_type_register (GTypeModule *type_module)
108 e_mail_parser_text_highlight_register_type (type_module);