[evolution] EMailFormatter: Use GOutputStream instead of CamelStream.



commit f4bb7d7748f3c407858e9c844d365411c586d861
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Feb 25 10:23:11 2014 -0500

    EMailFormatter: Use GOutputStream instead of CamelStream.

 composer/e-msg-composer.c                          |   25 +++---
 em-format/e-mail-formatter-attachment-bar.c        |    5 +-
 em-format/e-mail-formatter-attachment.c            |   55 ++++++++------
 em-format/e-mail-formatter-audio.c                 |   33 +++++---
 em-format/e-mail-formatter-error.c                 |   30 ++++----
 em-format/e-mail-formatter-extension.c             |    9 +-
 em-format/e-mail-formatter-extension.h             |    4 +-
 em-format/e-mail-formatter-headers.c               |    5 +-
 em-format/e-mail-formatter-image.c                 |   47 ++++++++----
 em-format/e-mail-formatter-message-rfc822.c        |   17 +++-
 em-format/e-mail-formatter-print-headers.c         |    6 +-
 em-format/e-mail-formatter-print.c                 |   23 ++++--
 em-format/e-mail-formatter-quote-attachment.c      |   28 ++++---
 em-format/e-mail-formatter-quote-headers.c         |    5 +-
 em-format/e-mail-formatter-quote-message-rfc822.c  |   10 ++-
 em-format/e-mail-formatter-quote-text-enriched.c   |   36 +++++----
 em-format/e-mail-formatter-quote-text-html.c       |   40 ++++++-----
 em-format/e-mail-formatter-quote-text-plain.c      |   31 ++++----
 em-format/e-mail-formatter-quote.c                 |   45 +++++++-----
 em-format/e-mail-formatter-secure-button.c         |    5 +-
 em-format/e-mail-formatter-source.c                |   64 ++++++++-------
 em-format/e-mail-formatter-text-enriched.c         |   35 ++++-----
 em-format/e-mail-formatter-text-html.c             |   37 ++++++---
 em-format/e-mail-formatter-text-plain.c            |   69 ++++++++++-------
 em-format/e-mail-formatter.c                       |   80 +++++++++-----------
 em-format/e-mail-formatter.h                       |   10 +-
 em-format/e-mail-part-utils.c                      |   73 ++++++++++--------
 em-format/e-mail-part-utils.h                      |    6 +-
 mail/e-mail-request.c                              |   46 ++++++------
 mail/em-utils.c                                    |   25 ++++---
 modules/itip-formatter/e-mail-formatter-itip.c     |    5 +-
 .../e-mail-formatter-text-highlight.c              |   34 +++------
 modules/vcard-inline/e-mail-formatter-vcard.c      |   39 ++++++----
 33 files changed, 552 insertions(+), 430 deletions(-)
---
diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c
index 0ac90e6..dddd59a 100644
--- a/composer/e-msg-composer.c
+++ b/composer/e-msg-composer.c
@@ -187,8 +187,7 @@ emcu_part_to_html (EMsgComposer *composer,
                    GCancellable *cancellable)
 {
        CamelSession *session;
-       CamelStreamMem *mem;
-       GByteArray *buf;
+       GOutputStream *stream;
        gchar *text;
        EMailParser *parser;
        EMailFormatter *formatter;
@@ -227,9 +226,7 @@ emcu_part_to_html (EMsgComposer *composer,
                return NULL;
        }
 
-       buf = g_byte_array_new ();
-       mem = (CamelStreamMem *) camel_stream_mem_new ();
-       camel_stream_mem_set_byte_array (mem, buf);
+       stream = g_memory_output_stream_new_resizable ();
 
        formatter = e_mail_formatter_quote_new (
                NULL, keep_signature ? E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG : 0);
@@ -238,19 +235,23 @@ emcu_part_to_html (EMsgComposer *composer,
                gtk_widget_get_state_flags (GTK_WIDGET (window)));
 
        e_mail_formatter_format_sync (
-               formatter, part_list, (CamelStream *) mem,
+               formatter, part_list, stream,
                0, E_MAIL_FORMATTER_MODE_PRINTING, cancellable);
+
        g_object_unref (formatter);
        g_object_unref (part_list);
 
-       camel_stream_write ((CamelStream *) mem, "", 1, cancellable, NULL);
-       g_object_unref (mem);
+       g_output_stream_write (stream, "", 1, NULL, NULL);
+
+       g_output_stream_close (stream, NULL, NULL);
 
-       text = (gchar *) buf->data;
-       if (len)
-               *len = buf->len - 1;
+       text = g_memory_output_stream_steal_data (
+               G_MEMORY_OUTPUT_STREAM (stream));
 
-       g_byte_array_free (buf, FALSE);
+       if (len != NULL)
+               *len = strlen (text);
+
+       g_object_unref (stream);
 
        return text;
 }
