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
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"
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>
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
)
48 empe_text_highlight_parse (EMailParserExtension
*extension
,
52 GCancellable
*cancellable
,
53 GQueue
*out_mail_parts
)
59 /* Prevent recursion */
60 if (g_str_has_suffix (part_id
->str
, ".text-highlight"))
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))
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
);
89 e_mail_parser_text_highlight_class_init (EMailParserExtensionClass
*class)
91 class->mime_types
= get_mime_types ();
92 class->parse
= empe_text_highlight_parse
;
96 e_mail_parser_text_highlight_class_finalize (EMailParserExtensionClass
*class)
101 e_mail_parser_text_highlight_init (EMailParserExtension
*extension
)
106 e_mail_parser_text_highlight_type_register (GTypeModule
*type_module
)
108 e_mail_parser_text_highlight_register_type (type_module
);