From f4bb7d7748f3c407858e9c844d365411c586d861 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Tue, 25 Feb 2014 10:23:11 -0500 Subject: 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 0ac90e67f5..dddd59a89c 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 9c3ab49b4d..f32cf80a3c 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 fd098d78bb..ea0bcd70f1 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, "
" "" "" @@ -268,16 +274,15 @@ emfe_attachment_format (EMailFormatterExtension *extension, "" "", 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, "", cancellable, NULL); + g_string_append (buffer, ""); g_free (wrapper_element_id); - g_free (str); } g_object_unref (content_stream); } - camel_stream_write_string (stream, "
%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, "
", cancellable, NULL); + g_string_append (buffer, ""); + + 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 228f238a1c..cf980f8e78 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 ( "", - 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 ( "