diff --git a/em-format/e-mail-formatter-attachment-bar.c b/em-format/e-mail-formatter-attachment-bar.c
index 9c3ab49..f32cf80 100644
--- a/em-format/e-mail-formatter-attachment-bar.c
+++ b/em-format/e-mail-formatter-attachment-bar.c
@@ -45,7 +45,7 @@ emfe_attachment_bar_format (EMailFormatterExtension *extension,
                             EMailFormatter *formatter,
                             EMailFormatterContext *context,
                             EMailPart *part,
-                            CamelStream *stream,
+                            GOutputStream *stream,
                             GCancellable *cancellable)
 {
        gchar *str;
@@ -61,7 +61,8 @@ emfe_attachment_bar_format (EMailFormatterExtension *extension,
                e_mail_part_get_id (part),
                e_mail_part_get_id (part));
 
-       camel_stream_write_string (stream, str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, str, strlen (str), NULL, cancellable, NULL);
 
        g_free (str);
 
diff --git a/em-format/e-mail-formatter-attachment.c b/em-format/e-mail-formatter-attachment.c
index fd098d7..ea0bcd7 100644
--- a/em-format/e-mail-formatter-attachment.c
+++ b/em-format/e-mail-formatter-attachment.c
@@ -113,10 +113,10 @@ emfe_attachment_format (EMailFormatterExtension *extension,
                         EMailFormatter *formatter,
                         EMailFormatterContext *context,
                         EMailPart *part,
-                        CamelStream *stream,
+                        GOutputStream *stream,
                         GCancellable *cancellable)
 {
-       gchar *str, *text, *html;
+       gchar *text, *html;
        gchar *button_id;
        EAttachmentStore *store;
        EMailExtensionRegistry *registry;
@@ -124,6 +124,7 @@ emfe_attachment_format (EMailFormatterExtension *extension,
        EMailPartAttachment *empa;
        CamelMimePart *mime_part;
        CamelMimeFilterToHTMLFlags flags;
+       GString *buffer;
        const gchar *attachment_part_id;
        const gchar *part_id;
 
@@ -217,8 +218,9 @@ emfe_attachment_format (EMailFormatterExtension *extension,
                                        display_name);
                        }
 
-                       camel_stream_write_string (
-                               stream, name, cancellable, NULL);
+                       g_output_stream_write_all (
+                               stream, name, strlen (name),
+                               NULL, cancellable, NULL);
 
                        g_free (description);
                        g_free (name);
@@ -257,7 +259,11 @@ emfe_attachment_format (EMailFormatterExtension *extension,
 
        button_id = g_strconcat (attachment_part_id, ".attachment_button", NULL);
 
-       str = g_strdup_printf (
+       /* XXX Wild guess at the initial size. */
+       buffer = g_string_sized_new (8192);
+
+       g_string_append_printf (
+               buffer,
                "<div class=\"attachment\">"
                "<table width=\"100%%\" border=\"0\">"
                "<tr valign=\"middle\">"
@@ -268,16 +274,15 @@ emfe_attachment_format (EMailFormatterExtension *extension,
                "<td align=\"left\">%s</td>"
                "</tr>", part_id, button_id, html);
 
-       camel_stream_write_string (stream, str, cancellable, NULL);
        g_free (button_id);
-       g_free (str);
        g_free (html);
 
        if (extensions != NULL) {
-               CamelStream *content_stream;
+               GOutputStream *content_stream;
                gboolean success = FALSE;
 
-               content_stream = camel_stream_mem_new ();
+               content_stream = g_memory_output_stream_new_resizable ();
+
                if (empa->attachment_view_part_id != NULL) {
                        EMailPart *attachment_view_part;
 
@@ -316,35 +321,41 @@ emfe_attachment_format (EMailFormatterExtension *extension,
 
                if (success) {
                        gchar *wrapper_element_id;
+                       gconstpointer data;
+                       gsize size;
 
                        wrapper_element_id = g_strconcat (
                                attachment_part_id, ".wrapper", NULL);
 
-                       str = g_strdup_printf (
+                       data = g_memory_output_stream_get_data (
+                               G_MEMORY_OUTPUT_STREAM (content_stream));
+                       size = g_memory_output_stream_get_data_size (
+                               G_MEMORY_OUTPUT_STREAM (content_stream));
+
+                       buffer = g_string_sized_new (size);
+
+                       g_string_append_printf (
+                               buffer,
                                "<tr><td colspan=\"2\">"
                                "<div class=\"attachment-wrapper\" id=\"%s\">",
                                wrapper_element_id);
 
-                       camel_stream_write_string (
-                               stream, str, cancellable, NULL);
+                       g_string_append_len (buffer, data, size);
 
-                       g_seekable_seek (
-                               G_SEEKABLE (content_stream), 0,
-                               G_SEEK_SET, cancellable, NULL);
-                       camel_stream_write_to_stream (
-                               content_stream, stream, cancellable, NULL);
-
-                       camel_stream_write_string (
-                               stream, "</div></td></tr>", cancellable, NULL);
+                       g_string_append (buffer, "</div></td></tr>");
 
                        g_free (wrapper_element_id);
-                       g_free (str);
                }
 
                g_object_unref (content_stream);
        }
 
-       camel_stream_write_string (stream, "</table></div>", cancellable, NULL);
+       g_string_append (buffer, "</table></div>");
+
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
+
+       g_string_free (buffer, TRUE);
 
        return TRUE;
 }
diff --git a/em-format/e-mail-formatter-audio.c b/em-format/e-mail-formatter-audio.c
index 228f238..cf980f8 100644
--- a/em-format/e-mail-formatter-audio.c
+++ b/em-format/e-mail-formatter-audio.c
@@ -71,14 +71,13 @@ mail_formatter_audio_format (EMailFormatterExtension *extension,
                              EMailFormatter *formatter,
                              EMailFormatterContext *context,
                              EMailPart *part,
-                             CamelStream *stream,
+                             GOutputStream *stream,
                              GCancellable *cancellable)
 {
        CamelMimePart *mime_part;
        CamelDataWrapper *content;
        CamelTransferEncoding encoding;
-       CamelStream *mem_stream;
-       GByteArray *byte_array;
+       GOutputStream *mem_stream;
        const gchar *mime_type;
        gchar *html;
        GError *local_error = NULL;
@@ -91,28 +90,37 @@ mail_formatter_audio_format (EMailFormatterExtension *extension,
        if (mime_type == NULL)
                mime_type = "audio/*";
 
-       mem_stream = camel_stream_mem_new ();
-       byte_array = camel_stream_mem_get_byte_array (
-               CAMEL_STREAM_MEM (mem_stream));
+       mem_stream = g_memory_output_stream_new_resizable ();
 
        if (encoding == CAMEL_TRANSFER_ENCODING_BASE64) {
-               camel_data_wrapper_write_to_stream_sync (
+               const gchar *data;
+
+               camel_data_wrapper_write_to_output_stream_sync (
                        content, mem_stream, cancellable, &local_error);
 
+               data = g_memory_output_stream_get_data (
+                       G_MEMORY_OUTPUT_STREAM (mem_stream));
+
                html = g_strdup_printf (
                        "<audio controls>"
                        "<source src=\"data:%s;base64,%s\"/>"
                        "</audio>",
-                       mime_type, (gchar *) byte_array->data);
+                       mime_type, data);
 
        } else {
+               const guchar *data;
                gchar *base64;
+               gsize size;
 
-               camel_data_wrapper_decode_to_stream_sync (
+               camel_data_wrapper_decode_to_output_stream_sync (
                        content, mem_stream, cancellable, &local_error);
 
-               base64 = g_base64_encode (
-                       (guchar *) byte_array->data, byte_array->len);
+               data = g_memory_output_stream_get_data (
+                       G_MEMORY_OUTPUT_STREAM (mem_stream));
+               size = g_memory_output_stream_get_data_size (
+                       G_MEMORY_OUTPUT_STREAM (mem_stream));
+
+               base64 = g_base64_encode (data, size);
                html = g_strdup_printf (
                        "<audio controls>"
                        "<source src=\"data:%s;base64,%s\"/>"
@@ -127,7 +135,8 @@ mail_formatter_audio_format (EMailFormatterExtension *extension,
                g_error_free (local_error);
        }
 
-       camel_stream_write_string (stream, html, NULL, NULL);
+       g_output_stream_write_all (
+               stream, html, strlen (html), NULL, cancellable, NULL);
 
        g_free (html);
 
diff --git a/em-format/e-mail-formatter-error.c b/em-format/e-mail-formatter-error.c
index 9c53a99..117fcd6 100644
--- a/em-format/e-mail-formatter-error.c
+++ b/em-format/e-mail-formatter-error.c
@@ -45,13 +45,14 @@ emfe_error_format (EMailFormatterExtension *extension,
                    EMailFormatter *formatter,
                    EMailFormatterContext *context,
                    EMailPart *part,
-                   CamelStream *stream,
+                   GOutputStream *stream,
                    GCancellable *cancellable)
 {
-       CamelStream *filtered_stream;
+       GOutputStream *filtered_stream;
        CamelMimeFilter *filter;
        CamelMimePart *mime_part;
        CamelDataWrapper *dw;
+       const gchar *string;
        gchar *html;
 
        mime_part = e_mail_part_ref_mime_part (part);
@@ -68,28 +69,27 @@ emfe_error_format (EMailFormatterExtension *extension,
                "<td style=\"color: red;\">",
                "dialog-error", GTK_ICON_SIZE_DIALOG);
 
-       camel_stream_write_string (stream, html, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, html, strlen (html), NULL, cancellable, NULL);
+
        g_free (html);
 
-       filtered_stream = camel_stream_filter_new (stream);
        filter = camel_mime_filter_tohtml_new (
                CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
                CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS, 0);
-       camel_stream_filter_add (CAMEL_STREAM_FILTER (filtered_stream), filter);
+       filtered_stream = camel_filter_output_stream_new (stream, filter);
        g_object_unref (filter);
 
-       camel_data_wrapper_decode_to_stream_sync (dw, filtered_stream, cancellable, NULL);
-       camel_stream_flush (filtered_stream, cancellable, NULL);
+       camel_data_wrapper_decode_to_output_stream_sync (
+               dw, filtered_stream, cancellable, NULL);
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
+
        g_object_unref (filtered_stream);
 
-       camel_stream_write_string (
-               stream,
-               "</td>\n"
-               "</tr>\n"
-               "</table>\n"
-               "</div>\n"
-               "</div>",
-               cancellable, NULL);
+       string = "</td></tr></table></div></div>";
+
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        g_object_unref (mime_part);
 
diff --git a/em-format/e-mail-formatter-extension.c b/em-format/e-mail-formatter-extension.c
index 6d7f6de..55b481b 100644
--- a/em-format/e-mail-formatter-extension.c
+++ b/em-format/e-mail-formatter-extension.c
@@ -39,7 +39,7 @@ e_mail_formatter_extension_init (EMailFormatterExtension *extension)
  * @formatter: an #EMailFormatter
  * @context: an #EMailFormatterContext
  * @part: a #EMailPart to be formatter
- * @stream: a #CamelStream to which the output should be written
+ * @stream: a #GOutputStream to which the output should be written
  * @cancellable: (allow-none) a #GCancellable
  *
  * A virtual function reimplemented in all mail formatter extensions. The
@@ -61,7 +61,7 @@ e_mail_formatter_extension_format (EMailFormatterExtension *extension,
                                    EMailFormatter *formatter,
                                    EMailFormatterContext *context,
                                    EMailPart *part,
-                                   CamelStream *stream,
+                                   GOutputStream *stream,
                                    GCancellable *cancellable)
 {
        EMailFormatterExtensionClass *class;
@@ -70,12 +70,13 @@ e_mail_formatter_extension_format (EMailFormatterExtension *extension,
        g_return_val_if_fail (E_IS_MAIL_FORMATTER (formatter), FALSE);
        g_return_val_if_fail (context != NULL, FALSE);
        g_return_val_if_fail (part != NULL, FALSE);
-       g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+       g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
 
        class = E_MAIL_FORMATTER_EXTENSION_GET_CLASS (extension);
        g_return_val_if_fail (class->format != NULL, FALSE);
 
-       return class->format (extension, formatter, context, part, stream, cancellable);
+       return class->format (
+               extension, formatter, context, part, stream, cancellable);
 }
 
 /**
diff --git a/em-format/e-mail-formatter-extension.h b/em-format/e-mail-formatter-extension.h
index 21642d3..adfe98f 100644
--- a/em-format/e-mail-formatter-extension.h
+++ b/em-format/e-mail-formatter-extension.h
@@ -81,7 +81,7 @@ struct _EMailFormatterExtensionClass {
                                         EMailFormatter *formatter,
                                         EMailFormatterContext *context,
                                         EMailPart *part,
-                                        CamelStream *stream,
+                                        GOutputStream *stream,
                                         GCancellable *cancellable);
        GtkWidget *     (*get_widget)   (EMailFormatterExtension *extension,
                                         EMailPartList *context,
@@ -96,7 +96,7 @@ gboolean      e_mail_formatter_extension_format
                                                 EMailFormatter *formatter,
                                                 EMailFormatterContext *context,
                                                 EMailPart *part,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 GCancellable *cancellable);
 gboolean       e_mail_formatter_extension_has_widget
                                                (EMailFormatterExtension *extension);
diff --git a/em-format/e-mail-formatter-headers.c b/em-format/e-mail-formatter-headers.c
index 1ccb822..8ee6e38 100644
--- a/em-format/e-mail-formatter-headers.c
+++ b/em-format/e-mail-formatter-headers.c
@@ -480,7 +480,7 @@ emfe_headers_format (EMailFormatterExtension *extension,
                      EMailFormatter *formatter,
                      EMailFormatterContext *context,
                      EMailPart *part,
-                     CamelStream *stream,
+                     GOutputStream *stream,
                      GCancellable *cancellable)
 {
        CamelMimePart *mime_part;
@@ -557,7 +557,8 @@ emfe_headers_format (EMailFormatterExtension *extension,
 
        g_string_append (buffer, "</tr></table></div>");
 
-       camel_stream_write_string (stream, buffer->str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
 
        g_string_free (buffer, TRUE);
 
diff --git a/em-format/e-mail-formatter-image.c b/em-format/e-mail-formatter-image.c
index 610405f..619082f 100644
--- a/em-format/e-mail-formatter-image.c
+++ b/em-format/e-mail-formatter-image.c
@@ -64,14 +64,14 @@ emfe_image_format (EMailFormatterExtension *extension,
                    EMailFormatter *formatter,
                    EMailFormatterContext *context,
                    EMailPart *part,
-                   CamelStream *stream,
+                   GOutputStream *stream,
                    GCancellable *cancellable)
 {
        gchar *content;
        CamelMimePart *mime_part;
        CamelDataWrapper *dw;
-       GByteArray *ba;
-       CamelStream *raw_content;
+       GBytes *bytes;
+       GOutputStream *raw_content;
 
        if (g_cancellable_is_cancelled (cancellable))
                return FALSE;
@@ -80,9 +80,13 @@ emfe_image_format (EMailFormatterExtension *extension,
        dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
        g_return_val_if_fail (dw, FALSE);
 
-       raw_content = camel_stream_mem_new ();
-       camel_data_wrapper_decode_to_stream_sync (dw, raw_content, cancellable, NULL);
-       ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (raw_content));
+       raw_content = g_memory_output_stream_new_resizable ();
+       camel_data_wrapper_decode_to_output_stream_sync (
+               dw, raw_content, cancellable, NULL);
+       g_output_stream_close (raw_content, NULL, NULL);
+
+       bytes = g_memory_output_stream_steal_as_bytes (
+               G_MEMORY_OUTPUT_STREAM (raw_content));
 
        if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
 
@@ -91,17 +95,22 @@ emfe_image_format (EMailFormatterExtension *extension,
                        gchar *buff;
                        gsize len;
 
-                       e_mail_part_animation_extract_frame (ba, &buff, &len);
+                       e_mail_part_animation_extract_frame (
+                               bytes, &buff, &len);
 
-                       camel_stream_write (stream, buff, len, cancellable, NULL);
+                       g_output_stream_write_all (
+                               stream, buff, len, NULL, cancellable, NULL);
 
                        g_free (buff);
 
                } else {
+                       gconstpointer data;
+                       gsize size;
+
+                       data = g_bytes_get_data (bytes, &size);
 
-                       camel_stream_write (
-                               stream, (gchar *) ba->data,
-                               ba->len, cancellable, NULL);
+                       g_output_stream_write_all (
+                               stream, data, size, NULL, cancellable, NULL);
                }
 
        } else {
@@ -113,13 +122,18 @@ emfe_image_format (EMailFormatterExtension *extension,
                        gchar *buff;
                        gsize len;
 
-                       e_mail_part_animation_extract_frame (ba, &buff, &len);
+                       e_mail_part_animation_extract_frame (
+                               bytes, &buff, &len);
 
                        content = g_base64_encode ((guchar *) buff, len);
                        g_free (buff);
 
                } else {
-                       content = g_base64_encode ((guchar *) ba->data, ba->len);
+                       gconstpointer data;
+                       gsize size;
+
+                       data = g_bytes_get_data (bytes, &size);
+                       content = g_base64_encode (data, size);
                }
 
                mime_type = e_mail_part_get_mime_type (part);
@@ -133,11 +147,16 @@ emfe_image_format (EMailFormatterExtension *extension,
                        "     style=\"max-width: 100%%;\" />",
                        mime_type, content);
 
-               camel_stream_write_string (stream, buffer, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, buffer, strlen (buffer),
+                       NULL, cancellable, NULL);
+
                g_free (buffer);
                g_free (content);
        }
 
+       g_bytes_unref (bytes);
+
        g_object_unref (raw_content);
 
        g_object_unref (mime_part);
diff --git a/em-format/e-mail-formatter-message-rfc822.c b/em-format/e-mail-formatter-message-rfc822.c
index c8378d2..8884cbc 100644
--- a/em-format/e-mail-formatter-message-rfc822.c
+++ b/em-format/e-mail-formatter-message-rfc822.c
@@ -49,7 +49,7 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
                             EMailFormatter *formatter,
                             EMailFormatterContext *context,
                             EMailPart *part,
-                            CamelStream *stream,
+                            GOutputStream *stream,
                             GCancellable *cancellable)
 {
        const gchar *part_id;
@@ -63,9 +63,12 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
                GQueue queue = G_QUEUE_INIT;
                GList *head, *link;
                gchar *header, *end;
+               const gchar *string;
 
                header = e_mail_formatter_get_html_header (formatter);
-               camel_stream_write_string (stream, header, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, header, strlen (header),
+                       NULL, cancellable, NULL);
                g_free (header);
 
                /* Print content of the message normally */
@@ -122,7 +125,11 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
 
                context->mode = E_MAIL_FORMATTER_MODE_RAW;
 
-               camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+               string = "</body></html>";
+
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
 
        } else if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
                GQueue queue = G_QUEUE_INIT;
@@ -228,7 +235,9 @@ emfe_message_rfc822_format (EMailFormatterExtension *extension,
                        "</div>",
                        part_id, uri, part_id);
 
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str),
+                       NULL, cancellable, NULL);
 
                g_free (str);
                g_free (uri);
diff --git a/em-format/e-mail-formatter-print-headers.c b/em-format/e-mail-formatter-print-headers.c
index da2f43a..7825913 100644
--- a/em-format/e-mail-formatter-print-headers.c
+++ b/em-format/e-mail-formatter-print-headers.c
@@ -52,7 +52,7 @@ emfpe_headers_format (EMailFormatterExtension *extension,
                       EMailFormatter *formatter,
                       EMailFormatterContext *context,
                       EMailPart *part,
-                      CamelStream *stream,
+                      GOutputStream *stream,
                       GCancellable *cancellable)
 {
        EMailPartHeaders *headers_part;
@@ -211,7 +211,9 @@ emfpe_headers_format (EMailFormatterExtension *extension,
 
        g_string_append (str, "</table>");
 
-       camel_stream_write_string (stream, str->str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, str->str, str->len, NULL, cancellable, NULL);
+
        g_string_free (str, TRUE);
        g_free (part_id_prefix);
 
diff --git a/em-format/e-mail-formatter-print.c b/em-format/e-mail-formatter-print.c
index b7609c8..d67743d 100644
--- a/em-format/e-mail-formatter-print.c
+++ b/em-format/e-mail-formatter-print.c
@@ -38,7 +38,7 @@ static gpointer e_mail_formatter_print_parent_class = 0;
 static void
 mail_formatter_print_write_attachments (EMailFormatter *formatter,
                                         GQueue *attachments,
-                                        CamelStream *stream,
+                                        GOutputStream *stream,
                                         GCancellable *cancellable)
 {
        GString *str;
@@ -96,7 +96,8 @@ mail_formatter_print_write_attachments (EMailFormatter *formatter,
 
        g_string_append (str, "</table>\n");
 
-       camel_stream_write_string (stream, str->str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, str->str, str->len, NULL, cancellable, NULL);
 
        g_string_free (str, TRUE);
 }
@@ -104,17 +105,17 @@ mail_formatter_print_write_attachments (EMailFormatter *formatter,
 static void
 mail_formatter_print_run (EMailFormatter *formatter,
                           EMailFormatterContext *context,
-                          CamelStream *stream,
+                          GOutputStream *stream,
                           GCancellable *cancellable)
 {
        GQueue queue = G_QUEUE_INIT;
        GQueue attachments = G_QUEUE_INIT;
        GList *head, *link;
+       const gchar *string;
 
        context->mode = E_MAIL_FORMATTER_MODE_PRINTING;
 
-       camel_stream_write_string (
-               stream,
+       string =
                "<!DOCTYPE HTML>\n"
                "<html>\n"
                "<head>\n"
@@ -123,8 +124,10 @@ mail_formatter_print_run (EMailFormatter *formatter,
                "<link type=\"text/css\" rel=\"stylesheet\" "
                "      media=\"print\" href=\"" STYLESHEET_URI "/>\n"
                "</head>\n"
-               "<body style=\"background: #FFF; color: #000;\">",
-               cancellable, NULL);
+               "<body style=\"background: #FFF; color: #000;\">";
+
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
 
@@ -181,7 +184,11 @@ mail_formatter_print_run (EMailFormatter *formatter,
                        formatter, &attachments,
                        stream, cancellable);
 
-       camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+       string = "</body></html>";
+
+       g_output_stream_write_all (
+               stream, string, strlen (string),
+               NULL, cancellable, NULL);
 }
 
 static void
diff --git a/em-format/e-mail-formatter-quote-attachment.c b/em-format/e-mail-formatter-quote-attachment.c
index 4ed2f49..0ec4889 100644
--- a/em-format/e-mail-formatter-quote-attachment.c
+++ b/em-format/e-mail-formatter-quote-attachment.c
@@ -51,7 +51,7 @@ emfqe_attachment_format (EMailFormatterExtension *extension,
                          EMailFormatter *formatter,
                          EMailFormatterContext *context,
                          EMailPart *part,
-                         CamelStream *stream,
+                         GOutputStream *stream,
                          GCancellable *cancellable)
 {
        gchar *text, *html;
@@ -59,6 +59,7 @@ emfqe_attachment_format (EMailFormatterExtension *extension,
        EMailPart *attachment_view_part;
        CamelMimeFilterToHTMLFlags text_format_flags;
        CamelMimePart *mime_part;
+       const gchar *string;
 
        empa = E_MAIL_PART_ATTACHMENT (part);
 
@@ -70,7 +71,9 @@ emfqe_attachment_format (EMailFormatterExtension *extension,
        if (attachment_view_part == NULL)
                return FALSE;
 
-       camel_stream_write_string (stream, "<br><br>", cancellable, NULL);
+       string = "<br><br>";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        text_format_flags =
                e_mail_formatter_get_text_format_flags (formatter);
@@ -86,26 +89,29 @@ emfqe_attachment_format (EMailFormatterExtension *extension,
                text,
                text_format_flags & CAMEL_MIME_FILTER_TOHTML_CONVERT_URLS,
                0);
-       camel_stream_write_string (stream, html, cancellable, NULL);
-       camel_stream_write_string (stream, "<br>", cancellable, NULL);
+       g_output_stream_write_all (
+               stream, html, strlen (html), NULL, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, "<br>", 4, NULL, cancellable, NULL);
        g_free (html);
        g_free (text);
 
-       camel_stream_write_string (
-               stream,
+       string =
                "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
                "key=\"orig\" value=\"1\">-->\n"
-               "<blockquote type=cite>\n", cancellable, NULL);
+               "<blockquote type=cite>\n";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        e_mail_formatter_format_as (
                formatter, context, attachment_view_part,
                stream, NULL, cancellable);
 
-       camel_stream_write_string (
-               stream,
+       string =
                "</blockquote><!--+GtkHTML:"
-               "<DATA class=\"ClueFlow\" clear=\"orig\">-->",
-               cancellable, NULL);
+               "<DATA class=\"ClueFlow\" clear=\"orig\">-->";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        g_object_unref (attachment_view_part);
 
diff --git a/em-format/e-mail-formatter-quote-headers.c b/em-format/e-mail-formatter-quote-headers.c
index 5d7d5f3..e996bd0 100644
--- a/em-format/e-mail-formatter-quote-headers.c
+++ b/em-format/e-mail-formatter-quote-headers.c
@@ -219,7 +219,7 @@ emqfe_headers_format (EMailFormatterExtension *extension,
                       EMailFormatter *formatter,
                       EMailFormatterContext *context,
                       EMailPart *part,
-                      CamelStream *stream,
+                      GOutputStream *stream,
                       GCancellable *cancellable)
 {
        CamelContentType *ct;
@@ -255,7 +255,8 @@ emqfe_headers_format (EMailFormatterExtension *extension,
 
        g_string_append (buffer, "<br>\n");
 
-       camel_stream_write_string (stream, buffer->str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
 
        g_string_free (buffer, TRUE);
 
diff --git a/em-format/e-mail-formatter-quote-message-rfc822.c 
b/em-format/e-mail-formatter-quote-message-rfc822.c
index ae50508..180a283 100644
--- a/em-format/e-mail-formatter-quote-message-rfc822.c
+++ b/em-format/e-mail-formatter-quote-message-rfc822.c
@@ -51,7 +51,7 @@ emfqe_message_rfc822_format (EMailFormatterExtension *extension,
                              EMailFormatter *formatter,
                              EMailFormatterContext *context,
                              EMailPart *part,
-                             CamelStream *stream,
+                             GOutputStream *stream,
                              GCancellable *cancellable)
 {
        GQueue queue = G_QUEUE_INIT;
@@ -59,6 +59,7 @@ emfqe_message_rfc822_format (EMailFormatterExtension *extension,
        gchar *header, *end;
        EMailFormatterQuoteContext *qc = (EMailFormatterQuoteContext *) context;
        const gchar *part_id;
+       const gchar *string;
 
        part_id = e_mail_part_get_id (part);
 
@@ -66,7 +67,8 @@ emfqe_message_rfc822_format (EMailFormatterExtension *extension,
                return FALSE;
 
        header = e_mail_formatter_get_html_header (formatter);
-       camel_stream_write_string (stream, header, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, header, strlen (header), NULL, cancellable, NULL);
        g_free (header);
 
        e_mail_part_list_queue_parts (context->part_list, part_id, &queue);
@@ -134,7 +136,9 @@ emfqe_message_rfc822_format (EMailFormatterExtension *extension,
        while (!g_queue_is_empty (&queue))
                g_object_unref (g_queue_pop_head (&queue));
 
-       camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+       string = "</body></html>";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        return TRUE;
 }
diff --git a/em-format/e-mail-formatter-quote-text-enriched.c 
b/em-format/e-mail-formatter-quote-text-enriched.c
index 5eec82a..390bbd6 100644
--- a/em-format/e-mail-formatter-quote-text-enriched.c
+++ b/em-format/e-mail-formatter-quote-text-enriched.c
@@ -49,36 +49,38 @@ emqfe_text_enriched_format (EMailFormatterExtension *extension,
                             EMailFormatter *formatter,
                             EMailFormatterContext *context,
                             EMailPart *part,
-                            CamelStream *stream,
+                            GOutputStream *stream,
                             GCancellable *cancellable)
 {
-       CamelStream *filtered_stream;
-       CamelMimeFilter *enriched;
+       GOutputStream *filtered_stream;
+       CamelMimeFilter *filter;
        const gchar *mime_type;
+       const gchar *string;
        guint32 camel_flags = 0;
 
        mime_type = e_mail_part_get_mime_type (part);
 
        if (g_strcmp0 (mime_type, "text/richtext") == 0) {
                camel_flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT;
-               camel_stream_write_string (
-                       stream, "\n<!-- text/richtext -->\n",
-                       cancellable, NULL);
+               string = "\n<!-- text/richtext -->\n";
        } else {
-               camel_stream_write_string (
-                       stream, "\n<!-- text/enriched -->\n",
-                       cancellable, NULL);
+               string = "\n<!-- text/enriched -->\n";
        }
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
-       enriched = camel_mime_filter_enriched_new (camel_flags);
-       filtered_stream = camel_stream_filter_new (stream);
-       camel_stream_filter_add (
-               CAMEL_STREAM_FILTER (filtered_stream), enriched);
-       g_object_unref (enriched);
+       string = "<br><hr><br>";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
+
+       filter = camel_mime_filter_enriched_new (camel_flags);
+       filtered_stream = camel_filter_output_stream_new (stream, filter);
+       g_object_unref (filter);
+
+       e_mail_formatter_format_text (
+               formatter, part, filtered_stream, cancellable);
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
 
-       camel_stream_write_string (stream, "<br><hr><br>", cancellable, NULL);
-       e_mail_formatter_format_text (formatter, part, filtered_stream, cancellable);
-       camel_stream_flush (filtered_stream, cancellable, NULL);
        g_object_unref (filtered_stream);
 
        return TRUE;
diff --git a/em-format/e-mail-formatter-quote-text-html.c b/em-format/e-mail-formatter-quote-text-html.c
index 7183fac..5ae94f7 100644
--- a/em-format/e-mail-formatter-quote-text-html.c
+++ b/em-format/e-mail-formatter-quote-text-html.c
@@ -50,36 +50,40 @@ emqfe_text_html_format (EMailFormatterExtension *extension,
                         EMailFormatter *formatter,
                         EMailFormatterContext *context,
                         EMailPart *part,
-                        CamelStream *stream,
+                        GOutputStream *stream,
                         GCancellable *cancellable)
 {
        EMailFormatterQuoteContext *qf_context;
+       GOutputStream *filtered_stream;
+       const gchar *string;
 
        qf_context = (EMailFormatterQuoteContext *) context;
 
-       camel_stream_write_string (
-               stream, "\n<!-- text/html -->\n", cancellable, NULL);
+       string = "\n<!-- text/html -->\n";
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
-       if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
-               CamelMimeFilter *sig_strip;
-               CamelStream *filtered_stream;
-
-               filtered_stream = camel_stream_filter_new (stream);
+       filtered_stream = g_object_ref (stream);
 
-               sig_strip = e_mail_stripsig_filter_new (FALSE);
-               camel_stream_filter_add (
-                       CAMEL_STREAM_FILTER (filtered_stream), sig_strip);
-               g_object_unref (sig_strip);
+       if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
+               CamelMimeFilter *filter;
+               GOutputStream *temp_stream;
 
-               e_mail_formatter_format_text (
-                       formatter, part, filtered_stream, cancellable);
-               camel_stream_flush (filtered_stream, cancellable, NULL);
+               filter = e_mail_stripsig_filter_new (FALSE);
+               temp_stream = camel_filter_output_stream_new (
+                       filtered_stream, filter);
                g_object_unref (filtered_stream);
-       } else {
-               e_mail_formatter_format_text (
-                       formatter, part, stream, cancellable);
+               filtered_stream = temp_stream;
+               g_object_unref (filter);
        }
 
+       e_mail_formatter_format_text (
+               formatter, part, filtered_stream, cancellable);
+
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
+
+       g_object_unref (filtered_stream);
+
        return TRUE;
 }
 
diff --git a/em-format/e-mail-formatter-quote-text-plain.c b/em-format/e-mail-formatter-quote-text-plain.c
index d0623f2..d53cc53 100644
--- a/em-format/e-mail-formatter-quote-text-plain.c
+++ b/em-format/e-mail-formatter-quote-text-plain.c
@@ -49,12 +49,12 @@ emqfe_text_plain_format (EMailFormatterExtension *extension,
                          EMailFormatter *formatter,
                          EMailFormatterContext *context,
                          EMailPart *part,
-                         CamelStream *stream,
+                         GOutputStream *stream,
                          GCancellable *cancellable)
 {
-       CamelStream *filtered_stream;
-       CamelMimeFilter *html_filter;
-       CamelMimeFilter *sig_strip;
+       GOutputStream *filtered_stream;
+       GOutputStream *temp_stream;
+       CamelMimeFilter *filter;
        CamelMimePart *mime_part;
        CamelContentType *type;
        EMailFormatterQuoteContext *qf_context;
@@ -83,24 +83,27 @@ emqfe_text_plain_format (EMailFormatterExtension *extension,
            && !g_ascii_strcasecmp (format, "flowed"))
                text_flags |= CAMEL_MIME_FILTER_TOHTML_FORMAT_FLOWED;
 
-       filtered_stream = camel_stream_filter_new (stream);
+       filtered_stream = g_object_ref (stream);
 
        if ((qf_context->qf_flags & E_MAIL_FORMATTER_QUOTE_FLAG_KEEP_SIG) == 0) {
-               sig_strip = e_mail_stripsig_filter_new (TRUE);
-               camel_stream_filter_add (
-                       CAMEL_STREAM_FILTER (filtered_stream), sig_strip);
-               g_object_unref (sig_strip);
+               filter = e_mail_stripsig_filter_new (TRUE);
+               temp_stream = camel_filter_output_stream_new (
+                       filtered_stream, filter);
+               g_object_unref (filtered_stream);
+               filtered_stream = temp_stream;
+               g_object_unref (filter);
        }
 
-       html_filter = camel_mime_filter_tohtml_new (text_flags, rgb);
-       camel_stream_filter_add (
-               CAMEL_STREAM_FILTER (filtered_stream), html_filter);
-       g_object_unref (html_filter);
+       filter = camel_mime_filter_tohtml_new (text_flags, rgb);
+       temp_stream = camel_filter_output_stream_new (filtered_stream, filter);
+       g_object_unref (filtered_stream);
+       filtered_stream = temp_stream;
+       g_object_unref (filter);
 
        e_mail_formatter_format_text (
                formatter, part, filtered_stream, cancellable);
 
-       camel_stream_flush (filtered_stream, cancellable, NULL);
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
        g_object_unref (filtered_stream);
 
        g_object_unref (mime_part);
diff --git a/em-format/e-mail-formatter-quote.c b/em-format/e-mail-formatter-quote.c
index cbfc26c..1a76568 100644
--- a/em-format/e-mail-formatter-quote.c
+++ b/em-format/e-mail-formatter-quote.c
@@ -52,7 +52,7 @@ static gpointer e_mail_formatter_quote_parent_class = 0;
 static void
 mail_formatter_quote_run (EMailFormatter *formatter,
                           EMailFormatterContext *context,
-                          CamelStream *stream,
+                          GOutputStream *stream,
                           GCancellable *cancellable)
 {
        EMailFormatterQuote *qf;
@@ -60,6 +60,7 @@ mail_formatter_quote_run (EMailFormatter *formatter,
        GSettings *settings;
        GQueue queue = G_QUEUE_INIT;
        GList *head, *link;
+       const gchar *string;
 
        if (g_cancellable_is_cancelled (cancellable))
                return;
@@ -74,26 +75,31 @@ mail_formatter_quote_run (EMailFormatter *formatter,
                0, G_SEEK_SET, NULL, NULL);
 
        settings = g_settings_new ("org.gnome.evolution.mail");
-       if (g_settings_get_boolean (
-               settings, "composer-top-signature"))
-               camel_stream_write_string (
-                       stream, "<br>\n", cancellable, NULL);
+       if (g_settings_get_boolean (settings, "composer-top-signature")) {
+               string = "<br>\n";
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
+       }
        g_object_unref (settings);
 
-       if (qf->priv->credits && *qf->priv->credits) {
-               gchar *credits = g_strdup_printf ("%s<br>", qf->priv->credits);
-               camel_stream_write_string (stream, credits, cancellable, NULL);
-               g_free (credits);
-       } else {
-               camel_stream_write_string (stream, "<br>", cancellable, NULL);
+       if (qf->priv->credits != NULL && *qf->priv->credits != '\0') {
+               g_output_stream_write_all (
+                       stream, qf->priv->credits,
+                       strlen (qf->priv->credits),
+                       NULL, cancellable, NULL);
        }
 
+       g_output_stream_write_all (
+               stream, "<br>", 4, NULL, cancellable, NULL);
+
        if (qf->priv->flags & E_MAIL_FORMATTER_QUOTE_FLAG_CITE) {
-               camel_stream_write_string (
-                       stream,
-                       "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
+               string = "<!--+GtkHTML:<DATA class=\"ClueFlow\" "
                        "key=\"orig\" value=\"1\">-->\n"
-                       "<blockquote type=cite>\n", cancellable, NULL);
+                       "<blockquote type=cite>\n";
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
        }
 
        e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
@@ -131,10 +137,11 @@ mail_formatter_quote_run (EMailFormatter *formatter,
                g_object_unref (g_queue_pop_head (&queue));
 
        if (qf->priv->flags & E_MAIL_FORMATTER_QUOTE_FLAG_CITE) {
-               camel_stream_write_string (
-                       stream, "</blockquote><!--+GtkHTML:"
-                       "<DATA class=\"ClueFlow\" clear=\"orig\">-->",
-                       cancellable, NULL);
+               string = "</blockquote><!--+GtkHTML:"
+                       "<DATA class=\"ClueFlow\" clear=\"orig\">-->";
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
        }
 }
 
diff --git a/em-format/e-mail-formatter-secure-button.c b/em-format/e-mail-formatter-secure-button.c
index ec0e49f..1c09023 100644
--- a/em-format/e-mail-formatter-secure-button.c
+++ b/em-format/e-mail-formatter-secure-button.c
@@ -79,7 +79,7 @@ emfe_secure_button_format (EMailFormatterExtension *extension,
                            EMailFormatter *formatter,
                            EMailFormatterContext *context,
                            EMailPart *part,
-                           CamelStream *stream,
+                           GOutputStream *stream,
                            GCancellable *cancellable)
 {
        gchar *str;
@@ -95,7 +95,8 @@ emfe_secure_button_format (EMailFormatterExtension *extension,
                e_mail_part_get_id (part),
                e_mail_part_get_id (part));
 
-       camel_stream_write_string (stream, str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, str, strlen (str), NULL, cancellable, NULL);
 
        g_free (str);
 
diff --git a/em-format/e-mail-formatter-source.c b/em-format/e-mail-formatter-source.c
index 217e9b3..4c80114 100644
--- a/em-format/e-mail-formatter-source.c
+++ b/em-format/e-mail-formatter-source.c
@@ -46,62 +46,66 @@ emfe_source_format (EMailFormatterExtension *extension,
                     EMailFormatter *formatter,
                     EMailFormatterContext *context,
                     EMailPart *part,
-                    CamelStream *stream,
+                    GOutputStream *stream,
                     GCancellable *cancellable)
 {
        GString *buffer;
-       CamelStream *filtered_stream;
+       GOutputStream *filtered_stream;
        CamelMimeFilter *filter;
        CamelMimePart *mime_part;
 
        mime_part = e_mail_part_ref_mime_part (part);
 
-       filtered_stream = camel_stream_filter_new (stream);
-
-       filter = camel_mime_filter_tohtml_new (
-               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
-               CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
-               CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT, 0);
-       camel_stream_filter_add (
-               CAMEL_STREAM_FILTER (filtered_stream), filter);
-       g_object_unref (filter);
-
        buffer = g_string_new ("");
 
        if (CAMEL_IS_MIME_MESSAGE (mime_part)) {
                g_string_append (
                        buffer,
-                       "<div class=\"part-container -e-mail-formatter-body-color "
-                       "-e-web-view-text-color\" style=\"border: 0;\" >");
+                       "<div class=\"part-container "
+                       "-e-mail-formatter-body-color "
+                       "-e-web-view-text-color\" "
+                       "style=\"border: 0;\" >");
        } else {
                g_string_append (
                        buffer,
-                       "<div class=\"part-container -e-mail-formatter-body-color "
-                       " -e-web-view-text-color -e-mail-formatter-frame-color\">"
+                       "<div class=\"part-container "
+                       "-e-mail-formatter-body-color "
+                       "-e-web-view-text-color "
+                       "-e-mail-formatter-frame-color\">"
                        "<div class=\"part-container-inner-margin pre\">\n");
        }
 
-       camel_stream_write_string (
-               stream, buffer->str, cancellable, NULL);
-       camel_stream_write_string (
-               stream, "<code class=\"pre\">", cancellable, NULL);
+       g_string_append (buffer, "<code class=\"pre\">");
+
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
 
-       camel_data_wrapper_write_to_stream_sync (
+       filter = camel_mime_filter_tohtml_new (
+               CAMEL_MIME_FILTER_TOHTML_CONVERT_NL |
+               CAMEL_MIME_FILTER_TOHTML_CONVERT_SPACES |
+               CAMEL_MIME_FILTER_TOHTML_PRESERVE_8BIT, 0);
+       filtered_stream = camel_filter_output_stream_new (stream, filter);
+       g_object_unref (filter);
+
+       camel_data_wrapper_write_to_output_stream_sync (
                CAMEL_DATA_WRAPPER (mime_part),
                filtered_stream, cancellable, NULL);
-       camel_stream_flush (filtered_stream, cancellable, NULL);
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
+
        g_object_unref (filtered_stream);
 
-       camel_stream_write_string (
-               stream, "</code>", cancellable, NULL);
+       /* Resets the string buffer. */
+       g_string_assign (buffer, "</code>");
 
-       g_string_free (buffer, TRUE);
+       if (CAMEL_IS_MIME_MESSAGE (mime_part))
+               g_string_append (buffer, "</div>");
+       else
+               g_string_append (buffer, "</div></div>");
 
-       if (CAMEL_IS_MIME_MESSAGE (mime_part)) {
-               camel_stream_write_string (stream, "</div>", cancellable, NULL);
-       } else {
-               camel_stream_write_string (stream, "</div></div>", cancellable, NULL);
-       }
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
+
+       g_string_free (buffer, TRUE);
 
        g_object_unref (mime_part);
 
diff --git a/em-format/e-mail-formatter-text-enriched.c b/em-format/e-mail-formatter-text-enriched.c
index 038f445..8e52223 100644
--- a/em-format/e-mail-formatter-text-enriched.c
+++ b/em-format/e-mail-formatter-text-enriched.c
@@ -47,14 +47,14 @@ emfe_text_enriched_format (EMailFormatterExtension *extension,
                            EMailFormatter *formatter,
                            EMailFormatterContext *context,
                            EMailPart *part,
-                           CamelStream *stream,
+                           GOutputStream *stream,
                            GCancellable *cancellable)
 {
-       CamelStream *filtered_stream;
-       CamelMimeFilter *enriched;
+       GOutputStream *filtered_stream;
+       CamelMimeFilter *filter;
        const gchar *mime_type;
+       const gchar *string;
        guint32 filter_flags = 0;
-       GString *buffer;
 
        if (g_cancellable_is_cancelled (cancellable))
                return FALSE;
@@ -64,29 +64,28 @@ emfe_text_enriched_format (EMailFormatterExtension *extension,
        if (g_strcmp0 (mime_type, "text/richtext") == 0)
                filter_flags = CAMEL_MIME_FILTER_ENRICHED_IS_RICHTEXT;
 
-       enriched = camel_mime_filter_enriched_new (filter_flags);
-       filtered_stream = camel_stream_filter_new (stream);
-       camel_stream_filter_add (
-               CAMEL_STREAM_FILTER (filtered_stream), enriched);
-       g_object_unref (enriched);
+       filter = camel_mime_filter_enriched_new (filter_flags);
+       filtered_stream = camel_filter_output_stream_new (stream, filter);
+       g_object_unref (filter);
 
-       buffer = g_string_new ("");
-
-       g_string_append (
-               buffer,
+       string =
                "<div class=\"part-container -e-mail-formatter-frame-color "
                "-e-web-view-background-color -e-web-view-text-color\">"
-               "<div class=\"part-container-inner-margin\">\n");
+               "<div class=\"part-container-inner-margin\">\n";
 
-       camel_stream_write_string (stream, buffer->str, cancellable, NULL);
-       g_string_free (buffer, TRUE);
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        e_mail_formatter_format_text (
                formatter, part, filtered_stream, cancellable);
-       camel_stream_flush (filtered_stream, cancellable, NULL);
+       g_output_stream_flush (filtered_stream, cancellable, NULL);
+
        g_object_unref (filtered_stream);
 
-       camel_stream_write_string (stream, "</div></div>", cancellable, NULL);
+       string = "</div></div>";
+
+       g_output_stream_write_all (
+               stream, string, strlen (string), NULL, cancellable, NULL);
 
        return TRUE;
 }
diff --git a/em-format/e-mail-formatter-text-html.c b/em-format/e-mail-formatter-text-html.c
index 4a464be..b8832d5 100644
--- a/em-format/e-mail-formatter-text-html.c
+++ b/em-format/e-mail-formatter-text-html.c
@@ -132,34 +132,40 @@ emfe_text_html_format (EMailFormatterExtension *extension,
                        EMailFormatter *formatter,
                        EMailFormatterContext *context,
                        EMailPart *part,
-                       CamelStream *stream,
+                       GOutputStream *stream,
                        GCancellable *cancellable)
 {
        if (g_cancellable_is_cancelled (cancellable))
                return FALSE;
 
        if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
-               e_mail_formatter_format_text (formatter, part, stream, cancellable);
+               e_mail_formatter_format_text (
+                       formatter, part, stream, cancellable);
 
        } else if (context->mode == E_MAIL_FORMATTER_MODE_PRINTING) {
+               GOutputStream *decoded_stream;
                GString *string;
-               GByteArray *ba;
                gchar *pos;
                GList *tags, *iter;
                gboolean valid;
                gchar *tag;
                const gchar *document_end;
-               gint length;
+               gpointer data;
+               gsize length;
                gint i;
-               CamelStream *decoded_stream;
 
-               decoded_stream = camel_stream_mem_new ();
+               decoded_stream = g_memory_output_stream_new_resizable ();
+
                /* FORMATTER FIXME: See above */
-               e_mail_formatter_format_text (formatter, part, decoded_stream, cancellable);
-               g_seekable_seek (G_SEEKABLE (decoded_stream), 0, G_SEEK_SET, cancellable, NULL);
+               e_mail_formatter_format_text (
+                       formatter, part, decoded_stream, cancellable);
+
+               data = g_memory_output_stream_get_data (
+                       G_MEMORY_OUTPUT_STREAM (decoded_stream));
+               length = g_memory_output_stream_get_data_size (
+                       G_MEMORY_OUTPUT_STREAM (decoded_stream));
 
-               ba = camel_stream_mem_get_byte_array (CAMEL_STREAM_MEM (decoded_stream));
-               string = g_string_new_len ((gchar *) ba->data, ba->len);
+               string = g_string_new_len ((gchar *) data, length);
 
                g_object_unref (decoded_stream);
 
@@ -225,7 +231,8 @@ emfe_text_html_format (EMailFormatterExtension *extension,
                        };
 
                        emfe_text_html_format (
-                               extension, formatter, &c, part, stream, cancellable);
+                               extension, formatter, &c,
+                               part, stream, cancellable);
                        return FALSE;
                }
 
@@ -288,7 +295,9 @@ emfe_text_html_format (EMailFormatterExtension *extension,
                if (valid)
                        g_string_truncate (string, tag - string->str);
 
-               camel_stream_write_string (stream, string->str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, string->str, string->len,
+                       NULL, cancellable, NULL);
 
                g_string_free (string, TRUE);
        } else {
@@ -333,7 +342,9 @@ emfe_text_html_format (EMailFormatterExtension *extension,
                        e_mail_part_get_id (part),
                        e_mail_part_get_id (part));
 
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str),
+                       NULL, cancellable, NULL);
 
                g_free (str);
                g_free (uri);
diff --git a/em-format/e-mail-formatter-text-plain.c b/em-format/e-mail-formatter-text-plain.c
index 7267bbd..c759a0a 100644
--- a/em-format/e-mail-formatter-text-plain.c
+++ b/em-format/e-mail-formatter-text-plain.c
@@ -50,13 +50,13 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
                         EMailFormatter *formatter,
                         EMailFormatterContext *context,
                         EMailPart *part,
-                        CamelStream *stream,
+                        GOutputStream *stream,
                         GCancellable *cancellable)
 {
-       CamelStream *filtered_stream;
-       CamelMimeFilter *html_filter;
-       gchar *content;
+       GOutputStream *filtered_stream;
+       CamelMimeFilter *filter;
        const gchar *format;
+       const gchar *string;
        guint32 rgb;
 
        if (g_cancellable_is_cancelled (cancellable))
@@ -69,17 +69,18 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
                CamelDataWrapper *dw;
 
                if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
-                       camel_stream_write_string (
-                               stream,
-                               e_mail_formatter_get_sub_html_header (formatter),
-                               cancellable,
-                               NULL);
+                       string = e_mail_formatter_get_sub_html_header (formatter);
+
+                       g_output_stream_write_all (
+                               stream, string, strlen (string),
+                               NULL, cancellable, NULL);
 
                        /* No need for body margins within <iframe> */
-                       camel_stream_write_string (
-                               stream,
-                               "<style>body{ margin: 0; }</style>",
-                               cancellable, NULL);
+                       string = "<style>body{ margin: 0; }</style>";
+
+                       g_output_stream_write_all (
+                               stream, string, strlen (string),
+                               NULL, cancellable, NULL);
                }
 
                flags = e_mail_formatter_get_text_format_flags (formatter);
@@ -101,30 +102,38 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
                        e_mail_formatter_get_color (
                                formatter, E_MAIL_FORMATTER_COLOR_CITATION));
 
-               filtered_stream = camel_stream_filter_new (stream);
-               html_filter = camel_mime_filter_tohtml_new (flags, rgb);
-               camel_stream_filter_add (
-                       CAMEL_STREAM_FILTER (filtered_stream), html_filter);
-               g_object_unref (html_filter);
+               filter = camel_mime_filter_tohtml_new (flags, rgb);
+               filtered_stream =
+                       camel_filter_output_stream_new (stream, filter);
+               g_object_unref (filter);
 
-               content = g_strdup (
+               string =
                        "<div class=\"part-container pre "
                        "-e-web-view-background-color -e-web-view-text-color\" "
-                       "style=\"border: none; padding: 8px; margin: 0;\">");
+                       "style=\"border: none; padding: 8px; margin: 0;\">";
+
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
 
-               camel_stream_write_string (stream, content, cancellable, NULL);
-               e_mail_formatter_format_text (formatter, part, filtered_stream, cancellable);
-               camel_stream_flush (filtered_stream, cancellable, NULL);
+               e_mail_formatter_format_text (
+                       formatter, part, filtered_stream, cancellable);
+               g_output_stream_flush (filtered_stream, cancellable, NULL);
 
                g_object_unref (filtered_stream);
-               g_free (content);
 
-               camel_stream_write_string (stream, "</div>\n", cancellable, NULL);
+               string = "</div>\n";
+
+               g_output_stream_write_all (
+                       stream, string, strlen (string),
+                       NULL, cancellable, NULL);
 
                if (context->mode == E_MAIL_FORMATTER_MODE_RAW) {
-                       camel_stream_write_string (
-                               stream, "</body></html>",
-                               cancellable, NULL);
+                       string = "</body></html>";
+
+                       g_output_stream_write_all (
+                               stream, string, strlen (string),
+                               NULL, cancellable, NULL);
                }
 
                g_object_unref (mime_part);
@@ -169,7 +178,9 @@ emfe_text_plain_format (EMailFormatterExtension *extension,
                        e_mail_part_get_id (part),
                        uri);
 
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str),
+                       NULL, cancellable, NULL);
 
                g_free (str);
                g_free (uri);
diff --git a/em-format/e-mail-formatter.c b/em-format/e-mail-formatter.c
index 0c96942..1feb8e1 100644
--- a/em-format/e-mail-formatter.c
+++ b/em-format/e-mail-formatter.c
@@ -17,6 +17,8 @@
 
 #include "e-mail-formatter.h"
 
+#include <string.h>
+
 #include <gdk/gdk.h>
 #include <libebackend/libebackend.h>
 
@@ -52,7 +54,7 @@ struct _EMailFormatterPrivate {
 };
 
 struct _AsyncContext {
-       CamelStream *stream;
+       GOutputStream *stream;
        EMailPartList *part_list;
        EMailFormatterHeaderFlags flags;
        EMailFormatterMode mode;
@@ -370,15 +372,17 @@ e_mail_formatter_constructed (GObject *object)
 static void
 mail_formatter_run (EMailFormatter *formatter,
                     EMailFormatterContext *context,
-                    CamelStream *stream,
+                    GOutputStream *stream,
                     GCancellable *cancellable)
 {
        GQueue queue = G_QUEUE_INIT;
        GList *head, *link;
        gchar *hdr;
+       const gchar *string;
 
        hdr = e_mail_formatter_get_html_header (formatter);
-       camel_stream_write_string (stream, hdr, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, hdr, strlen (hdr), NULL, cancellable, NULL);
        g_free (hdr);
 
        e_mail_part_list_queue_parts (context->part_list, NULL, &queue);
@@ -472,7 +476,10 @@ mail_formatter_run (EMailFormatter *formatter,
        while (!g_queue_is_empty (&queue))
                g_object_unref (g_queue_pop_head (&queue));
 
-       camel_stream_write_string (stream, "</body></html>", cancellable, NULL);
+       string = "</body></html>";
+       g_output_stream_write_all (
+               stream, string, strlen (string),
+               NULL, cancellable, NULL);
 }
 
 static void
@@ -815,7 +822,7 @@ e_mail_formatter_get_type (void)
 void
 e_mail_formatter_format_sync (EMailFormatter *formatter,
                               EMailPartList *part_list,
-                              CamelStream *stream,
+                              GOutputStream *stream,
                               EMailFormatterHeaderFlags flags,
                               EMailFormatterMode mode,
                               GCancellable *cancellable)
@@ -825,7 +832,7 @@ e_mail_formatter_format_sync (EMailFormatter *formatter,
 
        g_return_if_fail (E_IS_MAIL_FORMATTER (formatter));
        /* EMailPartList can be NULL. */
-       g_return_if_fail (CAMEL_IS_STREAM (stream));
+       g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
 
        class = E_MAIL_FORMATTER_GET_CLASS (formatter);
        g_return_if_fail (class->run != NULL);
@@ -859,7 +866,7 @@ mail_formatter_format_thread (GSimpleAsyncResult *simple,
 void
 e_mail_formatter_format (EMailFormatter *formatter,
                          EMailPartList *part_list,
-                         CamelStream *stream,
+                         GOutputStream *stream,
                          EMailFormatterHeaderFlags flags,
                          EMailFormatterMode mode,
                          GAsyncReadyCallback callback,
@@ -872,7 +879,7 @@ e_mail_formatter_format (EMailFormatter *formatter,
 
        g_return_if_fail (E_IS_MAIL_FORMATTER (formatter));
        /* EMailPartList can be NULL. */
-       g_return_if_fail (CAMEL_IS_STREAM (stream));
+       g_return_if_fail (G_IS_OUTPUT_STREAM (stream));
 
        class = E_MAIL_FORMATTER_GET_CLASS (formatter);
        g_return_if_fail (class->run != NULL);
@@ -927,7 +934,7 @@ e_mail_formatter_format_finish (EMailFormatter *formatter,
  * @formatter: an #EMailFormatter
  * @context: an #EMailFormatterContext
  * @part: an #EMailPart
- * @stream: a #CamelStream
+ * @stream: a #GOutputStream
  * @as_mime_type: (allow-none) mime-type to use for formatting, or %NULL
  * @cancellable: (allow-none) an optional #GCancellable
  *
@@ -942,7 +949,7 @@ gboolean
 e_mail_formatter_format_as (EMailFormatter *formatter,
                             EMailFormatterContext *context,
                             EMailPart *part,
-                            CamelStream *stream,
+                            GOutputStream *stream,
                             const gchar *as_mime_type,
                             GCancellable *cancellable)
 {
@@ -961,7 +968,7 @@ e_mail_formatter_format_as (EMailFormatter *formatter,
 
        g_return_val_if_fail (E_IS_MAIL_FORMATTER (formatter), FALSE);
        g_return_val_if_fail (part != NULL, FALSE);
-       g_return_val_if_fail (CAMEL_IS_STREAM (stream), FALSE);
+       g_return_val_if_fail (G_IS_OUTPUT_STREAM (stream), FALSE);
 
        if (as_mime_type == NULL || *as_mime_type == '\0')
                as_mime_type = e_mail_part_get_mime_type (part);
@@ -1026,14 +1033,12 @@ e_mail_formatter_format_as (EMailFormatter *formatter,
 void
 e_mail_formatter_format_text (EMailFormatter *formatter,
                               EMailPart *part,
-                              CamelStream *stream,
+                              GOutputStream *stream,
                               GCancellable *cancellable)
 {
-       CamelStream *filter_stream;
        CamelMimeFilter *filter;
        const gchar *charset = NULL;
        CamelMimeFilter *windows = NULL;
-       CamelStream *mem_stream = NULL;
        CamelMimePart *mime_part;
        CamelContentType *mime_type;
 
@@ -1048,26 +1053,26 @@ e_mail_formatter_format_text (EMailFormatter *formatter,
        } else if (mime_type != NULL
                   && (charset = camel_content_type_param (mime_type, "charset"))
                   && g_ascii_strncasecmp (charset, "iso-8859-", 9) == 0) {
-               CamelStream *null;
+               GOutputStream *null_stream;
+               GOutputStream *filter_stream;
 
                /* Since a few Windows mailers like to claim they sent
                 * out iso-8859-# encoded text when they really sent
                 * out windows-cp125#, do some simple sanity checking
                 * before we move on... */
 
-               null = camel_stream_null_new ();
-               filter_stream = camel_stream_filter_new (null);
-               g_object_unref (null);
-
+               null_stream = camel_null_output_stream_new ();
                windows = camel_mime_filter_windows_new (charset);
-               camel_stream_filter_add (
-                       CAMEL_STREAM_FILTER (filter_stream), windows);
+               filter_stream = camel_filter_output_stream_new (
+                       null_stream, windows);
 
-               camel_data_wrapper_decode_to_stream_sync (
+               camel_data_wrapper_decode_to_output_stream_sync (
                        CAMEL_DATA_WRAPPER (mime_part),
                        filter_stream, cancellable, NULL);
-               camel_stream_flush (filter_stream, cancellable, NULL);
+               g_output_stream_flush (filter_stream, cancellable, NULL);
+
                g_object_unref (filter_stream);
+               g_object_unref (null_stream);
 
                charset = camel_mime_filter_windows_real_charset (
                        CAMEL_MIME_FILTER_WINDOWS (windows));
@@ -1075,34 +1080,23 @@ e_mail_formatter_format_text (EMailFormatter *formatter,
                charset = formatter->priv->default_charset;
        }
 
-       mem_stream = (CamelStream *) camel_stream_mem_new ();
-       filter_stream = camel_stream_filter_new (mem_stream);
-
        filter = camel_mime_filter_charset_new (charset, "UTF-8");
        if (filter != NULL) {
-               camel_stream_filter_add (
-                       CAMEL_STREAM_FILTER (filter_stream), filter);
+               stream = camel_filter_output_stream_new (stream, filter);
                g_object_unref (filter);
+       } else {
+               g_object_ref (stream);
        }
 
-       camel_data_wrapper_decode_to_stream_sync (
+       camel_data_wrapper_decode_to_output_stream_sync (
                camel_medium_get_content (CAMEL_MEDIUM (mime_part)),
-               filter_stream, cancellable, NULL);
-       camel_stream_flush (filter_stream, cancellable, NULL);
-       g_object_unref (filter_stream);
-
-       g_seekable_seek (G_SEEKABLE (mem_stream), 0, G_SEEK_SET, NULL, NULL);
-
-       camel_stream_write_to_stream (
-               mem_stream, stream, cancellable, NULL);
-       camel_stream_flush (mem_stream, cancellable, NULL);
-
-       if (windows != NULL)
-               g_object_unref (windows);
+               stream, cancellable, NULL);
+       g_output_stream_flush (stream, cancellable, NULL);
 
-       g_object_unref (mem_stream);
+       g_object_unref (stream);
 
-       g_object_unref (mime_part);
+       g_clear_object (&windows);
+       g_clear_object (&mime_part);
 }
 
 const gchar *
diff --git a/em-format/e-mail-formatter.h b/em-format/e-mail-formatter.h
index afb56e2..bbd61f2 100644
--- a/em-format/e-mail-formatter.h
+++ b/em-format/e-mail-formatter.h
@@ -77,7 +77,7 @@ struct _EMailFormatterClass {
 
        void            (*run)                  (EMailFormatter *formatter,
                                                 EMailFormatterContext *context,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 GCancellable *cancellable);
 
        void            (*update_style)         (EMailFormatter *formatter,
@@ -94,14 +94,14 @@ EMailFormatter *
 
 void           e_mail_formatter_format_sync    (EMailFormatter *formatter,
                                                 EMailPartList *part_list,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 EMailFormatterHeaderFlags flags,
                                                 EMailFormatterMode mode,
                                                 GCancellable *cancellable);
 
 void           e_mail_formatter_format         (EMailFormatter *formatter,
                                                 EMailPartList *part_list,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 EMailFormatterHeaderFlags flags,
                                                 EMailFormatterMode mode,
                                                 GAsyncReadyCallback callback,
@@ -115,13 +115,13 @@ gboolean  e_mail_formatter_format_finish  (EMailFormatter *formatter,
 gboolean       e_mail_formatter_format_as      (EMailFormatter *formatter,
                                                 EMailFormatterContext *context,
                                                 EMailPart *part,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 const gchar *as_mime_type,
                                                 GCancellable *cancellable);
 
 void           e_mail_formatter_format_text    (EMailFormatter *formatter,
                                                 EMailPart *part,
-                                                CamelStream *stream,
+                                                GOutputStream *stream,
                                                 GCancellable *cancellable);
 const gchar *  e_mail_formatter_get_sub_html_header
                                                (EMailFormatter *formatter);
diff --git a/em-format/e-mail-part-utils.c b/em-format/e-mail-part-utils.c
index 5b0072e..f3b853d 100644
--- a/em-format/e-mail-part-utils.c
+++ b/em-format/e-mail-part-utils.c
@@ -288,67 +288,76 @@ e_mail_part_get_related_display_part (CamelMimePart *part,
 }
 
 void
-e_mail_part_animation_extract_frame (const GByteArray *anim,
-                                     gchar **frame,
-                                     gsize *len)
+e_mail_part_animation_extract_frame (GBytes *bytes,
+                                     gchar **out_frame,
+                                     gsize *out_len)
 {
        GdkPixbufLoader *loader;
        GdkPixbufAnimation *animation;
        GdkPixbuf *frame_buf;
+       const guchar *bytes_data;
+       gsize bytes_size;
 
-        /* GIF89a (GIF image signature) */
-       const gchar GIF_HEADER[] = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 };
-       const gint   GIF_HEADER_LEN = sizeof (GIF_HEADER);
+       /* GIF89a (GIF image signature) */
+       const guchar GIF_HEADER[] = { 0x47, 0x49, 0x46, 0x38, 0x39, 0x61 };
+       const gint GIF_HEADER_LEN = sizeof (GIF_HEADER);
 
-        /* NETSCAPE2.0 (extension describing animated GIF, starts on 0x310) */
-       const gchar GIF_APPEXT[] = { 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41,
+       /* NETSCAPE2.0 (extension describing animated GIF, starts on 0x310) */
+       const guchar GIF_APPEXT[] = { 0x4E, 0x45, 0x54, 0x53, 0x43, 0x41,
                                     0x50, 0x45, 0x32, 0x2E, 0x30 };
-       const gint   GIF_APPEXT_LEN = sizeof (GIF_APPEXT);
+       const gint GIF_APPEXT_LEN = sizeof (GIF_APPEXT);
 
-       if ((anim == NULL) || (anim->data == NULL)) {
-               *frame = NULL;
-               *len = 0;
+       g_return_if_fail (out_frame != NULL);
+       g_return_if_fail (out_len != NULL);
+
+       *out_frame = NULL;
+       *out_len = 0;
+
+       if (bytes == NULL)
                return;
-       }
 
-        /* Check if the image is an animated GIF. We don't care about any
-         * other animated formats (APNG or MNG) as WebKit does not support them
-         * and displays only the first frame. */
-       if ((anim->len < 0x331)
-           || (memcmp (anim->data, GIF_HEADER, GIF_HEADER_LEN) != 0)
-           || (memcmp (&anim->data[0x310], GIF_APPEXT, GIF_APPEXT_LEN) != 0)) {
+       bytes_data = g_bytes_get_data (bytes, &bytes_size);
 
-                *frame = g_memdup (anim->data, anim->len);
-                *len = anim->len;
+       if (bytes_size == 0)
+               return;
+
+       /* Check if the image is an animated GIF. We don't care about any
+        * other animated formats (APNG or MNG) as WebKit does not support them
+        * and displays only the first frame. */
+       if ((bytes_size < 0x331)
+           || (memcmp (bytes_data, GIF_HEADER, GIF_HEADER_LEN) != 0)
+           || (memcmp (&bytes_data[0x310], GIF_APPEXT, GIF_APPEXT_LEN) != 0)) {
+               *out_frame = g_memdup (bytes_data, bytes_size);
+               *out_len = bytes_size;
                return;
        }
 
        loader = gdk_pixbuf_loader_new ();
-       gdk_pixbuf_loader_write (loader, (guchar *) anim->data, anim->len, NULL);
+       gdk_pixbuf_loader_write (loader, bytes_data, bytes_size, NULL);
        gdk_pixbuf_loader_close (loader, NULL);
        animation = gdk_pixbuf_loader_get_animation (loader);
        if (!animation) {
-
-                *frame = g_memdup (anim->data, anim->len);
-                *len = anim->len;
+               *out_frame = g_memdup (bytes_data, bytes_size);
+               *out_len = bytes_size;
                g_object_unref (loader);
                return;
        }
 
-        /* Extract first frame */
+       /* Extract first frame */
        frame_buf = gdk_pixbuf_animation_get_static_image (animation);
        if (!frame_buf) {
-                *frame = g_memdup (anim->data, anim->len);
-                *len = anim->len;
+               *out_frame = g_memdup (bytes_data, bytes_size);
+               *out_len = bytes_size;
                g_object_unref (loader);
                g_object_unref (animation);
                return;
        }
 
-        /* Unforunatelly, GdkPixbuf cannot save to GIF, but WebKit does not
-         * have any trouble displaying PNG image despite the part having
-         * image/gif mime-type */
-       gdk_pixbuf_save_to_buffer (frame_buf, frame, len, "png", NULL, NULL);
+       /* Unforunately, GdkPixbuf cannot save to GIF, but WebKit does not
+        * have any trouble displaying PNG image despite the part having
+        * image/gif mime-type */
+       gdk_pixbuf_save_to_buffer (
+               frame_buf, out_frame, out_len, "png", NULL, NULL);
 
        g_object_unref (loader);
 }
diff --git a/em-format/e-mail-part-utils.h b/em-format/e-mail-part-utils.h
index 6b1ebe2..ef8b36e 100644
--- a/em-format/e-mail-part-utils.h
+++ b/em-format/e-mail-part-utils.h
@@ -37,9 +37,9 @@ CamelMimePart *       e_mail_part_get_related_display_part
                                                 gint *out_displayid);
 
 void           e_mail_part_animation_extract_frame (
-                                               const GByteArray *anim,
-                                               gchar **frame,
-                                               gsize *len);
+                                               GBytes *bytes,
+                                               gchar **out_frame,
+                                               gsize *out_len);
 
 gchar *                e_mail_part_build_uri           (CamelFolder *folder,
                                                 const gchar *message_uid,
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index eb1a32b..8c1bbc1 100644
--- a/mail/e-mail-request.c
+++ b/mail/e-mail-request.c
@@ -65,12 +65,11 @@ handle_mail_request (GSimpleAsyncResult *simple,
                      GCancellable *cancellable)
 {
        EMailRequest *request = E_MAIL_REQUEST (object);
-       GInputStream *stream;
        EMailFormatter *formatter;
        EMailPartList *part_list;
        CamelObjectBag *registry;
-       CamelStream *output_stream;
-       GByteArray *byte_array;
+       GInputStream *input_stream;
+       GOutputStream *output_stream;
        const gchar *val;
        const gchar *default_charset, *charset;
 
@@ -122,12 +121,7 @@ handle_mail_request (GSimpleAsyncResult *simple,
        if (charset != NULL && *charset != '\0')
                e_mail_formatter_set_charset (formatter, charset);
 
-       byte_array = g_byte_array_new ();
-       output_stream = camel_stream_mem_new ();
-
-       /* We retain ownership of the byte array. */
-       camel_stream_mem_set_byte_array (
-               CAMEL_STREAM_MEM (output_stream), byte_array);
+       output_stream = g_memory_output_stream_new_resizable ();
 
        val = g_hash_table_lookup (request->priv->uri_query, "part_id");
        if (val != NULL) {
@@ -162,7 +156,7 @@ handle_mail_request (GSimpleAsyncResult *simple,
                        dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
                        g_return_if_fail (dw);
 
-                       camel_data_wrapper_decode_to_stream_sync (
+                       camel_data_wrapper_decode_to_output_stream_sync (
                                dw, output_stream, cancellable, NULL);
 
                        g_object_unref (mime_part);
@@ -185,31 +179,39 @@ handle_mail_request (GSimpleAsyncResult *simple,
        }
 
  no_part:
-       g_clear_object (&output_stream);
        g_clear_object (&context.part_list);
 
-       if (byte_array->data == NULL) {
+       g_output_stream_close (output_stream, NULL, NULL);
+
+       if (request->priv->bytes != NULL)
+               g_bytes_unref (request->priv->bytes);
+
+       request->priv->bytes = g_memory_output_stream_steal_as_bytes (
+               G_MEMORY_OUTPUT_STREAM (output_stream));
+
+       if (g_bytes_get_size (request->priv->bytes) == 0) {
                gchar *data;
 
+               g_bytes_unref (request->priv->bytes);
+
                data = g_strdup_printf (
                        "<p align='center'>%s</p>",
                        _("The message has no text content."));
-               g_byte_array_append (
-                       byte_array, (guint8 *) data, strlen (data));
-               g_free (data);
-       }
 
-       if (request->priv->bytes != NULL)
-               g_bytes_unref (request->priv->bytes);
-       request->priv->bytes = g_byte_array_free_to_bytes (byte_array);
+               /* Takes ownership of the string. */
+               request->priv->bytes = g_bytes_new_take (
+                       data, strlen (data) + 1);
+       }
 
-       stream = g_memory_input_stream_new_from_bytes (request->priv->bytes);
+       input_stream =
+               g_memory_input_stream_new_from_bytes (request->priv->bytes);
 
        g_simple_async_result_set_op_res_gpointer (
-               simple, g_object_ref (stream),
+               simple, g_object_ref (input_stream),
                (GDestroyNotify) g_object_unref);
 
-       g_object_unref (stream);
+       g_object_unref (input_stream);
+       g_object_unref (output_stream);
 
        g_object_unref (part_list);
        g_object_unref (formatter);
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 5a938ab..2291e08 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -1196,23 +1196,21 @@ em_utils_message_to_html (CamelSession *session,
 {
        EMailFormatter *formatter;
        EMailParser *parser = NULL;
-       CamelStream *mem;
-       GByteArray *buf;
+       GOutputStream *stream;
        EShell *shell;
        GtkWindow *window;
        EMailPart *hidden_text_html_part = NULL;
        EMailPartValidityFlags is_validity_found = 0;
        GQueue queue = G_QUEUE_INIT;
        GList *head, *link;
+       gchar *data;
 
        shell = e_shell_get_default ();
        window = e_shell_get_active_window (shell);
 
        g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL);
 
-       buf = g_byte_array_new ();
-       mem = camel_stream_mem_new ();
-       camel_stream_mem_set_byte_array (CAMEL_STREAM_MEM (mem), buf);
+       stream = g_memory_output_stream_new_resizable ();
 
        formatter = e_mail_formatter_quote_new (credits, flags);
        e_mail_formatter_update_style (formatter,
@@ -1268,7 +1266,7 @@ em_utils_message_to_html (CamelSession *session,
                *validity_found = is_validity_found;
 
        e_mail_formatter_format_sync (
-               formatter, parts_list, mem, 0,
+               formatter, parts_list, stream, 0,
                E_MAIL_FORMATTER_MODE_PRINTING, NULL);
        g_object_unref (formatter);
 
@@ -1280,12 +1278,19 @@ em_utils_message_to_html (CamelSession *session,
                g_object_unref (parser);
 
        if (append != NULL && *append != '\0')
-               camel_stream_write_string (mem, append, NULL, NULL);
+               g_output_stream_write_all (
+                       stream, append, strlen (append), NULL, NULL, NULL);
 
-       camel_stream_write (mem, "", 1, NULL, NULL);
-       g_object_unref (mem);
+       g_output_stream_write (stream, "", 1, NULL, NULL);
 
-       return (gchar *) g_byte_array_free (buf, FALSE);
+       g_output_stream_close (stream, NULL, NULL);
+
+       data = g_memory_output_stream_steal_data (
+               G_MEMORY_OUTPUT_STREAM (stream));
+
+       g_object_unref (stream);
+
+       return data;
 }
 
 /* ********************************************************************** */
diff --git a/modules/itip-formatter/e-mail-formatter-itip.c b/modules/itip-formatter/e-mail-formatter-itip.c
index 9b51596..1439cf1 100644
--- a/modules/itip-formatter/e-mail-formatter-itip.c
+++ b/modules/itip-formatter/e-mail-formatter-itip.c
@@ -55,7 +55,7 @@ emfe_itip_format (EMailFormatterExtension *extension,
                   EMailFormatter *formatter,
                   EMailFormatterContext *context,
                   EMailPart *part,
-                  CamelStream *stream,
+                  GOutputStream *stream,
                   GCancellable *cancellable)
 {
        GString *buffer;
@@ -135,7 +135,8 @@ emfe_itip_format (EMailFormatterExtension *extension,
                g_free (uri);
        }
 
-       camel_stream_write_string (stream, buffer->str, cancellable, NULL);
+       g_output_stream_write_all (
+               stream, buffer->str, buffer->len, NULL, cancellable, NULL);
 
        g_string_free (buffer, TRUE);
 
diff --git a/modules/text-highlight/e-mail-formatter-text-highlight.c 
b/modules/text-highlight/e-mail-formatter-text-highlight.c
index cbf56ad..4f171ee 100644
--- a/modules/text-highlight/e-mail-formatter-text-highlight.c
+++ b/modules/text-highlight/e-mail-formatter-text-highlight.c
@@ -148,7 +148,7 @@ text_highlight_output_spliced (GObject *source_object,
 }
 
 static gboolean
-text_highlight_feed_data (CamelStream *stream,
+text_highlight_feed_data (GOutputStream *output_stream,
                           CamelDataWrapper *data_wrapper,
                           gint pipe_stdin,
                           gint pipe_stdout,
@@ -157,13 +157,12 @@ text_highlight_feed_data (CamelStream *stream,
 {
        TextHighlightClosure closure;
        GInputStream *input_stream = NULL;
-       GOutputStream *output_stream = NULL;
+       GOutputStream *temp_stream = NULL;
        GInputStream *stdout_stream = NULL;
        GOutputStream *stdin_stream = NULL;
        GMainContext *main_context;
        gchar *utf8_data;
        gconstpointer data;
-       gssize bytes_written;
        gsize size;
        gboolean success;
 
@@ -173,10 +172,10 @@ text_highlight_feed_data (CamelStream *stream,
 
        /* FIXME Use GSubprocess once we can require GLib 2.40. */
 
-       output_stream = g_memory_output_stream_new_resizable ();
+       temp_stream = g_memory_output_stream_new_resizable ();
 
        success = camel_data_wrapper_decode_to_output_stream_sync (
-               data_wrapper, output_stream, cancellable, error);
+               data_wrapper, temp_stream, cancellable, error);
 
        if (!success)
                goto exit;
@@ -190,23 +189,21 @@ text_highlight_feed_data (CamelStream *stream,
        g_main_context_push_thread_default (main_context);
 
        data = g_memory_output_stream_get_data (
-               G_MEMORY_OUTPUT_STREAM (output_stream));
+               G_MEMORY_OUTPUT_STREAM (temp_stream));
        size = g_memory_output_stream_get_data_size (
-               G_MEMORY_OUTPUT_STREAM (output_stream));
+               G_MEMORY_OUTPUT_STREAM (temp_stream));
 
        /* FIXME Write a GConverter that does this so we can decode
         *       straight to the stdin pipe and skip all this extra
         *       buffering. */
        utf8_data = e_util_utf8_data_make_valid ((gchar *) data, size);
 
-       g_clear_object (&output_stream);
+       g_clear_object (&temp_stream);
 
        /* Takes ownership of the UTF-8 string. */
        input_stream = g_memory_input_stream_new_from_data (
                utf8_data, -1, (GDestroyNotify) g_free);
 
-       output_stream = g_memory_output_stream_new_resizable ();
-
        stdin_stream = g_unix_output_stream_new (pipe_stdin, TRUE);
        stdout_stream = g_unix_input_stream_new (pipe_stdout, TRUE);
 
@@ -255,17 +252,8 @@ text_highlight_feed_data (CamelStream *stream,
                goto exit;
        }
 
-       data = g_memory_output_stream_get_data (
-               G_MEMORY_OUTPUT_STREAM (output_stream));
-       size = g_memory_output_stream_get_data_size (
-               G_MEMORY_OUTPUT_STREAM (output_stream));
-
-       bytes_written = camel_stream_write (
-               stream, data, size, cancellable, error);
-       success = (bytes_written >= 0);
-
 exit:
-       g_clear_object (&output_stream);
+       g_clear_object (&temp_stream);
 
        return success;
 }
@@ -275,7 +263,7 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                             EMailFormatter *formatter,
                             EMailFormatterContext *context,
                             EMailPart *part,
-                            CamelStream *stream,
+                            GOutputStream *stream,
                             GCancellable *cancellable)
 {
        CamelMimePart *mime_part;
@@ -471,7 +459,9 @@ emfe_text_highlight_format (EMailFormatterExtension *extension,
                        e_mail_part_get_id (part),
                        uri);
 
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str),
+                       NULL, cancellable, NULL);
 
                g_free (str);
                g_free (uri);
diff --git a/modules/vcard-inline/e-mail-formatter-vcard.c b/modules/vcard-inline/e-mail-formatter-vcard.c
index 773bf68..f13d677 100644
--- a/modules/vcard-inline/e-mail-formatter-vcard.c
+++ b/modules/vcard-inline/e-mail-formatter-vcard.c
@@ -60,7 +60,7 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                              EMailFormatter *formatter,
                              EMailFormatterContext *context,
                              EMailPart *part,
-                             CamelStream *stream,
+                             GOutputStream *stream,
                              GCancellable *cancellable)
 {
        EMailPartVCard *vcard_part;
@@ -80,8 +80,10 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
 
                eab_contact_formatter_format_contact (
                        vcard_part->formatter, contact, buffer);
-               camel_stream_write_string (
-                       stream, buffer->str, cancellable, NULL);
+
+               g_output_stream_write_all (
+                       stream, buffer->str, buffer->len,
+                       NULL, cancellable, NULL);
 
                g_string_free (buffer, TRUE);
 
@@ -94,7 +96,8 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                const gchar *label = NULL;
                EABContactDisplayMode mode;
                const gchar *info = NULL;
-               gchar *html_label, *access_key;
+               gchar *access_key = NULL;
+               gchar *html_label;
 
                length = g_slist_length (vcard_part->contact_list);
 
@@ -134,11 +137,12 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                str = g_strdup_printf (
                        "<div id=\"%s\">",
                        e_mail_part_get_id (part));
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str), NULL, cancellable, NULL);
                g_free (str);
 
                html_label = e_mail_formatter_parse_html_mnemonics (
-                               label, &access_key);
+                       label, &access_key);
                str = g_strdup_printf (
                        "<button type=\"button\" "
                                "name=\"set-display-mode\" "
@@ -146,11 +150,13 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                                "value=\"%d\" "
                                "accesskey=\"%s\">%s</button>",
                        mode, access_key, html_label);
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str), NULL, cancellable, NULL);
                g_free (str);
                g_free (html_label);
-               if (access_key)
-                       g_free (access_key);
+
+               g_free (access_key);
+               access_key = NULL;
 
                html_label = e_mail_formatter_parse_html_mnemonics (
                                _("Save _To Addressbook"), &access_key);
@@ -166,18 +172,18 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                        e_mail_part_get_id (part),
                        access_key, html_label, uri,
                        e_mail_part_get_id (part));
-               camel_stream_write_string (stream, str, cancellable, NULL);
+               g_output_stream_write_all (
+                       stream, str, strlen (str), NULL, cancellable, NULL);
                g_free (str);
                g_free (html_label);
-               if (access_key)
-                       g_free (access_key);
 
-               if (length == 2) {
+               g_free (access_key);
+               access_key = NULL;
 
+               if (length == 2) {
                        info = _("There is one other contact.");
 
                } else if (length > 2) {
-
                        /* Translators: This will always be two or more. */
                        info = g_strdup_printf (ngettext (
                                "There is %d other contact.",
@@ -186,12 +192,13 @@ mail_formatter_vcard_format (EMailFormatterExtension *extension,
                }
 
                if (info) {
-
                        str = g_strdup_printf (
                                "<div class=\"attachment-info\">%s</div>",
                                info);
 
-                       camel_stream_write_string (stream, str, cancellable, NULL);
+                       g_output_stream_write_all (
+                               stream, str, strlen (str),
+                               NULL, cancellable, NULL);
 
                        g_free (str);
                }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]