[gmime] Added a GMimeTextPart for convenience



commit 25f69458e811cbfbff051b5ad07120c521eb6e06
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Wed Mar 8 15:15:35 2017 -0500

    Added a GMimeTextPart for convenience
    
    Allows more easily setting/getting text content.

 PORTING                     |    5 +
 examples/basic-example.c    |   23 +---
 gmime/Makefile.am           |    2 +
 gmime/gmime-part.c          |    6 +-
 gmime/gmime-stream-filter.c |    4 +-
 gmime/gmime-text-part.c     |  299 +++++++++++++++++++++++++++++++++++++++++++
 gmime/gmime-text-part.h     |   70 ++++++++++
 gmime/gmime.c               |    1 +
 gmime/gmime.h               |    1 +
 tests/test-parser.c         |    3 +-
 tests/test-pgpmime.c        |   40 +-----
 tests/test-smime.c          |   40 +-----
 12 files changed, 402 insertions(+), 92 deletions(-)
---
diff --git a/PORTING b/PORTING
index 61a2825..f9dbbb8 100644
--- a/PORTING
+++ b/PORTING
@@ -115,6 +115,11 @@ Porting from GMime 2.6 to GMime 3.0
 - g_mime_stream_fs_new_for_path() has been renamed to
   g_mime_stream_fs_open().
 
+- g_mime_part_new() now returns a GMimePart with a Content-Type of
+  "application/octet-stream" instead of "text/plain" since there is
+  now a GMimeTextPart who's g_mime_text_part_new() returns a
+  GMimeTextPart with a Content-Type of "text/plain".
+
 
 Porting from GMime 2.4 to GMime 2.6
 -----------------------------------
diff --git a/examples/basic-example.c b/examples/basic-example.c
index 3fbfe29..f386a44 100644
--- a/examples/basic-example.c
+++ b/examples/basic-example.c
@@ -202,35 +202,24 @@ write_message_to_screen (GMimeMessage *message)
        g_object_unref (stream);
 }
 
