2 * e-mail-formatter-text-enriched.c
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.
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
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/>.
18 #include "evolution-config.h"
20 #include <glib/gi18n-lib.h>
22 #include <e-util/e-util.h>
24 #include "e-mail-formatter-extension.h"
25 #include "e-mail-inline-filter.h"
26 #include "e-mail-part-utils.h"
28 typedef EMailFormatterExtension EMailFormatterTextEnriched
;
29 typedef EMailFormatterExtensionClass EMailFormatterTextEnrichedClass
;
31 GType
e_mail_formatter_text_enriched_get_type (void);
34 EMailFormatterTextEnriched
,
35 e_mail_formatter_text_enriched
,
36 E_TYPE_MAIL_FORMATTER_EXTENSION
)
38 static const gchar
*formatter_mime_types
[] = {
45 emfe_text_enriched_format (EMailFormatterExtension
*extension
,
46 EMailFormatter
*formatter
,
47 EMailFormatterContext
*context
,
49 GOutputStream
*stream
,
50 GCancellable
*cancellable
)
52 GOutputStream
*filtered_stream
;
53 CamelMimeFilter
*filter
;
54 const gchar
*mime_type
;
57 guint32 filter_flags
= 0;
59 if (g_cancellable_is_cancelled (cancellable
))
62 mime_type
= e_mail_part_get_mime_type (part
);
64 if (g_strcmp0 (mime_type
, "text/richtext") == 0)
65 filter_flags
= CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT
;
67 filter
= camel_mime_filter_enriched_new (filter_flags
);
68 filtered_stream
= camel_filter_output_stream_new (stream
, filter
);
69 g_filter_output_stream_set_close_base_stream (
70 G_FILTER_OUTPUT_STREAM (filtered_stream
), FALSE
);
71 g_object_unref (filter
);
73 str
= g_strdup_printf (
74 "<div class=\"part-container -e-mail-formatter-frame-color %s"
75 "-e-web-view-background-color -e-web-view-text-color\">"
76 "<div class=\"part-container-inner-margin\">\n",
77 e_mail_part_get_frame_security_style (part
));
79 g_output_stream_write_all (
80 stream
, str
, strlen (str
), NULL
, cancellable
, NULL
);
83 e_mail_formatter_format_text (
84 formatter
, part
, filtered_stream
, cancellable
);
85 g_output_stream_flush (filtered_stream
, cancellable
, NULL
);
87 g_object_unref (filtered_stream
);
89 string
= "</div></div>";
91 g_output_stream_write_all (
92 stream
, string
, strlen (string
), NULL
, cancellable
, NULL
);
98 e_mail_formatter_text_enriched_class_init (EMailFormatterExtensionClass
*class)
100 class->display_name
= _("Richtext");
101 class->description
= _("Display part as enriched text");
102 class->mime_types
= formatter_mime_types
;
103 class->priority
= G_PRIORITY_LOW
;
104 class->format
= emfe_text_enriched_format
;
108 e_mail_formatter_text_enriched_init (EMailFormatterExtension
*extension
)