1 /*
2  * e-mail-formatter-quote-text-html.c
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU Lesser General Public License as published by
6  * the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11  * for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public License
14  * along with this program; if not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #include "evolution-config.h"
19 
20 #include <string.h>
21 #include <glib/gi18n-lib.h>
22 
23 #include <camel/camel.h>
24 
25 #include <e-util/e-util.h>
26 
27 #include "e-mail-formatter-quote.h"
28 #include "e-mail-part-utils.h"
29 #include "e-mail-stripsig-filter.h"
30 
31 typedef EMailFormatterExtension EMailFormatterQuoteTextHTML;
32 typedef EMailFormatterExtensionClass EMailFormatterQuoteTextHTMLClass;
33 
34 GType e_mail_formatter_quote_text_html_get_type (void);
35 
36 G_DEFINE_TYPE (
37 	EMailFormatterQuoteTextHTML,
38 	e_mail_formatter_quote_text_html,
39 	E_TYPE_MAIL_FORMATTER_QUOTE_EXTENSION)
40 
41 static const gchar *formatter_mime_types[] = {
42 	"text/html",
43 	NULL
44 };
45 
46 static gboolean
emqfe_text_html_format(EMailFormatterExtension * extension,EMailFormatter * formatter,EMailFormatterContext * context,EMailPart * part,GOutputStream * stream,GCancellable * cancellable)47 emqfe_text_html_format (EMailFormatterExtension *extension,
48                         EMailFormatter *formatter,
49                         EMailFormatterContext *context,
50                         EMailPart *part,
51                         GOutputStream *stream,
52                         GCancellable *cancellable)
53 {
54 	EMailFormatterQuoteContext *qf_context;
55 	GOutputStream *filtered_stream;
56 	const gchar *string;
57 
58 	qf_context = (EMailFormatterQuoteContext *) context;
59 
60 	string = "<!-- text/html -->";
61 	g_output_stream_write_all (
62 		stream, string, strlen (string), NULL, cancellable, NULL);
63 
64 	filtered_stream = g_object_ref (stream);
65 
66 	if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
67 		CamelMimeFilter *filter;
68 		GOutputStream *temp_stream;
69 
70 		filter = e_mail_stripsig_filter_new (FALSE);
71 		temp_stream = camel_filter_output_stream_new (
72 			filtered_stream, filter);
73 		g_filter_output_stream_set_close_base_stream (
74 			G_FILTER_OUTPUT_STREAM (temp_stream), FALSE);
75 		g_object_unref (filtered_stream);
76 		filtered_stream = temp_stream;
77 		g_object_unref (filter);
78 	}
79 
80 	e_mail_formatter_format_text (
81 		formatter, part, filtered_stream, cancellable);
82 
83 	g_output_stream_flush (filtered_stream, cancellable, NULL);
84 
85 	g_object_unref (filtered_stream);
86 
87 	return TRUE;
88 }
89 
90 static void
e_mail_formatter_quote_text_html_class_init(EMailFormatterExtensionClass * class)91 e_mail_formatter_quote_text_html_class_init (EMailFormatterExtensionClass *class)
92 {
93 	class->display_name = _("HTML");
94 	class->description = _("Format part as HTML");
95 	class->mime_types = formatter_mime_types;
96 	class->priority = G_PRIORITY_HIGH;
97 	class->format = emqfe_text_html_format;
98 }
99 
100 static void
e_mail_formatter_quote_text_html_init(EMailFormatterExtension * extension)101 e_mail_formatter_quote_text_html_init (EMailFormatterExtension *extension)
102 {
103 }
104