[evolution-data-server/wip/camel-more-gobject] Seal CamelDataWrapper properties



commit 0664e5cd9d392113c449e0d7c981b4aa6de69658
Author: Milan Crha <mcrha redhat com>
Date:   Wed Nov 2 19:38:09 2016 +0100

    Seal CamelDataWrapper properties

 src/camel/camel-data-wrapper.c    |  135 ++++++++++++++++++++++++++++++-------
 src/camel/camel-data-wrapper.h    |   15 +++--
 src/camel/camel-folder-search.c   |    4 +-
 src/camel/camel-folder-summary.c  |    2 +-
 src/camel/camel-gpg-context.c     |    2 +-
 src/camel/camel-mime-message.c    |   20 +++---
 src/camel/camel-mime-part-utils.c |    2 +-
 src/camel/camel-mime-part.c       |   46 +++++-------
 src/camel/camel-multipart.c       |    8 +-
 src/camel/camel-search-private.c  |    6 +-
 src/camel/camel-smime-context.c   |    6 +-
 11 files changed, 163 insertions(+), 83 deletions(-)
---
diff --git a/src/camel/camel-data-wrapper.c b/src/camel/camel-data-wrapper.c
index 1da5026..b00bcf4 100644
--- a/src/camel/camel-data-wrapper.c
+++ b/src/camel/camel-data-wrapper.c
@@ -41,6 +41,12 @@ typedef struct _AsyncContext AsyncContext;
 struct _CamelDataWrapperPrivate {
        GMutex stream_lock;
        GByteArray *byte_array;
+
+       CamelTransferEncoding encoding;
+
+       CamelContentType *mime_type;
+
+       guint offline : 1;
 };
 
 struct _AsyncContext {
@@ -66,9 +72,9 @@ data_wrapper_dispose (GObject *object)
 {
        CamelDataWrapper *data_wrapper = CAMEL_DATA_WRAPPER (object);
 
-       if (data_wrapper->mime_type != NULL) {
-               camel_content_type_unref (data_wrapper->mime_type);
-               data_wrapper->mime_type = NULL;
+       if (data_wrapper->priv->mime_type != NULL) {
+               camel_content_type_unref (data_wrapper->priv->mime_type);
+               data_wrapper->priv->mime_type = NULL;
        }
 
        /* Chain up to parent's dispose() method. */
@@ -93,21 +99,21 @@ static void
 data_wrapper_set_mime_type (CamelDataWrapper *data_wrapper,
                             const gchar *mime_type)
 {
-       if (data_wrapper->mime_type)
-               camel_content_type_unref (data_wrapper->mime_type);
-       data_wrapper->mime_type = camel_content_type_decode (mime_type);
+       if (data_wrapper->priv->mime_type)
+               camel_content_type_unref (data_wrapper->priv->mime_type);
+       data_wrapper->priv->mime_type = camel_content_type_decode (mime_type);
 }
 
 static gchar *
 data_wrapper_get_mime_type (CamelDataWrapper *data_wrapper)
 {
-       return camel_content_type_simple (data_wrapper->mime_type);
+       return camel_content_type_simple (data_wrapper->priv->mime_type);
 }
 
 static CamelContentType *
 data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
 {
-       return data_wrapper->mime_type;
+       return data_wrapper->priv->mime_type;
 }
 
 static void
@@ -116,15 +122,15 @@ data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
 {
        if (mime_type)
                camel_content_type_ref (mime_type);
-       if (data_wrapper->mime_type)
-               camel_content_type_unref (data_wrapper->mime_type);
-       data_wrapper->mime_type = mime_type;
+       if (data_wrapper->priv->mime_type)
+               camel_content_type_unref (data_wrapper->priv->mime_type);
+       data_wrapper->priv->mime_type = mime_type;
 }
 
 static gboolean
 data_wrapper_is_offline (CamelDataWrapper *data_wrapper)
 {
-       return data_wrapper->offline;
+       return data_wrapper->priv->offline;
 }
 
 static gssize
@@ -173,7 +179,7 @@ data_wrapper_decode_to_stream_sync (CamelDataWrapper *data_wrapper,
 
        fstream = camel_stream_filter_new (stream);
 
-       switch (data_wrapper->encoding) {
+       switch (data_wrapper->priv->encoding) {
        case CAMEL_TRANSFER_ENCODING_BASE64:
                filter = camel_mime_filter_basic_new (CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
                camel_stream_filter_add (CAMEL_STREAM_FILTER (fstream), filter);
@@ -290,7 +296,7 @@ data_wrapper_decode_to_output_stream_sync (CamelDataWrapper *data_wrapper,
        gboolean content_type_is_text;
        gssize bytes_written;
 
-       switch (data_wrapper->encoding) {
+       switch (data_wrapper->priv->encoding) {
                case CAMEL_TRANSFER_ENCODING_BASE64:
                        filter = camel_mime_filter_basic_new (
                                CAMEL_MIME_FILTER_BASIC_BASE64_DEC);
@@ -325,10 +331,8 @@ data_wrapper_decode_to_output_stream_sync (CamelDataWrapper *data_wrapper,
        }
 
        content_type_is_text =
-               camel_content_type_is (
-               data_wrapper->mime_type, "text", "*") &&
-               !camel_content_type_is (
-               data_wrapper->mime_type, "text", "pdf");
+               camel_content_type_is (data_wrapper->priv->mime_type, "text", "*") &&
+               !camel_content_type_is (data_wrapper->priv->mime_type, "text", "pdf");
 
        if (content_type_is_text) {
                GOutputStream *temp_stream;
@@ -444,10 +448,9 @@ camel_data_wrapper_init (CamelDataWrapper *data_wrapper)
        g_mutex_init (&data_wrapper->priv->stream_lock);
        data_wrapper->priv->byte_array = g_byte_array_new ();
 
-       data_wrapper->mime_type = camel_content_type_new (
-               "application", "octet-stream");
-       data_wrapper->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
-       data_wrapper->offline = FALSE;
+       data_wrapper->priv->mime_type = camel_content_type_new ("application", "octet-stream");
+       data_wrapper->priv->encoding = CAMEL_TRANSFER_ENCODING_DEFAULT;
+       data_wrapper->priv->offline = FALSE;
 }
 
 /**
@@ -484,6 +487,41 @@ camel_data_wrapper_get_byte_array (CamelDataWrapper *data_wrapper)
 }
 
 /**
+ * camel_data_wrapper_get_encoding:
+ * @data_wrapper: a #CamelDataWrapper
+ *
+ * Returns: An encoding (#CamelTransferEncoding) of the @data_wrapper
+ *
+ * Since: 3.24
+ **/
+CamelTransferEncoding
+camel_data_wrapper_get_encoding (CamelDataWrapper *data_wrapper)
+{
+       g_return_val_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper), CAMEL_TRANSFER_ENCODING_DEFAULT);
+
+       return data_wrapper->priv->encoding;
+}
+
+/**
+ * camel_data_wrapper_set_encoding:
+ * @data_wrapper: a #CamelDataWrapper
+ * @encoding: an encoding to set
+ *
+ * Sets encoding (#CamelTransferEncoding) for the @data_wrapper.
+ * It doesn't re-encode the content, if the encoding changes.
+ *
+ * Since: 3.24
+ **/
+void
+camel_data_wrapper_set_encoding (CamelDataWrapper *data_wrapper,
+                                CamelTransferEncoding encoding)
+{
+       g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+
+       data_wrapper->priv->encoding = encoding;
+}
+
+/**
  * camel_data_wrapper_set_mime_type:
  * @data_wrapper: a #CamelDataWrapper
  * @mime_type: a MIME type
@@ -552,10 +590,12 @@ camel_data_wrapper_get_mime_type_field (CamelDataWrapper *data_wrapper)
 /**
  * camel_data_wrapper_set_mime_type_field:
  * @data_wrapper: a #CamelDataWrapper
- * @mime_type: a #CamelContentType
+ * @mime_type: (nullable): a #CamelContentType
+ *
+ * This sets the data wrapper's MIME type. It adds its own reference
+ * to @mime_type, if not %NULL.
  *
- * This sets the data wrapper's MIME type. It suffers from the same
- * flaws as camel_data_wrapper_set_mime_type().
+ * It suffers from the same flaws as camel_data_wrapper_set_mime_type().
  **/
 void
 camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
@@ -573,6 +613,32 @@ camel_data_wrapper_set_mime_type_field (CamelDataWrapper *data_wrapper,
 }
 
 /**
+ * camel_data_wrapper_take_mime_type_field:
+ * @data_wrapper: a #CamelDataWrapper
+ * @mime_type: (nullable) (transfer full): a #CamelContentType
+ *
+ * Sets mime-type filed to be @mime_type and consumes it, aka unlike
+ * camel_data_wrapper_set_mime_type_field(), this doesn't add its own
+ * reference to @mime_type.
+ *
+ * It suffers from the same flaws as camel_data_wrapper_set_mime_type().
+ *
+ * Since: 3.24
+ **/
+void
+camel_data_wrapper_take_mime_type_field (CamelDataWrapper *data_wrapper,
+                                        CamelContentType *mime_type)
+{
+       g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+       g_return_if_fail (mime_type != NULL);
+
+       camel_data_wrapper_set_mime_type_field (data_wrapper, mime_type);
+
+       if (mime_type)
+               camel_content_type_unref (mime_type);
+}
+
+/**
  * camel_data_wrapper_is_offline:
  * @data_wrapper: a #CamelDataWrapper
  *
@@ -594,6 +660,25 @@ camel_data_wrapper_is_offline (CamelDataWrapper *data_wrapper)
 }
 
 /**
+ * camel_data_wrapper_set_offline:
+ * @data_wrapper: a #CamelDataWrapper
+ * @offline: whether the @data_wrapper is "offline"
+ *
+ * Sets whether the @data_wrapper is "offline". It applies only to this
+ * concrete instance. See camel_data_wrapper_is_offline().
+ *
+ * Since: 3.24
+ **/
+void
+camel_data_wrapper_set_offline (CamelDataWrapper *data_wrapper,
+                               gboolean offline)
+{
+       g_return_if_fail (CAMEL_IS_DATA_WRAPPER (data_wrapper));
+
+       data_wrapper->priv->offline = offline;
+}
+
+/**
  * camel_data_wrapper_write_to_stream_sync:
  * @data_wrapper: a #CamelDataWrapper
  * @stream: a #CamelStream for output
diff --git a/src/camel/camel-data-wrapper.h b/src/camel/camel-data-wrapper.h
index de57dec..69f8dcb 100644
--- a/src/camel/camel-data-wrapper.h
+++ b/src/camel/camel-data-wrapper.h
@@ -59,12 +59,6 @@ typedef struct _CamelDataWrapperPrivate CamelDataWrapperPrivate;
 struct _CamelDataWrapper {
        GObject parent;
        CamelDataWrapperPrivate *priv;
-
-       CamelTransferEncoding encoding;
-
-       CamelContentType *mime_type;
-
-       guint offline : 1;
 };
 
 struct _CamelDataWrapperClass {
@@ -119,6 +113,10 @@ CamelDataWrapper *
                camel_data_wrapper_new          (void);
 GByteArray *   camel_data_wrapper_get_byte_array
                                                (CamelDataWrapper *data_wrapper);
+CamelTransferEncoding
+               camel_data_wrapper_get_encoding (CamelDataWrapper *data_wrapper);
+void           camel_data_wrapper_set_encoding (CamelDataWrapper *data_wrapper,
+                                                CamelTransferEncoding encoding);
 void           camel_data_wrapper_set_mime_type
                                                (CamelDataWrapper *data_wrapper,
                                                 const gchar *mime_type);
@@ -130,7 +128,12 @@ CamelContentType *
 void           camel_data_wrapper_set_mime_type_field
                                                (CamelDataWrapper *data_wrapper,
                                                 CamelContentType *mime_type);
+void           camel_data_wrapper_take_mime_type_field
+                                               (CamelDataWrapper *data_wrapper,
+                                                CamelContentType *mime_type);
 gboolean       camel_data_wrapper_is_offline   (CamelDataWrapper *data_wrapper);
+void           camel_data_wrapper_set_offline  (CamelDataWrapper *data_wrapper,
+                                                gboolean offline);
 
 gssize         camel_data_wrapper_write_to_stream_sync
                                                (CamelDataWrapper *data_wrapper,
diff --git a/src/camel/camel-folder-search.c b/src/camel/camel-folder-search.c
index 16067dd..4e358fe 100644
--- a/src/camel/camel-folder-search.c
+++ b/src/camel/camel-folder-search.c
@@ -527,7 +527,7 @@ match_words_1message (CamelDataWrapper *object,
        } else if (CAMEL_IS_MIME_MESSAGE (containee)) {
                /* for messages we only look at its contents */
                truth = match_words_1message ((CamelDataWrapper *) containee, words, mask, cancellable);
-       } else if (camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")) {
+       } else if (camel_content_type_is (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER 
(containee)), "text", "*")) {
                /* for all other text parts, we look inside, otherwise we dont care */
                CamelStream *stream;
                GByteArray *byte_array;
@@ -536,7 +536,7 @@ match_words_1message (CamelDataWrapper *object,
                byte_array = g_byte_array_new ();
                stream = camel_stream_mem_new_with_byte_array (byte_array);
 
-               charset = camel_content_type_param (CAMEL_DATA_WRAPPER (containee)->mime_type, "charset");
+               charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (containee)), "charset");
                if (charset && *charset) {
                        CamelMimeFilter *filter = camel_mime_filter_charset_new (charset, "UTF-8");
                        if (filter) {
diff --git a/src/camel/camel-folder-summary.c b/src/camel/camel-folder-summary.c
index abe7eef..9c3162b 100644
--- a/src/camel/camel-folder-summary.c
+++ b/src/camel/camel-folder-summary.c
@@ -2972,7 +2972,7 @@ summary_traverse_content_with_part (CamelFolderSummary *summary,
         * add a reference, probably need fixing for multithreading */
 
        /* check for attachments */
-       ct = ((CamelDataWrapper *) containee)->mime_type;
+       ct = camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (containee));
        if (camel_content_type_is (ct, "multipart", "*")) {
                if (camel_content_type_is (ct, "multipart", "mixed"))
                        camel_message_info_set_flags (msginfo, CAMEL_MESSAGE_ATTACHMENTS, 
CAMEL_MESSAGE_ATTACHMENTS);
diff --git a/src/camel/camel-gpg-context.c b/src/camel/camel-gpg-context.c
index b539272..4194637 100644
--- a/src/camel/camel-gpg-context.c
+++ b/src/camel/camel-gpg-context.c
@@ -2082,7 +2082,7 @@ gpg_verify_sync (CamelCipherContext *context,
        class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
 
        mps = (CamelMultipart *) camel_medium_get_content ((CamelMedium *) ipart);
-       ct = ((CamelDataWrapper *) mps)->mime_type;
+       ct = camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (mps));
 
        /* Inline signature (using our fake mime type) or PGP/Mime signature */
        if (camel_content_type_is (ct, "multipart", "signed")) {
diff --git a/src/camel/camel-mime-message.c b/src/camel/camel-mime-message.c
index 2dc1a7e..0f43814 100644
--- a/src/camel/camel-mime-message.c
+++ b/src/camel/camel-mime-message.c
@@ -120,8 +120,8 @@ process_header (CamelMedium *medium,
                break;
        case HEADER_SUBJECT:
                g_free (message->subject);
-               if (((CamelDataWrapper *) message)->mime_type) {
-                       charset = camel_content_type_param (((CamelDataWrapper *) message)->mime_type, 
"charset");
+               if (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (message))) {
+                       charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (message)), "charset");
                        charset = camel_iconv_charset_name (charset);
                } else
                        charset = NULL;
@@ -951,7 +951,7 @@ find_best_encoding (CamelMimePart *part,
                return CAMEL_TRANSFER_ENCODING_DEFAULT;
        }
 
-       istext = camel_content_type_is (((CamelDataWrapper *) part)->mime_type, "text", "*");
+       istext = camel_content_type_is (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (part)), 
"text", "*");
        if (istext) {
                flags = CAMEL_BESTENC_GET_CHARSET | CAMEL_BESTENC_GET_ENCODING;
                enctype |= CAMEL_BESTENC_TEXT;
@@ -971,7 +971,7 @@ find_best_encoding (CamelMimePart *part,
 
        /* if we're looking for the best charset, then we need to convert to UTF-8 */
        if (istext && (required & CAMEL_BESTENC_GET_CHARSET) != 0
-           && (charsetin = camel_content_type_param (content->mime_type, "charset"))) {
+           && (charsetin = camel_content_type_param (camel_data_wrapper_get_mime_type_field (content), 
"charset"))) {
                charenc = camel_mime_filter_charset_new (charsetin, "UTF-8");
                if (charenc != NULL)
                        idc = camel_stream_filter_add (
@@ -997,7 +997,7 @@ find_best_encoding (CamelMimePart *part,
                d (printf ("best charset = %s\n", charsetin ? charsetin : "(null)"));
                charset = g_strdup (charsetin);
 
-               charsetin = camel_content_type_param (content->mime_type, "charset");
+               charsetin = camel_content_type_param (camel_data_wrapper_get_mime_type_field (content), 
"charset");
        } else {
                charset = NULL;
        }
@@ -1081,14 +1081,14 @@ best_encoding (CamelMimeMessage *msg,
                camel_mime_part_set_encoding (part, encoding);
 
                if ((data->required & CAMEL_BESTENC_GET_CHARSET) != 0) {
-                       if (camel_content_type_is (((CamelDataWrapper *) part)->mime_type, "text", "*")) {
+                       if (camel_content_type_is (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER 
(part)), "text", "*")) {
                                gchar *newct;
 
                                /* FIXME: ick, the part content_type interface needs fixing bigtime */
                                camel_content_type_set_param (
-                                       ((CamelDataWrapper *) part)->mime_type, "charset",
+                                       camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (part)), 
"charset",
                                        charset ? charset : "us-ascii");
-                               newct = camel_content_type_format (((CamelDataWrapper *) part)->mime_type);
+                               newct = camel_content_type_format (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (part)));
                                if (newct) {
                                        d (printf ("Setting content-type to %s\n", newct));
 
@@ -1383,7 +1383,7 @@ cmm_dump_rec (CamelMimeMessage *msg,
        s[depth] = 0;
        /* yes this leaks, so what its only debug stuff */
        printf ("%sclass: %s\n", s, G_OBJECT_TYPE_NAME (part));
-       printf ("%smime-type: %s\n", s, camel_content_type_format (((CamelDataWrapper *) part)->mime_type));
+       printf ("%smime-type: %s\n", s, camel_content_type_format (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (part))));
 
        containee = camel_medium_get_content ((CamelMedium *) part);
 
@@ -1391,7 +1391,7 @@ cmm_dump_rec (CamelMimeMessage *msg,
                return;
 
        printf ("%scontent class: %s\n", s, G_OBJECT_TYPE_NAME (containee));
-       printf ("%scontent mime-type: %s\n", s, camel_content_type_format (((CamelDataWrapper *) 
containee)->mime_type));
+       printf ("%scontent mime-type: %s\n", s, camel_content_type_format 
(camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (containee))));
 
        data = camel_data_wrapper_get_byte_array (containee);
        if (body && data) {
diff --git a/src/camel/camel-mime-part-utils.c b/src/camel/camel-mime-part-utils.c
index e27977d..babeee1 100644
--- a/src/camel/camel-mime-part-utils.c
+++ b/src/camel/camel-mime-part-utils.c
@@ -138,7 +138,7 @@ camel_mime_part_construct_content_from_parser (CamelMimePart *dw,
 
        if (content) {
                if (encoding)
-                       content->encoding = camel_transfer_encoding_from_string (encoding);
+                       camel_data_wrapper_set_encoding (content, camel_transfer_encoding_from_string 
(encoding));
 
                /* would you believe you have to set this BEFORE you set the content object???  oh my god 
!!!! */
                camel_data_wrapper_set_mime_type_field (content, camel_mime_part_get_content_type (dw));
diff --git a/src/camel/camel-mime-part.c b/src/camel/camel-mime-part.c
index ffc48e4..f2c92a3 100644
--- a/src/camel/camel-mime-part.c
+++ b/src/camel/camel-mime-part.c
@@ -318,8 +318,8 @@ mime_part_process_header (CamelMedium *medium,
        switch (header_type) {
        case HEADER_DESCRIPTION: /* raw header->utf8 conversion */
                g_free (mime_part->priv->description);
-               if (((CamelDataWrapper *) mime_part)->mime_type) {
-                       charset = camel_content_type_param (((CamelDataWrapper *) mime_part)->mime_type, 
"charset");
+               if (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (mime_part))) {
+                       charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (mime_part)), "charset");
                        charset = camel_iconv_charset_name (charset);
                } else
                        charset = NULL;
@@ -346,9 +346,7 @@ mime_part_process_header (CamelMedium *medium,
                mime_part->priv->content_location = camel_header_location_decode (value);
                break;
        case HEADER_CONTENT_TYPE:
-               if (((CamelDataWrapper *) mime_part)->mime_type)
-                       camel_content_type_unref (((CamelDataWrapper *) mime_part)->mime_type);
-               ((CamelDataWrapper *) mime_part)->mime_type = camel_content_type_decode (value);
+               camel_data_wrapper_take_mime_type_field (CAMEL_DATA_WRAPPER (mime_part), 
camel_content_type_decode (value));
                break;
        default:
                return FALSE;
@@ -542,7 +540,7 @@ mime_part_set_content (CamelMedium *medium,
        medium_class->set_content (medium, content);
 
        content_type = camel_data_wrapper_get_mime_type_field (content);
-       if (mime_part->mime_type != content_type) {
+       if (camel_data_wrapper_get_mime_type_field (mime_part) != content_type) {
                gchar *txt;
 
                txt = camel_content_type_format (content_type);
@@ -620,9 +618,9 @@ mime_part_write_to_stream_sync (CamelDataWrapper *dw,
                gboolean reencode = FALSE;
                const gchar *filename;
 
-               if (camel_content_type_is (dw->mime_type, "text", "*")) {
-                       content_charset = camel_content_type_param (content->mime_type, "charset");
-                       part_charset = camel_content_type_param (dw->mime_type, "charset");
+               if (camel_content_type_is (camel_data_wrapper_get_mime_type_field (dw), "text", "*")) {
+                       content_charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(content), "charset");
+                       part_charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field (dw), 
"charset");
 
                        if (content_charset && part_charset) {
                                content_charset = camel_iconv_charset_name (content_charset);
@@ -630,7 +628,7 @@ mime_part_write_to_stream_sync (CamelDataWrapper *dw,
                        }
                }
 
-               if (mp->priv->encoding != content->encoding) {
+               if (mp->priv->encoding != camel_data_wrapper_get_encoding (content)) {
                        gchar *content;
 
                        switch (mp->priv->encoding) {
@@ -818,11 +816,11 @@ mime_part_write_to_output_stream_sync (CamelDataWrapper *dw,
                const gchar *filename;
 
                content_type_is_text =
-                       camel_content_type_is (dw->mime_type, "text", "*");
+                       camel_content_type_is (camel_data_wrapper_get_mime_type_field (dw), "text", "*");
 
                if (content_type_is_text) {
-                       content_charset = camel_content_type_param (content->mime_type, "charset");
-                       part_charset = camel_content_type_param (dw->mime_type, "charset");
+                       content_charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(content), "charset");
+                       part_charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field (dw), 
"charset");
 
                        if (content_charset && part_charset) {
                                content_charset = camel_iconv_charset_name (content_charset);
@@ -830,7 +828,7 @@ mime_part_write_to_output_stream_sync (CamelDataWrapper *dw,
                        }
                }
 
-               if (mp->priv->encoding != content->encoding) {
+               if (mp->priv->encoding != camel_data_wrapper_get_encoding (content)) {
                        gchar *content;
 
                        switch (mp->priv->encoding) {
@@ -972,9 +970,7 @@ mime_part_construct_from_parser_sync (CamelMimePart *mime_part,
        switch (camel_mime_parser_step (parser, &buf, &len)) {
        case CAMEL_MIME_PARSER_STATE_MESSAGE:
                /* set the default type of a message always */
-               if (dw->mime_type)
-                       camel_content_type_unref (dw->mime_type);
-               dw->mime_type = camel_content_type_decode ("message/rfc822");
+               camel_data_wrapper_take_mime_type_field (dw, camel_content_type_decode ("message/rfc822"));
                /* coverity[fallthrough] */
 
        case CAMEL_MIME_PARSER_STATE_HEADER:
@@ -1099,10 +1095,7 @@ camel_mime_part_init (CamelMimePart *mime_part)
 
        data_wrapper = CAMEL_DATA_WRAPPER (mime_part);
 
-       if (data_wrapper->mime_type != NULL)
-               camel_content_type_unref (data_wrapper->mime_type);
-
-       data_wrapper->mime_type = camel_content_type_new ("text", "plain");
+       camel_data_wrapper_take_mime_type_field (data_wrapper, camel_content_type_new ("text", "plain"));
 }
 
 /**
@@ -1527,8 +1520,7 @@ camel_mime_part_get_filename (CamelMimePart *mime_part)
                        return name;
        }
 
-       return camel_content_type_param (
-               ((CamelDataWrapper *) mime_part)->mime_type, "name");
+       return camel_content_type_param (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER 
(mime_part)), "name");
 }
 
 /**
@@ -1560,10 +1552,10 @@ camel_mime_part_set_filename (CamelMimePart *mime_part,
        g_free (str);
 
        dw = (CamelDataWrapper *) mime_part;
-       if (!dw->mime_type)
-               dw->mime_type = camel_content_type_new ("application", "octet-stream");
-       camel_content_type_set_param (dw->mime_type, "name", filename);
-       str = camel_content_type_format (dw->mime_type);
+       if (!camel_data_wrapper_get_mime_type_field (dw))
+               camel_data_wrapper_take_mime_type_field (dw, camel_content_type_new ("application", 
"octet-stream"));
+       camel_content_type_set_param (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (dw)), 
"name", filename);
+       str = camel_content_type_format (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER (dw)));
        camel_medium_set_header (medium, "Content-Type", str);
        g_free (str);
 }
diff --git a/src/camel/camel-multipart.c b/src/camel/camel-multipart.c
index 0836b5e..ea51717 100644
--- a/src/camel/camel-multipart.c
+++ b/src/camel/camel-multipart.c
@@ -297,7 +297,7 @@ multipart_set_boundary (CamelMultipart *multipart,
        gsize length;
        gint state, save;
 
-       g_return_if_fail (cdw->mime_type != NULL);
+       g_return_if_fail (camel_data_wrapper_get_mime_type_field (cdw) != NULL);
 
        length = g_checksum_type_get_length (G_CHECKSUM_MD5);
        digest = g_alloca (length);
@@ -328,7 +328,7 @@ multipart_set_boundary (CamelMultipart *multipart,
                boundary = bbuf;
        }
 
-       camel_content_type_set_param (cdw->mime_type, "boundary", boundary);
+       camel_content_type_set_param (camel_data_wrapper_get_mime_type_field (cdw), "boundary", boundary);
 }
 
 static const gchar *
@@ -336,8 +336,8 @@ multipart_get_boundary (CamelMultipart *multipart)
 {
        CamelDataWrapper *cdw = CAMEL_DATA_WRAPPER (multipart);
 
-       g_return_val_if_fail (cdw->mime_type != NULL, NULL);
-       return camel_content_type_param (cdw->mime_type, "boundary");
+       g_return_val_if_fail (camel_data_wrapper_get_mime_type_field (cdw) != NULL, NULL);
+       return camel_content_type_param (camel_data_wrapper_get_mime_type_field (cdw), "boundary");
 }
 
 static gint
diff --git a/src/camel/camel-search-private.c b/src/camel/camel-search-private.c
index 5d9412b..1401dd9 100644
--- a/src/camel/camel-search-private.c
+++ b/src/camel/camel-search-private.c
@@ -524,8 +524,8 @@ camel_search_message_body_contains (CamelDataWrapper *object,
        } else if (CAMEL_IS_MIME_MESSAGE (containee)) {
                /* For messages we only look at its contents. */
                truth = camel_search_message_body_contains ((CamelDataWrapper *) containee, pattern);
-       } else if (camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "text", "*")
-               || camel_content_type_is (CAMEL_DATA_WRAPPER (containee)->mime_type, "x-evolution", 
"evolution-rss-feed")) {
+       } else if (camel_content_type_is (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER 
(containee)), "text", "*")
+               || camel_content_type_is (camel_data_wrapper_get_mime_type_field (CAMEL_DATA_WRAPPER 
(containee)), "x-evolution", "evolution-rss-feed")) {
                /* For all other text parts we look
                 * inside, otherwise we don't care. */
                CamelStream *stream;
@@ -535,7 +535,7 @@ camel_search_message_body_contains (CamelDataWrapper *object,
                byte_array = g_byte_array_new ();
                stream = camel_stream_mem_new_with_byte_array (byte_array);
 
-               charset = camel_content_type_param (CAMEL_DATA_WRAPPER (containee)->mime_type, "charset");
+               charset = camel_content_type_param (camel_data_wrapper_get_mime_type_field 
(CAMEL_DATA_WRAPPER (containee)), "charset");
                if (charset && *charset) {
                        CamelMimeFilter *filter = camel_mime_filter_charset_new (charset, "UTF-8");
                        if (filter) {
diff --git a/src/camel/camel-smime-context.c b/src/camel/camel-smime-context.c
index 1e18a1d..adc1689 100644
--- a/src/camel/camel-smime-context.c
+++ b/src/camel/camel-smime-context.c
@@ -871,7 +871,7 @@ smime_context_sign_sync (CamelCipherContext *context,
        g_seekable_seek (G_SEEKABLE (ostream), 0, G_SEEK_SET, NULL, NULL);
        camel_data_wrapper_construct_from_stream_sync (
                dw, ostream, cancellable, NULL);
-       dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
+       camel_data_wrapper_set_encoding (dw, CAMEL_TRANSFER_ENCODING_BINARY);
 
        if (((CamelSMIMEContext *) context)->priv->sign_mode == CAMEL_SMIME_SIGN_CLEARSIGN) {
                CamelMultipartSigned *mps;
@@ -951,7 +951,7 @@ smime_context_verify_sync (CamelCipherContext *context,
        class = CAMEL_CIPHER_CONTEXT_GET_CLASS (context);
 
        dw = camel_medium_get_content ((CamelMedium *) ipart);
-       ct = dw->mime_type;
+       ct = camel_data_wrapper_get_mime_type_field (dw);
 
        /* FIXME: we should stream this to the decoder */
        buffer = g_byte_array_new ();
@@ -1175,7 +1175,7 @@ smime_context_encrypt_sync (CamelCipherContext *context,
        camel_data_wrapper_construct_from_stream_sync (
                dw, ostream, NULL, NULL);
        g_object_unref (ostream);
-       dw->encoding = CAMEL_TRANSFER_ENCODING_BINARY;
+       camel_data_wrapper_set_encoding (dw, CAMEL_TRANSFER_ENCODING_BINARY);
 
        ct = camel_content_type_new ("application", "x-pkcs7-mime");
        camel_content_type_set_param (ct, "name", "smime.p7m");


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