aboutsummaryrefslogtreecommitdiffstats
path: root/mail/e-mail-request.c
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2014-02-25 23:23:11 +0800
committerMatthew Barnes <mbarnes@redhat.com>2014-03-01 03:38:11 +0800
commitf4bb7d7748f3c407858e9c844d365411c586d861 (patch)
tree5946af137b2439857433fd9729ba758e9cd3c05d /mail/e-mail-request.c
parentc3f8c95322ca7e461444820c7469d5527c239b05 (diff)
downloadgsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar.gz
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar.bz2
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar.lz
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar.xz
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.tar.zst
gsoc2013-evolution-f4bb7d7748f3c407858e9c844d365411c586d861.zip
EMailFormatter: Use GOutputStream instead of CamelStream.
Diffstat (limited to 'mail/e-mail-request.c')
-rw-r--r--mail/e-mail-request.c46
1 files changed, 24 insertions, 22 deletions
diff --git a/mail/e-mail-request.c b/mail/e-mail-request.c
index eb1a32b02c..8c1bbc19bb 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);