aboutsummaryrefslogtreecommitdiffstats
path: root/mail/mail-format.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-12-12 00:52:40 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-12-12 00:52:40 +0800
commitcf5946baf722af0e701284a807ae3b3642d8582b (patch)
tree94cfd4c78ec3457746de863b4531b69e729bb27d /mail/mail-format.c
parent8d8578a64dda64c7bc4e05d687026f977e370aa4 (diff)
downloadgsoc2013-evolution-cf5946baf722af0e701284a807ae3b3642d8582b.tar.gz
gsoc2013-evolution-cf5946baf722af0e701284a807ae3b3642d8582b.tar.zst
gsoc2013-evolution-cf5946baf722af0e701284a807ae3b3642d8582b.zip
New function to handle a lot of the filtering/etc that was done in
2002-12-11 Jeffrey Stedfast <fejj@ximian.com> * mail-format.c (mail_format_data_wrapper_write_to_stream): New function to handle a lot of the filtering/etc that was done in mail_format_get_data_wrapper_text(). This is the first step toward getting rid of e-text-to-html crap and using my tohtml stream filter instead. (mail_format_get_data_wrapper_text): Use the new function. (mail_format_raw_message): Use camel streams to write the content to gtkhtml rather than using get_data_wrapper_text() and then converting that to html and then writing it to the gtkhtml stream. svn path=/trunk/; revision=19098
Diffstat (limited to 'mail/mail-format.c')
-rw-r--r--mail/mail-format.c71
1 files changed, 43 insertions, 28 deletions
diff --git a/mail/mail-format.c b/mail/mail-format.c
index 3104183efe..ad32250fee 100644
--- a/mail/mail-format.c
+++ b/mail/mail-format.c
@@ -187,8 +187,9 @@ void
mail_format_raw_message (CamelMimeMessage *mime_message, MailDisplay *md,
GtkHTML *html, GtkHTMLStream *stream)
{
- GByteArray *bytes;
- char *html_str;
+ CamelStream *mail_stream, *filtered_stream;
+ CamelMimeFilter *html_filter;
+ guint32 flags;
g_return_if_fail (CAMEL_IS_MIME_MESSAGE (mime_message));
@@ -196,17 +197,20 @@ mail_format_raw_message (CamelMimeMessage *mime_message, MailDisplay *md,
TRUE, NULL, html, NULL))
return;
- bytes = mail_format_get_data_wrapper_text (CAMEL_DATA_WRAPPER (mime_message), md);
- if (bytes) {
- g_byte_array_append (bytes, "", 1);
- html_str = e_text_to_html (bytes->data, E_TEXT_TO_HTML_CONVERT_NL |
- E_TEXT_TO_HTML_CONVERT_SPACES | E_TEXT_TO_HTML_ESCAPE_8BIT);
- g_byte_array_free (bytes, TRUE);
- mail_html_write (html, stream, "<tt>");
- mail_html_write (html, stream, html_str);
- g_free (html_str);
- mail_html_write (html, stream, "</tt>");
- }
+ mail_stream = mail_stream_gtkhtml_new (html, stream);
+ filtered_stream = camel_stream_filter_new_with_stream (mail_stream);
+
+ flags = CAMEL_MIME_FILTER_TOHTML_CONVERT_NL | CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+ CAMEL_MIME_FILTER_TOHTML_ESCAPE_8BIT;
+ html_filter = camel_mime_filter_tohtml_new (flags, 0);
+ camel_stream_filter_add ((CamelStreamFilter *) filtered_stream, html_filter);
+ camel_object_unref (html_filter);
+
+ camel_stream_write (mail_stream, "<tt>", 4);
+ mail_format_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (mime_message), md, filtered_stream);
+ camel_object_unref (filtered_stream);
+ camel_stream_write (mail_stream, "</tt>", 5);
+ camel_object_unref (mail_stream);
}
static const char *
@@ -1086,23 +1090,14 @@ mail_content_loaded (CamelDataWrapper *wrapper, MailDisplay *md, gboolean redisp
return FALSE;
}
-/* Return the contents of a data wrapper, or %NULL if it contains only
- * whitespace.
- */
-GByteArray *
-mail_format_get_data_wrapper_text (CamelDataWrapper *wrapper, MailDisplay *mail_display)
+
+static ssize_t
+mail_format_data_wrapper_write_to_stream (CamelDataWrapper *wrapper, MailDisplay *mail_display, CamelStream *stream)
{
- CamelStream *memstream;
CamelStreamFilter *filtered_stream;
- GByteArray *ba;
- char *text, *end;
+ ssize_t written;
- memstream = camel_stream_mem_new ();
- ba = g_byte_array_new ();
- camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (memstream), ba);
-
- filtered_stream = camel_stream_filter_new_with_stream (memstream);
- camel_object_unref (memstream);
+ filtered_stream = camel_stream_filter_new_with_stream (stream);
if (wrapper->rawtext || (mail_display && mail_display->charset)) {
CamelMimeFilterCharset *filter;
@@ -1143,10 +1138,30 @@ mail_format_get_data_wrapper_text (CamelDataWrapper *wrapper, MailDisplay *mail_
}
}
- camel_data_wrapper_write_to_stream (wrapper, CAMEL_STREAM (filtered_stream));
+ written = camel_data_wrapper_write_to_stream (wrapper, CAMEL_STREAM (filtered_stream));
camel_stream_flush (CAMEL_STREAM (filtered_stream));
camel_object_unref (filtered_stream);
+ return written;
+}
+
+/* Return the contents of a data wrapper, or %NULL if it contains only
+ * whitespace.
+ */
+GByteArray *
+mail_format_get_data_wrapper_text (CamelDataWrapper *wrapper, MailDisplay *mail_display)
+{
+ CamelStream *memstream;
+ GByteArray *ba;
+ char *text, *end;
+
+ memstream = camel_stream_mem_new ();
+ ba = g_byte_array_new ();
+ camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (memstream), ba);
+
+ mail_format_data_wrapper_write_to_stream (wrapper, mail_display, memstream);
+ camel_object_unref (memstream);
+
for (text = ba->data, end = text + ba->len; text < end; text++) {
if (!isspace ((unsigned char) *text))
break;