-#define PART_CONTENT "Hello, this is the new text/plain part's content text."
+#define TEXT_CONTENT "Hello, this is the new text/plain part's content text."
 
 static void
 add_a_mime_part (GMimeMessage *message)
 {
        GMimeMultipart *multipart;
        GMimeDataWrapper *content;
-       GMimePart *mime_part;
+       GMimeTextPart *mime_part;
        GMimeStream *stream;
        
        /* create the new part that we are going to add... */
-       mime_part = g_mime_part_new_with_type ("text", "plain");
+       mime_part = g_mime_text_part_new_with_subtype ("plain");
        
-       /* create the parts' content stream */
-       stream = g_mime_stream_mem_new_with_buffer (PART_CONTENT, strlen (PART_CONTENT));
-       
-       /* create the content object - since the stream is not base64
-          or QP encoded or anything, we can use
-          GMIME_CONTENT_ENCODING_DEFAULT as the encoding type (_DEFAULT
-          is the same as saying "nothing specified") */
-       content = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
-       g_object_unref (stream);
-       
-       /* set the content object on the new mime part */
-       g_mime_part_set_content_object (mime_part, content);
-       g_object_unref (content);
+       /* set the text content of the mime part */
+       g_mime_text_part_set_text (mime_part, TEXT_CONTENT);
        
        /* if we want, we can tell GMime that the content should be base64 encoded when written to disk... */
-       g_mime_part_set_content_encoding (mime_part, GMIME_CONTENT_ENCODING_BASE64);
+       g_mime_part_set_content_encoding ((GMimePart *) mime_part, GMIME_CONTENT_ENCODING_BASE64);
        
        /* the "polite" way to modify a mime structure that we didn't
           create is to create a new toplevel multipart/mixed part and
diff --git a/gmime/Makefile.am b/gmime/Makefile.am
index c0f931c..bfdf9f3 100644
--- a/gmime/Makefile.am
+++ b/gmime/Makefile.am
@@ -75,6 +75,7 @@ libgmime_3_0_la_SOURCES =             \
        gmime-stream-mmap.c             \
        gmime-stream-null.c             \
        gmime-stream-pipe.c             \
+       gmime-text-part.c               \
        gmime-utils.c                   \
        internet-address.c
 
@@ -131,6 +132,7 @@ gmimeinclude_HEADERS =                      \
        gmime-stream-mmap.h             \
        gmime-stream-null.h             \
        gmime-stream-pipe.h             \
+       gmime-text-part.h               \
        gmime-utils.h                   \
        gmime-version.h                 \
        internet-address.h
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index a1b8081..d3628e4 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -437,10 +437,10 @@ mime_part_encode (GMimeObject *object, GMimeEncodingConstraint constraint)
  * g_mime_part_new:
  *
  * Creates a new MIME Part object with a default content-type of
- * text/plain.
+ * application/octet-stream.
  *
  * Returns: an empty MIME Part object with a default content-type of
- * text/plain.
+ * application/octet-stream.
  **/
 GMimePart *
 g_mime_part_new (void)
@@ -450,7 +450,7 @@ g_mime_part_new (void)
        
        mime_part = g_object_newv (GMIME_TYPE_PART, 0, NULL);
        
-       content_type = g_mime_content_type_new ("text", "plain");
+       content_type = g_mime_content_type_new ("application", "octet-stream");
        g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
        g_object_unref (content_type);
        
diff --git a/gmime/gmime-stream-filter.c b/gmime/gmime-stream-filter.c
index a532cb5..e5a90ee 100644
--- a/gmime/gmime-stream-filter.c
+++ b/gmime/gmime-stream-filter.c
@@ -418,11 +418,11 @@ g_mime_stream_filter_new (GMimeStream *stream)
        filter->source = stream;
        g_object_ref (stream);
        
-       g_mime_stream_construct (GMIME_STREAM (filter),
+       g_mime_stream_construct ((GMimeStream *) filter,
                                 stream->bound_start,
                                 stream->bound_end);
        
-       return GMIME_STREAM (filter);
+       return (GMimeStream *) filter;
 }
 
 
diff --git a/gmime/gmime-text-part.c b/gmime/gmime-text-part.c
new file mode 100644
index 0000000..b06105e
--- /dev/null
+++ b/gmime/gmime-text-part.c
@@ -0,0 +1,299 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2017 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <string.h>
+
+#include "gmime-text-part.h"
+#include "gmime-stream-mem.h"
+#include "gmime-stream-filter.h"
+#include "gmime-filter-charset.h"
+#include "gmime-charset.h"
+
+#define d(x)
+
+
+/**
+ * SECTION: gmime-text-part
+ * @title: GMimeTextPart
+ * @short_description: textual MIME parts
+ * @see_also:
+ *
+ * A #GMimeTextPart represents any text MIME part.
+ **/
+
+/* GObject class methods */
+static void g_mime_text_part_class_init (GMimeTextPartClass *klass);
+static void g_mime_text_part_init (GMimeTextPart *mime_part, GMimeTextPartClass *klass);
+static void g_mime_text_part_finalize (GObject *object);
+
+
+static GMimePartClass *parent_class = NULL;
+
+
+GType
+g_mime_text_part_get_type (void)
+{
+       static GType type = 0;
+       
+       if (!type) {
+               static const GTypeInfo info = {
+                       sizeof (GMimeTextPartClass),
+                       NULL, /* base_class_init */
+                       NULL, /* base_class_finalize */
+                       (GClassInitFunc) g_mime_text_part_class_init,
+                       NULL, /* class_finalize */
+                       NULL, /* class_data */
+                       sizeof (GMimeTextPart),
+                       0,    /* n_preallocs */
+                       (GInstanceInitFunc) g_mime_text_part_init,
+               };
+               
+               type = g_type_register_static (GMIME_TYPE_PART, "GMimeTextPart", &info, 0);
+       }
+       
+       return type;
+}
+
+
+static void
+g_mime_text_part_class_init (GMimeTextPartClass *klass)
+{
+       GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+       
+       parent_class = g_type_class_ref (GMIME_TYPE_PART);
+       
+       gobject_class->finalize = g_mime_text_part_finalize;
+}
+
+static void
+g_mime_text_part_init (GMimeTextPart *mime_part, GMimeTextPartClass *klass)
+{
+}
+
+static void
+g_mime_text_part_finalize (GObject *object)
+{
+       GMimeTextPart *mime_part = (GMimeTextPart *) object;
+       
+       G_OBJECT_CLASS (parent_class)->finalize (object);
+}
+
+
+/**
+ * g_mime_text_part_new:
+ *
+ * Creates a new text MIME part object with a default content-type of
+ * text/plain.
+ *
+ * Returns: an empty MIME Part object with a default content-type of
+ * text/plain.
+ **/
+GMimeTextPart *
+g_mime_text_part_new (void)
+{
+       GMimeContentType *content_type;
+       GMimeTextPart *mime_part;
+       
+       mime_part = g_object_newv (GMIME_TYPE_TEXT_PART, 0, NULL);
+       
+       content_type = g_mime_content_type_new ("text", "plain");
+       g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
+       g_object_unref (content_type);
+       
+       return mime_part;
+}
+
+
+/**
+ * g_mime_text_part_new_with_subtype:
+ * @subtype: textual subtype string
+ *
+ * Creates a new text MIME part with a sepcified subtype.
+ *
+ * Returns: an empty text MIME part object with the specified subtype.
+ **/
+GMimeTextPart *
+g_mime_text_part_new_with_subtype (const char *subtype)
+{
+       GMimeContentType *content_type;
+       GMimeTextPart *mime_part;
+       
+       mime_part = g_object_newv (GMIME_TYPE_TEXT_PART, 0, NULL);
+       
+       content_type = g_mime_content_type_new ("text", subtype);
+       g_mime_object_set_content_type (GMIME_OBJECT (mime_part), content_type);
+       g_object_unref (content_type);
+       
+       return mime_part;
+}
+
+
+/**
+ * g_mime_text_part_set_charset:
+ * @mime_part: a #GMimeTextPart
+ * @charset: the name of the charset
+ *
+ * Sets the charset parameter on the Content-Type header to the specified value.
+ **/
+void
+g_mime_text_part_set_charset (GMimeTextPart *mime_part, const char *charset)
+{
+       GMimeContentType *content_type;
+       
+       g_return_if_fail (GMIME_IS_TEXT_PART (mime_part));
+       g_return_if_fail (charset != NULL);
+       
+       content_type = g_mime_object_get_content_type ((GMimeObject *) mime_part);
+       g_mime_content_type_set_parameter (content_type, "charset", charset);
+}
+
+
+/**
+ * g_mime_text_part_get_charset:
+ * @mime_part: a #GMimeTextPart
+ *
+ * Gets the value of the charset parameter on the Content-Type header.
+ *
+ * Returns: the value of the charset parameter or %NULL if unavailable.
+ **/
+const char *
+g_mime_text_part_get_charset (GMimeTextPart *mime_part)
+{
+       GMimeContentType *content_type;
+       
+       g_return_val_if_fail (GMIME_IS_TEXT_PART (mime_part), NULL);
+       
+       content_type = g_mime_object_get_content_type ((GMimeObject *) mime_part);
+       
+       return g_mime_content_type_get_parameter (content_type, "charset");
+}
+
+
+/**
+ * g_mime_text_part_set_text:
+ * @mime_part: a #GMimeTextPart
+ * @text: the text in utf-8
+ *
+ * Sets the specified text as the content and updates the charset parameter on the Content-Type header.
+ **/
+void
+g_mime_text_part_set_text (GMimeTextPart *mime_part, const char *text)
+{
+       GMimeContentType *content_type;
+       GMimeStream *filtered, *stream;
+       GMimeDataWrapper *content;
+       GMimeFilter *filter;
+       const char *charset;
+       GMimeCharset mask;
+       size_t len;
+       
+       g_return_if_fail (GMIME_IS_TEXT_PART (mime_part));
+       g_return_if_fail (text != NULL);
+       
+       len = strlen (text);
+       
+       g_mime_charset_init (&mask);
+       g_mime_charset_step (&mask, text, len);
+       
+       switch (mask.level) {
+       case 1: charset = "iso-8859-1"; break;
+       case 0: charset = "us-ascii"; break;
+       default: charset = "utf-8"; break;
+       }
+       
+       content_type = g_mime_object_get_content_type ((GMimeObject *) mime_part);
+       g_mime_content_type_set_parameter (content_type, "charset", charset);
+       
+       stream = g_mime_stream_mem_new_with_buffer (text, len);
+       
+       if (mask.level == 1) {
+               filtered = g_mime_stream_filter_new (stream);
+               g_object_unref (stream);
+               
+               filter = g_mime_filter_charset_new ("utf-8", charset);
+               g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+               g_object_unref (filter);
+               
+               stream = filtered;
+       }
+       
+       content = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
+       g_object_unref (stream);
+       
+       g_mime_part_set_content_object ((GMimePart *) mime_part, content);
+       g_object_unref (content);
+}
+
+
+/**
+ * g_mime_text_part_get_text:
+ * @mime_part: a #GMimeTextPart
+ * @charset: the charset
+ *
+ * Gets the text content of the @mime_part as a string.
+ *
+ * Returns: a newly allocated string containing the utf-8 encoded text content.
+ **/
+char *
+g_mime_text_part_get_text (GMimeTextPart *mime_part)
+{
+       GMimeContentType *content_type;
+       GMimeStream *filtered, *stream;
+       GMimeDataWrapper *content;
+       GMimeFilter *filter;
+       const char *charset;
+       GByteArray *buf;
+       
+       g_return_val_if_fail (GMIME_IS_TEXT_PART (mime_part), NULL);
+       
+       if (!(content = g_mime_part_get_content_object ((GMimePart *) mime_part)))
+               return NULL;
+       
+       content_type = g_mime_object_get_content_type ((GMimeObject *) mime_part);
+       stream = g_mime_stream_mem_new ();
+       
+       if ((charset = g_mime_content_type_get_parameter (content_type, "charset")) != NULL) {
+               filter = g_mime_filter_charset_new (charset, "utf-8");
+               filtered = g_mime_stream_filter_new (stream);
+               g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+               g_object_unref (filter);
+               
+               g_mime_data_wrapper_write_to_stream (content, filtered);
+               g_mime_stream_flush (filtered);
+               g_object_unref (filtered);
+       } else {
+               g_mime_data_wrapper_write_to_stream (content, stream);
+       }
+       
+       g_mime_stream_write (stream, "", 1);
+       
+       buf = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) stream);
+       g_mime_stream_mem_set_owner ((GMimeStreamMem *) stream, FALSE);
+       g_object_unref (stream);
+       
+       return (char *) g_byte_array_free (buf, FALSE);
+}
diff --git a/gmime/gmime-text-part.h b/gmime/gmime-text-part.h
new file mode 100644
index 0000000..fb58b88
--- /dev/null
+++ b/gmime/gmime-text-part.h
@@ -0,0 +1,70 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*  GMime
+ *  Copyright (C) 2000-2017 Jeffrey Stedfast
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
+ *  02110-1301, USA.
+ */
+
+
+#ifndef __GMIME_TEXT_PART_H__
+#define __GMIME_TEXT_PART_H__
+
+#include <gmime/gmime-part.h>
+
+G_BEGIN_DECLS
+
+#define GMIME_TYPE_TEXT_PART            (g_mime_text_part_get_type ())
+#define GMIME_TEXT_PART(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GMIME_TYPE_TEXT_PART, 
GMimeTextPart))
+#define GMIME_TEXT_PART_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GMIME_TYPE_TEXT_PART, 
GMimeTextPartClass))
+#define GMIME_IS_TEXT_PART(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GMIME_TYPE_TEXT_PART))
+#define GMIME_IS_TEXT_PART_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GMIME_TYPE_TEXT_PART))
+#define GMIME_TEXT_PART_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GMIME_TYPE_TEXT_PART, 
GMimeTextPartClass))
+
+typedef struct _GMimeTextPart GMimeTextPart;
+typedef struct _GMimeTextPartClass GMimeTextPartClass;
+
+/**
+ * GMimeTextPart:
+ * @parent_object: parent #GMimePart
+ *
+ * A text MIME part object.
+ **/
+struct _GMimeTextPart {
+       GMimePart parent_object;
+       
+};
+
+struct _GMimeTextPartClass {
+       GMimePartClass parent_class;
+       
+};
+
+
+GType g_mime_text_part_get_type (void);
+
+/* constructors */
+GMimeTextPart *g_mime_text_part_new (void);
+GMimeTextPart *g_mime_text_part_new_with_subtype (const char *subtype);
+
+void g_mime_text_part_set_charset (GMimeTextPart *mime_part, const char *charset);
+const char *g_mime_text_part_get_charset (GMimeTextPart *mime_part);
+
+void g_mime_text_part_set_text (GMimeTextPart *mime_part, const char *text);
+char *g_mime_text_part_get_text (GMimeTextPart *mime_part);
+
+G_END_DECLS
+
+#endif /* __GMIME_TEXT_PART_H__ */
diff --git a/gmime/gmime.c b/gmime/gmime.c
index e24dbbb..db9c0b9 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -181,6 +181,7 @@ g_mime_init (void)
        /* register our default mime object types */
        g_mime_object_type_registry_init ();
        g_mime_object_register_type ("*", "*", g_mime_part_get_type ());
