[evolution/wip/camel-more-gobject] Seal CamelStream (and its descendants) properties



commit 3355a6cee2a1f6decc76e960b76f843a2c307f31
Author: Milan Crha <mcrha redhat com>
Date:   Thu Nov 3 15:28:58 2016 +0100

    Seal CamelStream (and its descendants) properties

 src/e-util/e-attachment.c                          |    9 ++-----
 .../e-mail-parser-multipart-alternative.c          |    7 +-----
 src/libemail-engine/e-mail-session-utils.c         |   21 +------------------
 src/libemail-engine/mail-ops.c                     |   18 +----------------
 4 files changed, 7 insertions(+), 48 deletions(-)
---
diff --git a/src/e-util/e-attachment.c b/src/e-util/e-attachment.c
index 2c3ec5b..a45302d 100644
--- a/src/e-util/e-attachment.c
+++ b/src/e-util/e-attachment.c
@@ -2168,7 +2168,7 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
        const gchar *attribute;
        const gchar *string;
        gchar *allocated, *decoded_string = NULL;
-       CamelStream *null;
+       gsize bytes_written;
        CamelDataWrapper *dw;
 
        load_context = g_object_get_data (
@@ -2267,12 +2267,9 @@ attachment_load_from_mime_part_thread (GSimpleAsyncResult *simple,
                        file_info, attribute, string);
 
        dw = camel_medium_get_content (CAMEL_MEDIUM (mime_part));
-       null = camel_stream_null_new ();
        /* this actually downloads the part and makes it available later */
-       camel_data_wrapper_decode_to_stream_sync (
-               dw, null, attachment->priv->cancellable, NULL);
-       g_file_info_set_size (file_info, CAMEL_STREAM_NULL (null)->written);
-       g_object_unref (null);
+       bytes_written = camel_data_wrapper_calculate_decoded_size_sync (dw, attachment->priv->cancellable, 
NULL);
+       g_file_info_set_size (file_info, bytes_written);
 
        load_context->mime_part = g_object_ref (mime_part);
 
diff --git a/src/em-format/e-mail-parser-multipart-alternative.c 
b/src/em-format/e-mail-parser-multipart-alternative.c
index 5853b12..e777588 100644
--- a/src/em-format/e-mail-parser-multipart-alternative.c
+++ b/src/em-format/e-mail-parser-multipart-alternative.c
@@ -77,7 +77,6 @@ empe_mp_alternative_parse (EMailParserExtension *extension,
                CamelMimePart *mpart;
                CamelDataWrapper *data_wrapper;
                CamelContentType *type;
-               CamelStream *null_stream;
                gchar *mime_type;
                gsize content_size;
 
@@ -93,12 +92,8 @@ empe_mp_alternative_parse (EMailParserExtension *extension,
                /* This may block even though the stream does not.
                 * XXX Pretty inefficient way to test if the MIME part
                 *     is empty.  Surely there's a quicker way? */
-               null_stream = camel_stream_null_new ();
                data_wrapper = camel_medium_get_content (CAMEL_MEDIUM (mpart));
-               camel_data_wrapper_decode_to_stream_sync (
-                       data_wrapper, null_stream, cancellable, NULL);
-               content_size = CAMEL_STREAM_NULL (null_stream)->written;
-               g_object_unref (null_stream);
+               content_size = camel_data_wrapper_calculate_decoded_size_sync (data_wrapper, cancellable, 
NULL);
 
                if (content_size == 0)
                        continue;
diff --git a/src/libemail-engine/e-mail-session-utils.c b/src/libemail-engine/e-mail-session-utils.c
index 5dadf09..71b72cb 100644
--- a/src/libemail-engine/e-mail-session-utils.c
+++ b/src/libemail-engine/e-mail-session-utils.c
@@ -785,22 +785,6 @@ exit:
        g_string_free (error_messages, TRUE);
 }
 
-static guint32
-get_message_size (CamelMimeMessage *message,
-                  GCancellable *cancellable)
-{
-       CamelStream *null;
-       guint32 size;
-
-       null = camel_stream_null_new ();
-       camel_data_wrapper_write_to_stream_sync (
-               CAMEL_DATA_WRAPPER (message), null, cancellable, NULL);
-       size = CAMEL_STREAM_NULL (null)->written;
-       g_object_unref (null);
-
-       return size;
-}
-
 void
 e_mail_session_send_to (EMailSession *session,
                         CamelMimeMessage *message,
@@ -896,9 +880,8 @@ e_mail_session_send_to (EMailSession *session,
 
        /* Miscellaneous preparations. */
 
-       info = camel_message_info_new_from_header (
-               NULL, CAMEL_MIME_PART (message)->headers);
-       camel_message_info_set_size (info, get_message_size (message, cancellable));
+       info = camel_message_info_new_from_header (NULL, CAMEL_MIME_PART (message)->headers);
+       camel_message_info_set_size (info, camel_data_wrapper_calculate_size_sync (CAMEL_DATA_WRAPPER 
(message), cancellable, NULL));
        camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN |
                (camel_mime_message_has_attachment (message) ? CAMEL_MESSAGE_ATTACHMENTS : 0), ~0);
 
diff --git a/src/libemail-engine/mail-ops.c b/src/libemail-engine/mail-ops.c
index ef1bd11..e690bc3 100644
--- a/src/libemail-engine/mail-ops.c
+++ b/src/libemail-engine/mail-ops.c
@@ -568,22 +568,6 @@ static void        report_status           (struct _send_queue_msg *m,
                                         const gchar *desc,
                                         ...);
 
-static guint32
-get_message_size (CamelMimeMessage *message,
-                  GCancellable *cancellable)
-{
-       CamelStream *null;
-       guint32 size;
-
-       null = camel_stream_null_new ();
-       camel_data_wrapper_write_to_stream_sync (
-               CAMEL_DATA_WRAPPER (message), null, cancellable, NULL);
-       size = CAMEL_STREAM_NULL (null)->written;
-       g_object_unref (null);
-
-       return size;
-}
-
 /* send 1 message to a specific transport */
 static void
 mail_send_message (struct _send_queue_msg *m,
@@ -701,7 +685,7 @@ mail_send_message (struct _send_queue_msg *m,
 
        /* Now check for posting, failures are ignored */
        info = camel_message_info_new (NULL);
-       camel_message_info_set_size (info, get_message_size (message, cancellable));
+       camel_message_info_set_size (info, camel_data_wrapper_calculate_size_sync (CAMEL_DATA_WRAPPER 
(message), cancellable, NULL));
        camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN |
                (camel_mime_message_has_attachment (message) ? CAMEL_MESSAGE_ATTACHMENTS : 0), ~0);
 


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