+       g_mime_object_register_type ("text", "*", g_mime_text_part_get_type ());
        g_mime_object_register_type ("application", "x-pkcs7-mime", g_mime_application_pkcs7_mime_get_type 
());
        g_mime_object_register_type ("application", "pkcs7-mime", g_mime_application_pkcs7_mime_get_type ());
        g_mime_object_register_type ("multipart", "*", g_mime_multipart_get_type ());
diff --git a/gmime/gmime.h b/gmime/gmime.h
index dbd7c63..7a360f7 100644
--- a/gmime/gmime.h
+++ b/gmime/gmime.h
@@ -34,6 +34,7 @@
 #include <gmime/gmime-data-wrapper.h>
 #include <gmime/gmime-object.h>
 #include <gmime/gmime-part.h>
+#include <gmime/gmime-text-part.h>
 #include <gmime/gmime-part-iter.h>
 #include <gmime/gmime-application-pkcs7-mime.h>
 #include <gmime/gmime-multipart.h>
diff --git a/tests/test-parser.c b/tests/test-parser.c
index ce4fb3a..ff81149 100644
--- a/tests/test-parser.c
+++ b/tests/test-parser.c
@@ -259,8 +259,7 @@ int main (int argc, char **argv)
 #endif
        
 #ifdef STREAM_BUFFER
-       istream = g_mime_stream_buffer_new (stream,
-                                           GMIME_STREAM_BUFFER_BLOCK_READ);
+       istream = g_mime_stream_buffer_new (stream, GMIME_STREAM_BUFFER_BLOCK_READ);
        g_object_unref (stream);
        stream = istream;
 #endif
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index b8c236c..7cf43a5 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -154,35 +154,17 @@ test_multipart_signed (GMimeCryptoContext *ctx)
 {
        GMimeSignatureList *signatures;
        GMimeMultipartSigned *mps;
-       GMimeDataWrapper *content;
        InternetAddressList *list;
        InternetAddress *mailbox;
        GMimeMessage *message;
        GMimeStream *stream;
        GMimeParser *parser;
+       GMimeTextPart *part;
        GError *err = NULL;
-       GMimePart *part;
        Exception *ex;
        
-       part = g_mime_part_new_with_type ("text", "plain");
-       
-       stream = g_mime_stream_mem_new ();
-       g_mime_stream_write_string (stream, MULTIPART_SIGNED_CONTENT);
-#if 0
-       "This is a test of the emergency broadcast system with an sha1 detach-sign.\n\n"
-               "From now on, there will be text to try and break     \t  \n"
-               "various things. For example, the F in \"From\" in the previous line...\n"
-               "...and the first dot of this line have been pre-encoded in the QP encoding "
-               "in order to test that GMime properly treats MIME part content as opaque.\n"
-               "If this still verifies okay, then we have ourselves a winner I guess...\n";
-#endif
-       
-       g_mime_stream_reset (stream);
-       content = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
-       g_object_unref (stream);
-       
-       g_mime_part_set_content_object (part, content);
-       g_object_unref (content);
+       part = g_mime_text_part_new_with_subtype ("plain");
+       g_mime_text_part_set_text (part, MULTIPART_SIGNED_CONTENT);
        
        /* create the multipart/signed container part */
        mps = g_mime_multipart_signed_new ();
@@ -263,26 +245,16 @@ create_encrypted_message (GMimeCryptoContext *ctx, gboolean sign,
 {
        GMimeStream *cleartext, *stream;
        GMimeMultipartEncrypted *mpe;
-       GMimeDataWrapper *content;
        InternetAddressList *list;
        InternetAddress *mailbox;
        GPtrArray *recipients;
        GMimeMessage *message;
        Exception *ex = NULL;
        GError *err = NULL;
-       GMimePart *part;
-       
-       cleartext = g_mime_stream_mem_new ();
-       g_mime_stream_write_string (cleartext, MULTIPART_ENCRYPTED_CONTENT);
-       g_mime_stream_reset (cleartext);
-       
-       content = g_mime_data_wrapper_new ();
-       g_mime_data_wrapper_set_stream (content, cleartext);
-       g_object_unref (cleartext);
+       GMimeTextPart *part;
        
-       part = g_mime_part_new_with_type ("text", "plain");
-       g_mime_part_set_content_object (part, content);
-       g_object_unref (content);
+       part = g_mime_text_part_new ();
+       g_mime_text_part_set_text (part, MULTIPART_ENCRYPTED_CONTENT);
        
        /* hold onto this for comparison later */
        cleartext = g_mime_stream_mem_new ();
diff --git a/tests/test-smime.c b/tests/test-smime.c
index 874333b..f4afb3f 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -157,35 +157,17 @@ test_multipart_signed (GMimeCryptoContext *ctx)
 {
        GMimeSignatureList *signatures;
        GMimeMultipartSigned *mps;
-       GMimeDataWrapper *content;
        InternetAddressList *list;
        InternetAddress *mailbox;
        GMimeMessage *message;
        GMimeStream *stream;
        GMimeParser *parser;
+       GMimeTextPart *part;
        GError *err = NULL;
-       GMimePart *part;
        Exception *ex;
        
-       part = g_mime_part_new_with_type ("text", "plain");
-       
-       stream = g_mime_stream_mem_new ();
-       g_mime_stream_write_string (stream, MULTIPART_SIGNED_CONTENT);
-#if 0
-       "This is a test of the emergency broadcast system with an sha1 detach-sign.\n\n"
-               "From now on, there will be text to try and break     \t  \n"
-               "various things. For example, the F in \"From\" in the previous line...\n"
-               "...and the first dot of this line have been pre-encoded in the QP encoding "
-               "in order to test that GMime properly treats MIME part content as opaque.\n"
-               "If this still verifies okay, then we have ourselves a winner I guess...\n";
-#endif
-       
-       g_mime_stream_reset (stream);
-       content = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT);
-       g_object_unref (stream);
-       
-       g_mime_part_set_content_object (part, content);
-       g_object_unref (content);
+       part = g_mime_text_part_new_with_subtype ("plain");
+       g_mime_text_part_set_text (part, MULTIPART_SIGNED_CONTENT);
        
        /* create the multipart/signed container part */
        mps = g_mime_multipart_signed_new ();
@@ -267,7 +249,6 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
        GMimeStream *cleartext, *stream;
        GMimeMultipartEncrypted *mpe;
        GMimeDecryptResult *result;
-       GMimeDataWrapper *content;
        InternetAddressList *list;
        InternetAddress *mailbox;
        GMimeObject *decrypted;
@@ -275,21 +256,12 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign)
        GMimeMessage *message;
        Exception *ex = NULL;
        GMimeParser *parser;
+       GMimeTextPart *part;
        GByteArray *buf[2];
        GError *err = NULL;
-       GMimePart *part;
-       
-       cleartext = g_mime_stream_mem_new ();
-       g_mime_stream_write_string (cleartext, MULTIPART_ENCRYPTED_CONTENT);
-       g_mime_stream_reset (cleartext);
-       
-       content = g_mime_data_wrapper_new ();
-       g_mime_data_wrapper_set_stream (content, cleartext);
-       g_object_unref (cleartext);
        
-       part = g_mime_part_new_with_type ("text", "plain");
-       g_mime_part_set_content_object (part, content);
-       g_object_unref (content);
+       part = g_mime_text_part_new ();
+       g_mime_text_part_set_text (part, MULTIPART_ENCRYPTED_CONTENT);
        
        /* hold onto this for comparison later */
        cleartext = g_mime_stream_mem_new ();


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