[gmime] Proliferate GMimeFormatOptions throughout the API



commit 73943074a78da2a1df8b3d1fa0aa7c818b5dd35e
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Mar 17 21:27:03 2017 -0400

    Proliferate GMimeFormatOptions throughout the API

 examples/basic-example.c             |    3 +-
 examples/imap-example.c              |   30 ++++++++----
 gmime/gmime-application-pkcs7-mime.c |   84 ++++++++++++++++++----------------
 gmime/gmime-content-type.c           |    5 +-
 gmime/gmime-content-type.h           |    2 +-
 gmime/gmime-disposition.c            |    5 +-
 gmime/gmime-disposition.h            |    2 +-
 gmime/gmime-format-options.h         |   21 ++++++++-
 gmime/gmime-header.c                 |   24 ++++++----
 gmime/gmime-header.h                 |   12 +++--
 gmime/gmime-internal.h               |   12 ++++-
 gmime/gmime-message-part.c           |    9 ++--
 gmime/gmime-message-partial.c        |    5 ++-
 gmime/gmime-message.c                |   82 ++++++++++++++++++++-------------
 gmime/gmime-multipart-encrypted.c    |    3 +-
 gmime/gmime-multipart-signed.c       |   29 ++++++------
 gmime/gmime-multipart.c              |    9 ++--
 gmime/gmime-object.c                 |   48 ++++++++++++--------
 gmime/gmime-object.h                 |   12 +++--
 gmime/gmime-param.c                  |    9 ++--
 gmime/gmime-param.h                  |   22 +--------
 gmime/gmime-part.c                   |   31 ++++++------
 gmime/gmime-utils.c                  |   51 ++++++++++++--------
 gmime/gmime-utils.h                  |   11 ++--
 gmime/gmime.c                        |    2 +
 gmime/internet-address.c             |   39 +++++++++-------
 gmime/internet-address.h             |   10 ++--
 tests/test-mbox.c                    |    7 ++-
 tests/test-mime.c                    |   22 +++++----
 tests/test-parser.c                  |    9 ++--
 tests/test-partial.c                 |    7 ++-
 tests/test-pgpmime.c                 |   15 ++++--
 tests/test-smime.c                   |    3 +-
 33 files changed, 371 insertions(+), 264 deletions(-)
---
diff --git a/examples/basic-example.c b/examples/basic-example.c
index 58926d9..627bfa4 100644
--- a/examples/basic-example.c
+++ b/examples/basic-example.c
@@ -186,6 +186,7 @@ verify_signed_parts (GMimeMessage *message)
 static void
 write_message_to_screen (GMimeMessage *message)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeStream *stream;
        
        /* create a new stream for writing to stdout */
@@ -193,7 +194,7 @@ write_message_to_screen (GMimeMessage *message)
        g_mime_stream_file_set_owner ((GMimeStreamFile *) stream, FALSE);
        
        /* write the message to the stream */
-       g_mime_object_write_to_stream ((GMimeObject *) message, stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        
        /* flush the stream (kinda like fflush() in libc's stdio) */
        g_mime_stream_flush (stream);
diff --git a/examples/imap-example.c b/examples/imap-example.c
index 8b28866..106d6bd 100644
--- a/examples/imap-example.c
+++ b/examples/imap-example.c
@@ -274,6 +274,7 @@ write_bodystructure (GMimeMessage *message, const char *uid)
 static void
 write_header (GMimeMessage *message, const char *uid)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        char *buf;
        FILE *fp;
        
@@ -281,7 +282,7 @@ write_header (GMimeMessage *message, const char *uid)
        fp = fopen (buf, "wt");
        g_free (buf);
        
-       buf = g_mime_object_get_headers ((GMimeObject *) message);
+       buf = g_mime_object_get_headers ((GMimeObject *) message, format);
        
        fwrite (buf, 1, strlen (buf), fp);
        g_free (buf);
@@ -292,8 +293,10 @@ write_header (GMimeMessage *message, const char *uid)
 static void
 write_part (GMimeObject *part, const char *uid, const char *spec)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeStream *istream, *ostream;
        GMimeMultipart *multipart;
+       GMimeDataWrapper *content;
        GMimeMessage *message;
        GMimeObject *subpart;
        char *buf, *id;
@@ -304,7 +307,7 @@ write_part (GMimeObject *part, const char *uid, const char *spec)
        fp = fopen (buf, "wt");
        g_free (buf);
        
-       buf = g_mime_object_get_headers (part);
+       buf = g_mime_object_get_headers (part, format);
        fwrite (buf, 1, strlen (buf), fp);
        g_free (buf);
        
@@ -327,10 +330,10 @@ write_part (GMimeObject *part, const char *uid, const char *spec)
                fp = fopen (buf, "wt");
                g_free (buf);
                
-               message = GMIME_MESSAGE_PART (part)->message;
+               message = g_mime_message_part_get_message ((GMimeMessagePart *) part);
                
                ostream = g_mime_stream_file_new (fp);
-               g_mime_object_write_to_stream (GMIME_OBJECT (message), ostream);
+               g_mime_object_write_to_stream ((GMimeObject *) message, format, ostream);
                g_object_unref (ostream);
        } else if (GMIME_IS_PART (part)) {
                buf = g_strdup_printf ("%s/%s.TEXT", uid, spec);
@@ -338,7 +341,8 @@ write_part (GMimeObject *part, const char *uid, const char *spec)
                g_free (buf);
                
                ostream = g_mime_stream_file_new (fp);
-               istream = g_mime_data_wrapper_get_stream (GMIME_PART (part)->content);
+               content = g_mime_part_get_content ((GMimePart *) part);
+               istream = g_mime_data_wrapper_get_stream (content);
                g_mime_stream_write_to_stream (istream, ostream);
                g_object_unref (ostream);
        }
@@ -869,6 +873,8 @@ reconstruct_multipart (GMimeMultipart *multipart, struct _bodystruct *body,
 static void
 reconstruct_message (const char *uid)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
+       GMimeObject *mime_part;
        GMimeMessage *message;
        GMimeParser *parser;
        GMimeStream *stream;
@@ -892,7 +898,9 @@ reconstruct_message (const char *uid)
        message = g_mime_parser_construct_message (parser, NULL);
        g_object_unref (parser);
        
-       if (GMIME_IS_MULTIPART (message->mime_part)) {
+       mime_part = g_mime_message_get_mime_part (message);
+       
+       if (GMIME_IS_MULTIPART (mime_part)) {
                struct _bodystruct *body;
                GByteArray *buffer;
                GMimeStream *mem;
@@ -911,16 +919,16 @@ reconstruct_message (const char *uid)
                g_mime_stream_write_to_stream (stream, mem);
                g_object_unref (stream);
                
-               buffer = GMIME_STREAM_MEM (mem)->buffer;
+               buffer = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) mem);
                body = bodystruct_parse (buffer->data, buffer->len);
                g_object_unref (mem);
                
                bodystruct_dump (body, 0);
                
-               reconstruct_multipart ((GMimeMultipart *) message->mime_part, body, uid, "1");
+               reconstruct_multipart ((GMimeMultipart *) mime_part, body, uid, "1");
                bodystruct_free (body);
-       } else if (GMIME_IS_PART (message->mime_part)) {
-               reconstruct_part_content ((GMimePart *) message->mime_part, uid, "1");
+       } else if (GMIME_IS_PART (mime_part)) {
+               reconstruct_part_content ((GMimePart *) mime_part, uid, "1");
        }
        
        filename = g_strdup_printf ("%s/MESSAGE", uid);
@@ -931,7 +939,7 @@ reconstruct_message (const char *uid)
        
        g_free (filename);
        stream = g_mime_stream_fs_new (fd);
-       g_mime_object_write_to_stream ((GMimeObject *) message, stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        g_object_unref (message);
        g_object_unref (stream);
 }
diff --git a/gmime/gmime-application-pkcs7-mime.c b/gmime/gmime-application-pkcs7-mime.c
index be2ca54..0b10423 100644
--- a/gmime/gmime-application-pkcs7-mime.c
+++ b/gmime/gmime-application-pkcs7-mime.c
@@ -227,12 +227,13 @@ g_mime_application_pkcs7_mime_decompress (GMimeApplicationPkcs7Mime *pkcs7_mime,
 GMimeApplicationPkcs7Mime *
 g_mime_application_pkcs7_mime_encrypt (GMimeObject *entity, GMimeEncryptFlags flags, GPtrArray *recipients, 
GError **err)
 {
-       GMimeStream *filtered_stream, *ciphertext, *stream;
+       GMimeStream *filtered, *ciphertext, *stream;
        GMimeApplicationPkcs7Mime *pkcs7_mime;
        GMimeContentType *content_type;
+       GMimeFormatOptions *options;
        GMimeDataWrapper *content;
-       GMimeFilter *crlf_filter;
        GMimeCryptoContext *ctx;
+       GMimeFilter *filter;
        
        g_return_val_if_fail (GMIME_IS_OBJECT (entity), NULL);
        g_return_val_if_fail (recipients != NULL, NULL);
@@ -244,17 +245,19 @@ g_mime_application_pkcs7_mime_encrypt (GMimeObject *entity, GMimeEncryptFlags fl
                return NULL;
        }
        
+       options = g_mime_format_options_get_default ();
+       
        /* get the cleartext */
        stream = g_mime_stream_mem_new ();
-       filtered_stream = g_mime_stream_filter_new (stream);
+       filtered = g_mime_stream_filter_new (stream);
        
-       crlf_filter = g_mime_filter_crlf_new (TRUE, FALSE);
-       g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), crlf_filter);
-       g_object_unref (crlf_filter);
+       filter = g_mime_filter_crlf_new (TRUE, FALSE);
+       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+       g_object_unref (filter);
        
-       g_mime_object_write_to_stream (entity, filtered_stream);
-       g_mime_stream_flush (filtered_stream);
-       g_object_unref (filtered_stream);
+       g_mime_object_write_to_stream (entity, options, filtered);
+       g_mime_stream_flush (filtered);
+       g_object_unref (filtered);
        
        /* reset the content stream */
        g_mime_stream_reset (stream);
@@ -312,12 +315,12 @@ g_mime_application_pkcs7_mime_decrypt (GMimeApplicationPkcs7Mime *pkcs7_mime,
                                       GMimeDecryptFlags flags, const char *session_key,
                                       GMimeDecryptResult **result, GError **err)
 {
-       GMimeStream *filtered_stream, *ciphertext, *stream;
+       GMimeStream *filtered, *ciphertext, *stream;
        GMimeDataWrapper *content;
-       GMimeFilter *crlf_filter;
        GMimeCryptoContext *ctx;
        GMimeDecryptResult *res;
        GMimeObject *decrypted;
+       GMimeFilter *filter;
        GMimeParser *parser;
        
        g_return_val_if_fail (GMIME_IS_APPLICATION_PKCS7_MIME (pkcs7_mime), NULL);
@@ -333,30 +336,30 @@ g_mime_application_pkcs7_mime_decrypt (GMimeApplicationPkcs7Mime *pkcs7_mime,
        }
        
        /* get the ciphertext stream */
-       content = g_mime_part_get_content (GMIME_PART (pkcs7_mime));
+       content = g_mime_part_get_content ((GMimePart *) pkcs7_mime);
        ciphertext = g_mime_stream_mem_new ();
        g_mime_data_wrapper_write_to_stream (content, ciphertext);
        g_mime_stream_reset (ciphertext);
        
        stream = g_mime_stream_mem_new ();
-       filtered_stream = g_mime_stream_filter_new (stream);
-       crlf_filter = g_mime_filter_crlf_new (FALSE, FALSE);
-       g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), crlf_filter);
-       g_object_unref (crlf_filter);
+       filtered = g_mime_stream_filter_new (stream);
+       filter = g_mime_filter_crlf_new (FALSE, FALSE);
+       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+       g_object_unref (filter);
        
        /* decrypt the content stream */
-       if (!(res = g_mime_crypto_context_decrypt (ctx, flags, session_key, ciphertext, filtered_stream, 
err))) {
-               g_object_unref (filtered_stream);
+       if (!(res = g_mime_crypto_context_decrypt (ctx, flags, session_key, ciphertext, filtered, err))) {
                g_object_unref (ciphertext);
+               g_object_unref (filtered);
                g_object_unref (stream);
                g_object_unref (ctx);
                
                return NULL;
        }
        
-       g_mime_stream_flush (filtered_stream);
-       g_object_unref (filtered_stream);
+       g_mime_stream_flush (filtered);
        g_object_unref (ciphertext);
+       g_object_unref (filtered);
        g_object_unref (ctx);
        
        g_mime_stream_reset (stream);
@@ -398,12 +401,13 @@ g_mime_application_pkcs7_mime_decrypt (GMimeApplicationPkcs7Mime *pkcs7_mime,
 GMimeApplicationPkcs7Mime *
 g_mime_application_pkcs7_mime_sign (GMimeObject *entity, const char *userid, GError **err)
 {
-       GMimeStream *filtered_stream, *ciphertext, *stream;
+       GMimeStream *filtered, *ciphertext, *stream;
        GMimeApplicationPkcs7Mime *pkcs7_mime;
        GMimeContentType *content_type;
+       GMimeFormatOptions *options;
        GMimeDataWrapper *content;
-       GMimeFilter *crlf_filter;
        GMimeCryptoContext *ctx;
+       GMimeFilter *filter;
        
        g_return_val_if_fail (GMIME_IS_OBJECT (entity), NULL);
        g_return_val_if_fail (userid != NULL, NULL);
@@ -415,17 +419,19 @@ g_mime_application_pkcs7_mime_sign (GMimeObject *entity, const char *userid, GEr
                return NULL;
        }
        
+       options = g_mime_format_options_get_default ();
+       
        /* get the cleartext */
        stream = g_mime_stream_mem_new ();
-       filtered_stream = g_mime_stream_filter_new (stream);
+       filtered = g_mime_stream_filter_new (stream);
        
-       crlf_filter = g_mime_filter_crlf_new (TRUE, FALSE);
-       g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), crlf_filter);
-       g_object_unref (crlf_filter);
+       filter = g_mime_filter_crlf_new (TRUE, FALSE);
+       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+       g_object_unref (filter);
        
-       g_mime_object_write_to_stream (entity, filtered_stream);
-       g_mime_stream_flush (filtered_stream);
-       g_object_unref (filtered_stream);
+       g_mime_object_write_to_stream (entity, options, filtered);
+       g_mime_stream_flush (filtered);
+       g_object_unref (filtered);
        
        /* reset the content stream */
        g_mime_stream_reset (stream);
@@ -468,11 +474,11 @@ g_mime_application_pkcs7_mime_sign (GMimeObject *entity, const char *userid, GEr
 GMimeSignatureList *
 g_mime_application_pkcs7_mime_verify (GMimeApplicationPkcs7Mime *pkcs7_mime, GMimeVerifyFlags flags, 
GMimeObject **entity, GError **err)
 {
-       GMimeStream *filtered_stream, *ciphertext, *stream;
+       GMimeStream *filtered, *ciphertext, *stream;
        GMimeSignatureList *signatures;
        GMimeDataWrapper *content;
-       GMimeFilter *crlf_filter;
        GMimeCryptoContext *ctx;
+       GMimeFilter *filter;
        GMimeParser *parser;
        
        g_return_val_if_fail (GMIME_IS_APPLICATION_PKCS7_MIME (pkcs7_mime), NULL);
@@ -494,24 +500,24 @@ g_mime_application_pkcs7_mime_verify (GMimeApplicationPkcs7Mime *pkcs7_mime, GMi
        g_mime_stream_reset (ciphertext);
        
        stream = g_mime_stream_mem_new ();
-       filtered_stream = g_mime_stream_filter_new (stream);
-       crlf_filter = g_mime_filter_crlf_new (FALSE, FALSE);
-       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered_stream, crlf_filter);
-       g_object_unref (crlf_filter);
+       filtered = g_mime_stream_filter_new (stream);
+       filter = g_mime_filter_crlf_new (FALSE, FALSE);
+       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+       g_object_unref (filter);
        
        /* decrypt the content stream */
-       if (!(signatures = g_mime_crypto_context_verify (ctx, flags, ciphertext, NULL, filtered_stream, 
err))) {
-               g_object_unref (filtered_stream);
+       if (!(signatures = g_mime_crypto_context_verify (ctx, flags, ciphertext, NULL, filtered, err))) {
                g_object_unref (ciphertext);
+               g_object_unref (filtered);
                g_object_unref (stream);
                g_object_unref (ctx);
                
                return NULL;
        }
        
-       g_mime_stream_flush (filtered_stream);
-       g_object_unref (filtered_stream);
+       g_mime_stream_flush (filtered);
        g_object_unref (ciphertext);
+       g_object_unref (filtered);
        g_object_unref (ctx);
        
        g_mime_stream_reset (stream);
diff --git a/gmime/gmime-content-type.c b/gmime/gmime-content-type.c
index 4d822cb..5b3b617 100644
--- a/gmime/gmime-content-type.c
+++ b/gmime/gmime-content-type.c
@@ -244,13 +244,14 @@ g_mime_content_type_get_mime_type (GMimeContentType *content_type)
 /**
  * g_mime_content_type_encode:
  * @content_type: a #GMimeContentType
+ * @options: a #GMimeFormatOptions
  *
  * Encodes the Content-Disposition header.
  *
  * Returns: a new string containing the encoded header value.
  **/
 char *
-g_mime_content_type_encode (GMimeContentType *content_type)
+g_mime_content_type_encode (GMimeContentType *content_type, GMimeFormatOptions *options)
 {
        char *raw_value;
        GString *str;
@@ -267,7 +268,7 @@ g_mime_content_type_encode (GMimeContentType *content_type)
        g_string_append_c (str, '/');
        g_string_append (str, content_type->subtype ? content_type->subtype : "plain");
        
-       g_mime_param_list_encode (content_type->params, TRUE, str);
+       g_mime_param_list_encode (content_type->params, options, TRUE, str);
        len = str->len - n;
        
        raw_value = g_string_free (str, FALSE);
diff --git a/gmime/gmime-content-type.h b/gmime/gmime-content-type.h
index 983a54b..d763b8d 100644
--- a/gmime/gmime-content-type.h
+++ b/gmime/gmime-content-type.h
@@ -70,7 +70,7 @@ GMimeContentType *g_mime_content_type_parse (GMimeParserOptions *options, const
 
 char *g_mime_content_type_get_mime_type (GMimeContentType *content_type);
 
-char *g_mime_content_type_encode (GMimeContentType *content_type);
+char *g_mime_content_type_encode (GMimeContentType *content_type, GMimeFormatOptions *options);
 
 gboolean g_mime_content_type_is_type (GMimeContentType *content_type, const char *type, const char *subtype);
 
diff --git a/gmime/gmime-disposition.c b/gmime/gmime-disposition.c
index 6ab38d9..fb4026d 100644
--- a/gmime/gmime-disposition.c
+++ b/gmime/gmime-disposition.c
@@ -306,13 +306,14 @@ g_mime_content_disposition_is_attachment (GMimeContentDisposition *disposition)
 /**
  * g_mime_content_disposition_encode:
  * @disposition: a #GMimeContentDisposition object
+ * @options: a #GMimeFormatOptions
  *
  * Encodes the Content-Disposition header.
  *
  * Returns: a new string containing the encoded header value.
  **/
 char *
-g_mime_content_disposition_encode (GMimeContentDisposition *disposition)
+g_mime_content_disposition_encode (GMimeContentDisposition *disposition, GMimeFormatOptions *options)
 {
        char *raw_value;
        GString *str;
@@ -326,7 +327,7 @@ g_mime_content_disposition_encode (GMimeContentDisposition *disposition)
        
        g_string_append_c (str, ' ');
        g_string_append (str, disposition->disposition);
-       g_mime_param_list_encode (disposition->params, TRUE, str);
+       g_mime_param_list_encode (disposition->params, options, TRUE, str);
        len = str->len - n;
        
        raw_value = g_string_free (str, FALSE);
diff --git a/gmime/gmime-disposition.h b/gmime/gmime-disposition.h
index 6007c76..347dc4c 100644
--- a/gmime/gmime-disposition.h
+++ b/gmime/gmime-disposition.h
@@ -96,7 +96,7 @@ const char *g_mime_content_disposition_get_parameter (GMimeContentDisposition *d
 
 gboolean g_mime_content_disposition_is_attachment (GMimeContentDisposition *disposition);
 
-char *g_mime_content_disposition_encode (GMimeContentDisposition *disposition);
+char *g_mime_content_disposition_encode (GMimeContentDisposition *disposition, GMimeFormatOptions *options);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-format-options.h b/gmime/gmime-format-options.h
index aa450ca..83c4366 100644
--- a/gmime/gmime-format-options.h
+++ b/gmime/gmime-format-options.h
@@ -23,7 +23,6 @@
 #define __GMIME_FORMAT_OPTIONS_H__
 
 #include <glib.h>
-#include <gmime/gmime-param.h>
 #include <gmime/gmime-filter.h>
 
 G_BEGIN_DECLS
@@ -44,6 +43,26 @@ typedef enum {
        GMIME_NEWLINE_FORMAT_DOS
 } GMimeNewLineFormat;
 
+
+/**
+ * GMimeParamEncodingMethod:
+ * @GMIME_PARAM_ENCODING_METHOD_DEFAULT: Use the default encoding method set on the #GMimeFormatOptions.
+ * @GMIME_PARAM_ENCODING_METHOD_RFC2231: Use the encoding method described in rfc2231.
+ * @GMIME_PARAM_ENCODING_METHOD_RFC2047: Use the encoding method described in rfc2047.
+ *
+ * The MIME specifications specify that the proper method for encoding Content-Type and
+ * Content-Disposition parameter values is the method described in
+ * <a href="https://tools.ietf.org/html/rfc2231";>rfc2231</a>. However, it is common for
+ * some older email clients to improperly encode using the method described in
+ * <a href="https://tools.ietf.org/html/rfc2047";>rfc2047</a> instead.
+ **/
+typedef enum {
+       GMIME_PARAM_ENCODING_METHOD_DEFAULT = 0,
+       GMIME_PARAM_ENCODING_METHOD_RFC2231 = 1,
+       GMIME_PARAM_ENCODING_METHOD_RFC2047 = 2
+} GMimeParamEncodingMethod;
+
+
 /**
  * GMimeFormatOptions:
  * @method: The method to use for parameter encoding.
diff --git a/gmime/gmime-header.c b/gmime/gmime-header.c
index 0488476..53efad5 100644
--- a/gmime/gmime-header.c
+++ b/gmime/gmime-header.c
@@ -263,12 +263,13 @@ _g_mime_header_set_offset (GMimeHeader *header, gint64 offset)
 }
 
 static ssize_t
-default_writer (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+default_writer (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+               const char *name, const char *value)
 {
        ssize_t nwritten;
        char *val;
        
-       val = g_mime_utils_header_printf (options, "%s: %s\n", name, value);
+       val = g_mime_utils_header_printf (options, format, "%s: %s\n", name, value);
        nwritten = g_mime_stream_write_string (stream, val);
        g_free (val);
        
@@ -278,7 +279,9 @@ default_writer (GMimeParserOptions *options, GMimeStream *stream, const char *na
 
 /**
  * g_mime_header_write_to_stream:
+ * @headers: the #GMimeHeaderList that contains @header
  * @header: a #GMimeHeader
+ * @options: a #GMimeFormatOptions
  * @stream: a #GMimeStream
  *
  * Write the header to the specified stream.
@@ -286,7 +289,8 @@ default_writer (GMimeParserOptions *options, GMimeStream *stream, const char *na
  * Returns: the number of bytes written, or %-1 on fail.
  **/
 ssize_t
-g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header, GMimeStream *stream)
+g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header,
+                              GMimeFormatOptions *options, GMimeStream *stream)
 {
        ssize_t nwritten, total = 0;
        GMimeHeaderWriter writer;
@@ -309,7 +313,7 @@ g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header, GM
                if (!(writer = g_hash_table_lookup (headers->writers, header->name)))
                        writer = default_writer;
                
-               if ((nwritten = writer (headers->options, stream, header->name, header->value)) == -1)
+               if ((nwritten = writer (headers->options, options, stream, header->name, header->value)) == 
-1)
                        return -1;
                
                total += nwritten;
@@ -834,6 +838,7 @@ g_mime_header_list_remove_at (GMimeHeaderList *headers, int index)
 /**
  * g_mime_header_list_write_to_stream:
  * @headers: a #GMimeHeaderList
+ * @options: a #GMimeFormatOptions
  * @stream: output stream
  *
  * Write the headers to a stream.
@@ -841,19 +846,19 @@ g_mime_header_list_remove_at (GMimeHeaderList *headers, int index)
  * Returns: the number of bytes written or %-1 on fail.
  **/
 ssize_t
-g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *stream)
+g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeFormatOptions *options, GMimeStream 
*stream)
 {
        ssize_t nwritten, total = 0;
        GMimeHeader *header;
        guint i;
        
        g_return_val_if_fail (GMIME_IS_HEADER_LIST (headers), -1);
-       g_return_val_if_fail (stream != NULL, -1);
+       g_return_val_if_fail (GMIME_IS_STREAM (stream), -1);
        
        for (i = 0; i < headers->array->len; i++) {
                header = (GMimeHeader *) headers->array->pdata[i];
                
-               if ((nwritten = g_mime_header_write_to_stream (headers, header, stream)) == -1)
+               if ((nwritten = g_mime_header_write_to_stream (headers, header, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
@@ -866,6 +871,7 @@ g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *strea
 /**
  * g_mime_header_list_to_string:
  * @headers: a #GMimeHeaderList
+ * @options: a #GMimeFormatOptions
  *
  * Allocates a string buffer containing the raw rfc822 headers
  * contained in @headers.
@@ -873,7 +879,7 @@ g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *strea
  * Returns: a string containing the header block.
  **/
 char *
-g_mime_header_list_to_string (GMimeHeaderList *headers)
+g_mime_header_list_to_string (GMimeHeaderList *headers, GMimeFormatOptions *options)
 {
        GMimeStream *stream;
        GByteArray *array;
@@ -884,7 +890,7 @@ g_mime_header_list_to_string (GMimeHeaderList *headers)
        array = g_byte_array_new ();
        stream = g_mime_stream_mem_new ();
        g_mime_stream_mem_set_byte_array (GMIME_STREAM_MEM (stream), array);
-       g_mime_header_list_write_to_stream (headers, stream);
+       g_mime_header_list_write_to_stream (headers, options, stream);
        g_object_unref (stream);
        
        g_byte_array_append (array, (unsigned char *) "", 1);
diff --git a/gmime/gmime-header.h b/gmime/gmime-header.h
index 7a9ffe2..26e45e6 100644
--- a/gmime/gmime-header.h
+++ b/gmime/gmime-header.h
@@ -23,6 +23,7 @@
 #define __GMIME_HEADER_H__
 
 #include <glib.h>
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 #include <gmime/gmime-stream.h>
 
@@ -52,6 +53,7 @@ typedef struct _GMimeHeaderListClass GMimeHeaderListClass;
 /**
  * GMimeHeaderWriter:
  * @options: The #GMimeParserOptions
+ * @format: The #GMimeFormatOptions
  * @stream: The output stream.
  * @name: The field name.
  * @value: The field value.
@@ -61,7 +63,8 @@ typedef struct _GMimeHeaderListClass GMimeHeaderListClass;
  *
  * Returns: the number of bytes written or %-1 on error.
  **/
-typedef ssize_t (* GMimeHeaderWriter) (GMimeParserOptions *options, GMimeStream *stream, const char *name, 
const char *value);
+typedef ssize_t (* GMimeHeaderWriter) (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream 
*stream,
+                                      const char *name, const char *value);
 
 
 /**
@@ -98,7 +101,8 @@ void g_mime_header_set_value (GMimeHeader *header, const char *value);
 
 gint64 g_mime_header_get_offset (GMimeHeader *header);
 
-ssize_t g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header, GMimeStream *stream);
+ssize_t g_mime_header_write_to_stream (GMimeHeaderList *headers, GMimeHeader *header,
+                                      GMimeFormatOptions *options, GMimeStream *stream);
 
 
 /**
@@ -139,8 +143,8 @@ gboolean g_mime_header_list_remove (GMimeHeaderList *headers, const char *name);
 void g_mime_header_list_remove_at (GMimeHeaderList *headers, int index);
 
 void g_mime_header_list_register_writer (GMimeHeaderList *headers, const char *name, GMimeHeaderWriter 
writer);
-ssize_t g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeStream *stream);
-char *g_mime_header_list_to_string (GMimeHeaderList *headers);
+ssize_t g_mime_header_list_write_to_stream (GMimeHeaderList *headers, GMimeFormatOptions *options, 
GMimeStream *stream);
+char *g_mime_header_list_to_string (GMimeHeaderList *headers, GMimeFormatOptions *options);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-internal.h b/gmime/gmime-internal.h
index 8afc1c7..4cb7766 100644
--- a/gmime/gmime-internal.h
+++ b/gmime/gmime-internal.h
@@ -22,6 +22,7 @@
 #ifndef __GMIME_INTERNAL_H__
 #define __GMIME_INTERNAL_H__
 
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 #include <gmime/gmime-object.h>
 #include <gmime/gmime-events.h>
@@ -42,6 +43,11 @@ typedef struct {
 } GMimeHeaderListChangedEventArgs;
 
 /* GMimeParserOptions */
+G_GNUC_INTERNAL void g_mime_format_options_init (void);
+G_GNUC_INTERNAL void g_mime_format_options_shutdown (void);
+G_GNUC_INTERNAL GMimeFormatOptions *_g_mime_format_options_clone (GMimeFormatOptions *options);
+
+/* GMimeParserOptions */
 G_GNUC_INTERNAL void g_mime_parser_options_init (void);
 G_GNUC_INTERNAL void g_mime_parser_options_shutdown (void);
 G_GNUC_INTERNAL GMimeParserOptions *_g_mime_parser_options_clone (GMimeParserOptions *options);
@@ -67,8 +73,10 @@ G_GNUC_INTERNAL void _g_mime_object_append_header (GMimeObject *object, const ch
 G_GNUC_INTERNAL void _g_mime_object_set_header (GMimeObject *object, const char *header, const char *value, 
const char *raw_value, gint64 offset);
 
 /* utils */
-G_GNUC_INTERNAL char *_g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char 
*field, const char *value);
-G_GNUC_INTERNAL char *_g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *field, 
const char *value);
+G_GNUC_INTERNAL char *_g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, 
GMimeFormatOptions *format,
+                                                             const char *field, const char *value);
+G_GNUC_INTERNAL char *_g_mime_utils_structured_header_fold (GMimeParserOptions *options, GMimeFormatOptions 
*format,
+                                                           const char *field, const char *value);
 G_GNUC_INTERNAL char *_g_mime_utils_header_decode_text (GMimeParserOptions *options, const char *text, const 
char **charset);
 G_GNUC_INTERNAL char *_g_mime_utils_header_decode_phrase (GMimeParserOptions *options, const char *text, 
const char **charset);
 
diff --git a/gmime/gmime-message-part.c b/gmime/gmime-message-part.c
index 4c85d2d..53a5fa2 100644
--- a/gmime/gmime-message-part.c
+++ b/gmime/gmime-message-part.c
@@ -47,7 +47,8 @@ static void g_mime_message_part_init (GMimeMessagePart *message_part, GMimeMessa
 static void g_mime_message_part_finalize (GObject *object);
 
 /* GMimeObject class methods */
-static ssize_t message_part_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean 
content_only);
+static ssize_t message_part_write_to_stream (GMimeObject *object, GMimeFormatOptions *options,
+                                            gboolean content_only, GMimeStream *stream);
 
 
 static GMimeObjectClass *parent_class = NULL;
@@ -109,14 +110,14 @@ g_mime_message_part_finalize (GObject *object)
 }
 
 static ssize_t
-message_part_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only)
+message_part_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean content_only, 
GMimeStream *stream)
 {
        GMimeMessagePart *part = (GMimeMessagePart *) object;
        ssize_t nwritten, total = 0;
        
        if (!content_only) {
                /* write the content headers */
-               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, stream)) == -1)
+               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
@@ -130,7 +131,7 @@ message_part_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean
        
        /* write the message */
        if (part->message) {
-               if ((nwritten = g_mime_object_write_to_stream (GMIME_OBJECT (part->message), stream)) == -1)
+               if ((nwritten = g_mime_object_write_to_stream ((GMimeObject *) part->message, options, 
stream)) == -1)
                        return -1;
                
                total += nwritten;
diff --git a/gmime/gmime-message-partial.c b/gmime/gmime-message-partial.c
index d7076bd..14e31de 100644
--- a/gmime/gmime-message-partial.c
+++ b/gmime/gmime-message-partial.c
@@ -368,6 +368,7 @@ g_mime_message_partial_split_message (GMimeMessage *message, size_t max_size, si
        GMimeMessage **messages;
        GMimeMessagePartial *partial;
        GMimeStream *stream, *substream;
+       GMimeFormatOptions *options;
        GMimeDataWrapper *wrapper;
        const unsigned char *buf;
        GPtrArray *parts;
@@ -380,8 +381,10 @@ g_mime_message_partial_split_message (GMimeMessage *message, size_t max_size, si
        
        g_return_val_if_fail (GMIME_IS_MESSAGE (message), NULL);
        
+       options = g_mime_format_options_get_default ();
        stream = g_mime_stream_mem_new ();
-       if (g_mime_object_write_to_stream (GMIME_OBJECT (message), stream) == -1) {
+       
+       if (g_mime_object_write_to_stream ((GMimeObject *) message, options, stream) == -1) {
                g_object_unref (stream);
                return NULL;
        }
diff --git a/gmime/gmime-message.c b/gmime/gmime-message.c
index b5330ea..15cf274 100644
--- a/gmime/gmime-message.c
+++ b/gmime/gmime-message.c
@@ -60,16 +60,23 @@ static void message_header_changed  (GMimeObject *object, GMimeHeader *header);
 static void message_header_removed  (GMimeObject *object, GMimeHeader *header);
 static void message_headers_cleared (GMimeObject *object);
 
-static char *message_get_headers (GMimeObject *object);
-static ssize_t message_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only);
+static char *message_get_headers (GMimeObject *object, GMimeFormatOptions *options);
+static ssize_t message_write_to_stream (GMimeObject *object, GMimeFormatOptions *options,
+                                       gboolean content_only, GMimeStream *stream);
 static void message_encode (GMimeObject *object, GMimeEncodingConstraint constraint);
 
-/*static ssize_t write_structured (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);*/
-static ssize_t write_references (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);
-static ssize_t write_addrspec (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);
-static ssize_t write_received (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);
-static ssize_t write_subject (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char 
*value);
-static ssize_t write_msgid (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char 
*value);
+/*static ssize_t write_structured (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream 
*stream,
+  const char *name, const char *value);*/
+static ssize_t write_references (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream 
*stream,
+                                const char *name, const char *value);
+static ssize_t write_addrspec (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                              const char *name, const char *value);
+static ssize_t write_received (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                              const char *name, const char *value);
+static ssize_t write_subject (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                             const char *name, const char *value);
+static ssize_t write_msgid (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                           const char *name, const char *value);
 
 
 static void sender_changed (InternetAddressList *list, gpointer args, GMimeMessage *message);
@@ -416,7 +423,8 @@ struct _received_part {
 };
 
 static ssize_t
-write_received (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_received (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+               const char *name, const char *value)
 {
        struct _received_part *parts, *part, *tail;
        const char *inptr, *lwsp = NULL;
@@ -529,12 +537,13 @@ write_received (GMimeParserOptions *options, GMimeStream *stream, const char *na
 }
 
 static ssize_t
-write_subject (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_subject (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+              const char *name, const char *value)
 {
        char *folded;
        ssize_t n;
        
-       folded = _g_mime_utils_unstructured_header_fold (options, name, value);
+       folded = _g_mime_utils_unstructured_header_fold (options, format, name, value);
        n = g_mime_stream_write_string (stream, folded);
        g_free (folded);
        
@@ -542,7 +551,8 @@ write_subject (GMimeParserOptions *options, GMimeStream *stream, const char *nam
 }
 
 static ssize_t
-write_msgid (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_msgid (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+            const char *name, const char *value)
 {
        /* Note: we don't want to wrap the Message-Id header - seems to
           break a lot of clients (and servers) */
@@ -550,7 +560,8 @@ write_msgid (GMimeParserOptions *options, GMimeStream *stream, const char *name,
 }
 
 static ssize_t
-write_references (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_references (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                 const char *name, const char *value)
 {
        GMimeReferences *references, *reference;
        ssize_t nwritten;
@@ -594,12 +605,13 @@ write_references (GMimeParserOptions *options, GMimeStream *stream, const char *
 
 #if 0
 static ssize_t
-write_structured (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_structured (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                 const char *name, const char *value)
 {
        char *folded;
        ssize_t n;
        
-       folded = _g_mime_utils_structured_header_fold (options, name, value);
+       folded = _g_mime_utils_structured_header_fold (options, format, name, value);
        n = g_mime_stream_write_string (stream, folded);
        g_free (folded);
        
@@ -608,7 +620,8 @@ write_structured (GMimeParserOptions *options, GMimeStream *stream, const char *
 #endif
 
 static ssize_t
-write_addrspec (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_addrspec (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+               const char *name, const char *value)
 {
        InternetAddressList *addrlist;
        GString *str;
@@ -618,7 +631,7 @@ write_addrspec (GMimeParserOptions *options, GMimeStream *stream, const char *na
        g_string_append (str, ": ");
        
        if (value && (addrlist = internet_address_list_parse (options, value))) {
-               internet_address_list_writer (addrlist, str);
+               internet_address_list_writer (addrlist, format, str);
                g_object_unref (addrlist);
        }
        
@@ -846,7 +859,7 @@ message_headers_cleared (GMimeObject *object)
 
 
 static ssize_t
-write_headers_to_stream (GMimeObject *object, GMimeStream *stream)
+write_headers_to_stream (GMimeObject *object, GMimeFormatOptions *options, GMimeStream *stream)
 {
        GMimeMessage *message = (GMimeMessage *) object;
        GMimeObject *mime_part = message->mime_part;
@@ -869,13 +882,13 @@ write_headers_to_stream (GMimeObject *object, GMimeStream *stream)
                        offset = g_mime_header_get_offset (header);
                        
                        if (offset >= 0 && offset < body_offset) {
-                               if ((nwritten = g_mime_header_write_to_stream (object->headers, header, 
stream)) == -1)
+                               if ((nwritten = g_mime_header_write_to_stream (object->headers, header, 
options, stream)) == -1)
                                        return -1;
                                
                                total += nwritten;
                                index++;
                        } else {
-                               if ((nwritten = g_mime_header_write_to_stream (mime_part->headers, 
body_header, stream)) == -1)
+                               if ((nwritten = g_mime_header_write_to_stream (mime_part->headers, 
body_header, options, stream)) == -1)
                                        return -1;
                                
                                total += nwritten;
@@ -886,7 +899,7 @@ write_headers_to_stream (GMimeObject *object, GMimeStream *stream)
                while (index < count) {
                        header = g_mime_header_list_get_header_at (object->headers, index);
                        
-                       if ((nwritten = g_mime_header_write_to_stream (object->headers, header, stream)) == 
-1)
+                       if ((nwritten = g_mime_header_write_to_stream (object->headers, header, options, 
stream)) == -1)
                                return -1;
                        
                        total += nwritten;
@@ -896,7 +909,7 @@ write_headers_to_stream (GMimeObject *object, GMimeStream *stream)
                while (body_index < body_count) {
                        header = g_mime_header_list_get_header_at (mime_part->headers, body_index);
                        
-                       if ((nwritten = g_mime_header_write_to_stream (mime_part->headers, header, stream)) 
== -1)
+                       if ((nwritten = g_mime_header_write_to_stream (mime_part->headers, header, options, 
stream)) == -1)
                                return -1;
                        
                        total += nwritten;
@@ -906,12 +919,12 @@ write_headers_to_stream (GMimeObject *object, GMimeStream *stream)
                return total;
        }
        
-       return g_mime_header_list_write_to_stream (object->headers, stream);
+       return g_mime_header_list_write_to_stream (object->headers, options, stream);
 }
 
 
 static char *
-message_get_headers (GMimeObject *object)
+message_get_headers (GMimeObject *object, GMimeFormatOptions *options)
 {
        GMimeStream *stream;
        GByteArray *ba;
@@ -919,8 +932,8 @@ message_get_headers (GMimeObject *object)
        
        ba = g_byte_array_new ();
        stream = g_mime_stream_mem_new ();
-       g_mime_stream_mem_set_byte_array (GMIME_STREAM_MEM (stream), ba);
-       write_headers_to_stream (object, stream);
+       g_mime_stream_mem_set_byte_array ((GMimeStreamMem *) stream, ba);
+       write_headers_to_stream (object, options, stream);
        g_object_unref (stream);
        g_byte_array_append (ba, (unsigned char *) "", 1);
        str = (char *) ba->data;
@@ -930,14 +943,14 @@ message_get_headers (GMimeObject *object)
 }
 
 static ssize_t
-message_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only)
+message_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean content_only, 
GMimeStream *stream)
 {
        GMimeMessage *message = (GMimeMessage *) object;
        GMimeObject *mime_part = message->mime_part;
        ssize_t nwritten, total = 0;
        
        if (!content_only) {
-               if ((nwritten = write_headers_to_stream (object, stream)) == -1)
+               if ((nwritten = write_headers_to_stream (object, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
@@ -949,7 +962,9 @@ message_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean cont
        }
        
        if (mime_part) {
-               if ((nwritten = GMIME_OBJECT_GET_CLASS (mime_part)->write_to_stream (mime_part, stream, 
TRUE)) == -1)
+               GMimeObjectClass *klass = GMIME_OBJECT_GET_CLASS (mime_part);
+               
+               if ((nwritten = klass->write_to_stream (mime_part, options, TRUE, stream)) == -1)
                        return -1;
                
                total += nwritten;
@@ -1108,10 +1123,11 @@ g_mime_message_get_bcc (GMimeMessage *message)
 static void
 sync_internet_address_list (InternetAddressList *list, GMimeMessage *message, const char *name)
 {
+       GMimeFormatOptions *options = g_mime_format_options_get_default ();
        GMimeObject *object = (GMimeObject *) message;
        char *string;
        
-       string = internet_address_list_to_string (list, TRUE);
+       string = internet_address_list_to_string (list, options, TRUE);
        
        _g_mime_object_block_header_list_changed (object);
        g_mime_header_list_set (object->headers, name, string);
@@ -1261,6 +1277,7 @@ g_mime_message_get_all_recipients (GMimeMessage *message)
 void
 g_mime_message_set_subject (GMimeMessage *message, const char *subject, const char *charset)
 {
+       GMimeFormatOptions *options;
        char *encoded;
        
        g_return_if_fail (GMIME_IS_MESSAGE (message));
@@ -1269,8 +1286,9 @@ g_mime_message_set_subject (GMimeMessage *message, const char *subject, const ch
        g_free (message->subject);
        message->subject = g_mime_strdup_trim (subject);
        
-       encoded = g_mime_utils_header_encode_text (message->subject, charset);
-       g_mime_object_set_header (GMIME_OBJECT (message), "Subject", encoded);
+       options = g_mime_format_options_get_default ();
+       encoded = g_mime_utils_header_encode_text (options, message->subject, charset);
+       g_mime_object_set_header ((GMimeObject *) message, "Subject", encoded);
        g_free (encoded);
 }
 
diff --git a/gmime/gmime-multipart-encrypted.c b/gmime/gmime-multipart-encrypted.c
index 7918325..dcc362b 100644
--- a/gmime/gmime-multipart-encrypted.c
+++ b/gmime/gmime-multipart-encrypted.c
@@ -159,6 +159,7 @@ g_mime_multipart_encrypted_encrypt (GMimeCryptoContext *ctx, GMimeObject *entity
                                    GMimeEncryptFlags flags, GPtrArray *recipients, GError **err)
 {
        GMimeParserOptions *options = g_mime_parser_options_get_default ();
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeStream *filtered, *stream, *ciphertext;
        GMimePart *version_part, *encrypted_part;
        GMimeMultipartEncrypted *encrypted;
@@ -183,7 +184,7 @@ g_mime_multipart_encrypted_encrypt (GMimeCryptoContext *ctx, GMimeObject *entity
        g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
        g_object_unref (filter);
        
-       g_mime_object_write_to_stream (entity, filtered);
+       g_mime_object_write_to_stream (entity, format, filtered);
        g_mime_stream_flush (filtered);
        g_object_unref (filtered);
        
diff --git a/gmime/gmime-multipart-signed.c b/gmime/gmime-multipart-signed.c
index 27ac057..a02bf14 100644
--- a/gmime/gmime-multipart-signed.c
+++ b/gmime/gmime-multipart-signed.c
@@ -212,6 +212,7 @@ g_mime_multipart_signed_sign (GMimeCryptoContext *ctx, GMimeObject *entity,
                              const char *userid, GError **err)
 {
        GMimeParserOptions *options = g_mime_parser_options_get_default ();
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeStream *stream, *filtered, *sigstream;
        GMimeContentType *content_type;
        GMimeDataWrapper *content;
@@ -248,7 +249,7 @@ g_mime_multipart_signed_sign (GMimeCryptoContext *ctx, GMimeObject *entity,
        g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
        g_object_unref (filter);
        
-       g_mime_object_write_to_stream (entity, filtered);
+       g_mime_object_write_to_stream (entity, format, filtered);
        g_mime_stream_flush (filtered);
        g_mime_stream_reset (stream);
        g_object_unref (filtered);
@@ -367,15 +368,15 @@ check_protocol_supported (const char *protocol, const char *supported)
 GMimeSignatureList *
 g_mime_multipart_signed_verify (GMimeMultipartSigned *mps, GMimeVerifyFlags flags, GError **err)
 {
+       GMimeFormatOptions *options = g_mime_format_options_get_default ();
+       GMimeStream *filtered, *stream, *sigstream;
        const char *supported, *protocol;
        GMimeObject *content, *signature;
-       GMimeStream *stream, *sigstream;
        GMimeSignatureList *signatures;
-       GMimeStream *filtered_stream;
        GMimeDataWrapper *wrapper;
-       GMimeFilter *crlf_filter;
        GMimeCryptoContext *ctx;
        GMimeDigestAlgo digest;
+       GMimeFilter *filter;
        char *mime_type;
        
        g_return_val_if_fail (GMIME_IS_MULTIPART_SIGNED (mps), NULL);
@@ -413,7 +414,7 @@ g_mime_multipart_signed_verify (GMimeMultipartSigned *mps, GMimeVerifyFlags flag
                return NULL;
        }
        
-       signature = g_mime_multipart_get_part (GMIME_MULTIPART (mps), GMIME_MULTIPART_SIGNED_SIGNATURE);
+       signature = g_mime_multipart_get_part ((GMimeMultipart *) mps, GMIME_MULTIPART_SIGNED_SIGNATURE);
        
        /* make sure the protocol matches the signature content-type */
        mime_type = g_mime_content_type_get_mime_type (signature->content_type);
@@ -427,24 +428,24 @@ g_mime_multipart_signed_verify (GMimeMultipartSigned *mps, GMimeVerifyFlags flag
        }
        g_free (mime_type);
        
-       content = g_mime_multipart_get_part (GMIME_MULTIPART (mps), GMIME_MULTIPART_SIGNED_CONTENT);
+       content = g_mime_multipart_get_part ((GMimeMultipart *) mps, GMIME_MULTIPART_SIGNED_CONTENT);
        
        /* get the content stream */
        stream = g_mime_stream_mem_new ();
-       filtered_stream = g_mime_stream_filter_new (stream);
+       filtered = g_mime_stream_filter_new (stream);
        
        /* Note: see rfc2015 or rfc3156, section 5.1 */
-       crlf_filter = g_mime_filter_crlf_new (TRUE, FALSE);
-       g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), crlf_filter);
-       g_object_unref (crlf_filter);
+       filter = g_mime_filter_crlf_new (TRUE, FALSE);
+       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
+       g_object_unref (filter);
        
-       g_mime_object_write_to_stream (content, filtered_stream);
-       g_mime_stream_flush (filtered_stream);
-       g_object_unref (filtered_stream);
+       g_mime_object_write_to_stream (content, options, filtered);
+       g_mime_stream_flush (filtered);
+       g_object_unref (filtered);
        g_mime_stream_reset (stream);
        
        /* get the signature stream */
-       wrapper = g_mime_part_get_content (GMIME_PART (signature));
+       wrapper = g_mime_part_get_content ((GMimePart *) signature);
        
        sigstream = g_mime_stream_mem_new ();
        g_mime_data_wrapper_write_to_stream (wrapper, sigstream);
diff --git a/gmime/gmime-multipart.c b/gmime/gmime-multipart.c
index cb3cfda..4d533cc 100644
--- a/gmime/gmime-multipart.c
+++ b/gmime/gmime-multipart.c
@@ -49,7 +49,8 @@ static void g_mime_multipart_init (GMimeMultipart *multipart, GMimeMultipartClas
 static void g_mime_multipart_finalize (GObject *object);
 
 /* GMimeObject class methods */
-static ssize_t multipart_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only);
+static ssize_t multipart_write_to_stream (GMimeObject *object, GMimeFormatOptions *options,
+                                         gboolean content_only, GMimeStream *stream);
 static void multipart_encode (GMimeObject *object, GMimeEncodingConstraint constraint);
 
 /* GMimeMultipart class methods */
@@ -147,7 +148,7 @@ g_mime_multipart_finalize (GObject *object)
 }
 
 static ssize_t
-multipart_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only)
+multipart_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean content_only, 
GMimeStream *stream)
 {
        GMimeMultipart *multipart = (GMimeMultipart *) object;
        ssize_t nwritten, total = 0;
@@ -159,7 +160,7 @@ multipart_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean co
        
        if (!content_only) {
                /* write the content headers */
-               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, stream)) == -1)
+               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
@@ -194,7 +195,7 @@ multipart_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean co
                total += nwritten;
                
                /* write this part out */
-               if ((nwritten = g_mime_object_write_to_stream (part, stream)) == -1)
+               if ((nwritten = g_mime_object_write_to_stream (part, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
diff --git a/gmime/gmime-object.c b/gmime/gmime-object.c
index a17e662..b321a86 100644
--- a/gmime/gmime-object.c
+++ b/gmime/gmime-object.c
@@ -69,12 +69,14 @@ static void object_header_removed  (GMimeObject *object, GMimeHeader *header);
 static void object_headers_cleared (GMimeObject *object);
 
 static void object_set_content_type (GMimeObject *object, GMimeContentType *content_type);
-static char *object_get_headers (GMimeObject *object);
-static ssize_t object_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only);
+static char *object_get_headers (GMimeObject *object, GMimeFormatOptions *options);
+static ssize_t object_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean 
content_only, GMimeStream *stream);
 static void object_encode (GMimeObject *object, GMimeEncodingConstraint constraint);
 
-static ssize_t write_content_type (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);
-static ssize_t write_disposition (GMimeParserOptions *options, GMimeStream *stream, const char *name, const 
char *value);
+static ssize_t write_content_type (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream 
*stream,
+                                  const char *name, const char *value);
+static ssize_t write_disposition (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream 
*stream,
+                                 const char *name, const char *value);
 
 static void header_list_changed (GMimeHeaderList *headers, GMimeHeaderListChangedEventArgs *args, 
GMimeObject *object);
 static void content_type_changed (GMimeContentType *content_type, gpointer args, GMimeObject *object);
@@ -307,7 +309,8 @@ header_list_changed (GMimeHeaderList *headers, GMimeHeaderListChangedEventArgs *
 }
 
 static ssize_t
-write_content_type (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_content_type (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                   const char *name, const char *value)
 {
        GMimeContentType *content_type;
        ssize_t nwritten;
@@ -318,7 +321,7 @@ write_content_type (GMimeParserOptions *options, GMimeStream *stream, const char
        g_string_append_c (str, ':');
        
        content_type = g_mime_content_type_parse (options, value);
-       raw_value = g_mime_content_type_encode (content_type);
+       raw_value = g_mime_content_type_encode (content_type, format);
        g_object_unref (content_type);
        
        g_string_append (str, raw_value);
@@ -378,10 +381,11 @@ unfold_raw_value (const char *raw_value)
 static void
 content_type_changed (GMimeContentType *content_type, gpointer args, GMimeObject *object)
 {
+       GMimeFormatOptions *options = g_mime_format_options_get_default ();
        char *raw_value, *value;
        GMimeHeader *header;
        
-       raw_value = g_mime_content_type_encode (content_type);
+       raw_value = g_mime_content_type_encode (content_type, options);
        value = unfold_raw_value (raw_value);
        
        _g_mime_object_block_header_list_changed (object);
@@ -394,7 +398,8 @@ content_type_changed (GMimeContentType *content_type, gpointer args, GMimeObject
 }
 
 static ssize_t
-write_disposition (GMimeParserOptions *options, GMimeStream *stream, const char *name, const char *value)
+write_disposition (GMimeParserOptions *options, GMimeFormatOptions *format, GMimeStream *stream,
+                  const char *name, const char *value)
 {
        GMimeContentDisposition *disposition;
        ssize_t nwritten;
@@ -407,7 +412,7 @@ write_disposition (GMimeParserOptions *options, GMimeStream *stream, const char
        disposition = g_mime_content_disposition_parse (options, value);
        g_string_append (str, disposition->disposition);
        
-       g_mime_param_list_encode (disposition->params, TRUE, str);
+       g_mime_param_list_encode (disposition->params, format, TRUE, str);
        g_object_unref (disposition);
        
        nwritten = g_mime_stream_write (stream, str->str, str->len);
@@ -419,13 +424,15 @@ write_disposition (GMimeParserOptions *options, GMimeStream *stream, const char
 static void
 content_disposition_changed (GMimeContentDisposition *disposition, gpointer args, GMimeObject *object)
 {
+       GMimeFormatOptions *options;
        char *raw_value, *value;
        GMimeHeader *header;
        
        _g_mime_object_block_header_list_changed (object);
        
        if (object->disposition) {
-               raw_value = g_mime_content_disposition_encode (object->disposition);
+               options = g_mime_format_options_get_default ();
+               raw_value = g_mime_content_disposition_encode (object->disposition, options);
                value = unfold_raw_value (raw_value);
                
                g_mime_header_list_set (object->headers, "Content-Disposition", value);
@@ -1044,15 +1051,16 @@ g_mime_object_remove_header (GMimeObject *object, const char *header)
 
 
 static char *
-object_get_headers (GMimeObject *object)
+object_get_headers (GMimeObject *object, GMimeFormatOptions *options)
 {
-       return g_mime_header_list_to_string (object->headers);
+       return g_mime_header_list_to_string (object->headers, options);
 }
 
 
 /**
  * g_mime_object_get_headers:
  * @object: a #GMimeObject
+ * @options: a #GMimeFormatOptions
  *
  * Allocates a string buffer containing all of the MIME object's raw
  * headers.
@@ -1062,16 +1070,16 @@ object_get_headers (GMimeObject *object)
  * Note: The returned string will not be suitable for display.
  **/
 char *
-g_mime_object_get_headers (GMimeObject *object)
+g_mime_object_get_headers (GMimeObject *object, GMimeFormatOptions *options)
 {
        g_return_val_if_fail (GMIME_IS_OBJECT (object), NULL);
        
-       return GMIME_OBJECT_GET_CLASS (object)->get_headers (object);
+       return GMIME_OBJECT_GET_CLASS (object)->get_headers (object, options);
 }
 
 
 static ssize_t
-object_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only)
+object_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean content_only, GMimeStream 
*stream)
 {
        return -1;
 }
@@ -1080,6 +1088,7 @@ object_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean conte
 /**
  * g_mime_object_write_to_stream:
  * @object: a #GMimeObject
+ * @options: a #GMimeFormatOptions
  * @stream: stream
  *
  * Write the contents of the MIME object to @stream.
@@ -1087,12 +1096,12 @@ object_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean conte
  * Returns: the number of bytes written or %-1 on fail.
  **/
 ssize_t
-g_mime_object_write_to_stream (GMimeObject *object, GMimeStream *stream)
+g_mime_object_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, GMimeStream *stream)
 {
        g_return_val_if_fail (GMIME_IS_OBJECT (object), -1);
        g_return_val_if_fail (GMIME_IS_STREAM (stream), -1);
        
-       return GMIME_OBJECT_GET_CLASS (object)->write_to_stream (object, stream, FALSE);
+       return GMIME_OBJECT_GET_CLASS (object)->write_to_stream (object, options, FALSE, stream);
 }
 
 
@@ -1124,6 +1133,7 @@ g_mime_object_encode (GMimeObject *object, GMimeEncodingConstraint constraint)
 /**
  * g_mime_object_to_string:
  * @object: a #GMimeObject
+ * @options: a #GMimeFormatOptions
  *
  * Allocates a string buffer containing the contents of @object.
  *
@@ -1131,7 +1141,7 @@ g_mime_object_encode (GMimeObject *object, GMimeEncodingConstraint constraint)
  * object.
  **/
 char *
-g_mime_object_to_string (GMimeObject *object)
+g_mime_object_to_string (GMimeObject *object, GMimeFormatOptions *options)
 {
        GMimeStream *stream;
        GByteArray *array;
@@ -1143,7 +1153,7 @@ g_mime_object_to_string (GMimeObject *object)
        stream = g_mime_stream_mem_new ();
        g_mime_stream_mem_set_byte_array (GMIME_STREAM_MEM (stream), array);
        
-       g_mime_object_write_to_stream (object, stream);
+       g_mime_object_write_to_stream (object, options, stream);
        
        g_object_unref (stream);
        g_byte_array_append (array, (unsigned char *) "", 1);
diff --git a/gmime/gmime-object.h b/gmime/gmime-object.h
index fa32286..ed82fd8 100644
--- a/gmime/gmime-object.h
+++ b/gmime/gmime-object.h
@@ -25,6 +25,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 #include <gmime/gmime-content-type.h>
 #include <gmime/gmime-disposition.h>
@@ -74,9 +75,10 @@ struct _GMimeObjectClass {
        
        void         (* set_content_type) (GMimeObject *object, GMimeContentType *content_type);
        
-       char *       (* get_headers)   (GMimeObject *object);
+       char *       (* get_headers)   (GMimeObject *object, GMimeFormatOptions *options);
        
-       ssize_t      (* write_to_stream) (GMimeObject *object, GMimeStream *stream, gboolean content_only);
+       ssize_t      (* write_to_stream) (GMimeObject *object, GMimeFormatOptions *options,
+                                         gboolean content_only, GMimeStream *stream);
        
        void         (* encode) (GMimeObject *object, GMimeEncodingConstraint constraint);
 };
@@ -126,10 +128,10 @@ gboolean g_mime_object_remove_header (GMimeObject *object, const char *header);
 
 GMimeHeaderList *g_mime_object_get_header_list (GMimeObject *object);
 
-char *g_mime_object_get_headers (GMimeObject *object);
+char *g_mime_object_get_headers (GMimeObject *object, GMimeFormatOptions *options);
 
-ssize_t g_mime_object_write_to_stream (GMimeObject *object, GMimeStream *stream);
-char *g_mime_object_to_string (GMimeObject *object);
+ssize_t g_mime_object_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, GMimeStream 
*stream);
+char *g_mime_object_to_string (GMimeObject *object, GMimeFormatOptions *options);
 
 void g_mime_object_encode (GMimeObject *object, GMimeEncodingConstraint constraint);
 
diff --git a/gmime/gmime-param.c b/gmime/gmime-param.c
index ddb37f4..57d87c9 100644
--- a/gmime/gmime-param.c
+++ b/gmime/gmime-param.c
@@ -610,7 +610,7 @@ g_mime_param_list_remove_at (GMimeParamList *list, int index)
 
 /* FIXME: I wrote this in a quick & dirty fashion - it may not be 100% correct */
 static char *
-encode_param (GMimeParam *param, GMimeParamEncodingMethod *method)
+encode_param (GMimeParam *param, GMimeFormatOptions *options, GMimeParamEncodingMethod *method)
 {
        register const unsigned char *inptr = (const unsigned char *) param->value;
        const unsigned char *start = inptr;
@@ -636,7 +636,7 @@ encode_param (GMimeParam *param, GMimeParamEncodingMethod *method)
        if (param->method == GMIME_PARAM_ENCODING_METHOD_RFC2047) {
                *method = GMIME_PARAM_ENCODING_METHOD_RFC2047;
                
-               return g_mime_utils_header_encode_text (param->value, param->charset);
+               return g_mime_utils_header_encode_text (options, param->value, param->charset);
        }
        
        *method = GMIME_PARAM_ENCODING_METHOD_RFC2231;
@@ -712,13 +712,14 @@ g_string_append_len_quoted (GString *str, const char *text, size_t len)
 /**
  * g_mime_param_list_encode:
  * @list: a #GMimeParamList
+ * @options: a #GMimeFormatOptions
  * @fold: %TRUE if the parameter list should be folded; otherwise, %FALSE
  * @str: the output string buffer
  *
  * Encodes the parameter list into @str, folding lines if required.
  **/
 void
-g_mime_param_list_encode (GMimeParamList *list, gboolean fold, GString *str)
+g_mime_param_list_encode (GMimeParamList *list, GMimeFormatOptions *options, gboolean fold, GString *str)
 {
        guint count, i;
        int used;
@@ -743,7 +744,7 @@ g_mime_param_list_encode (GMimeParamList *list, gboolean fold, GString *str)
                if (!param->value)
                        continue;
                
-               if (!(value = encode_param (param, &method))) {
+               if (!(value = encode_param (param, options, &method))) {
                        w(g_warning ("appending parameter %s=%s violates rfc2184",
                                     param->name, param->value));
                        value = g_strdup (param->value);
diff --git a/gmime/gmime-param.h b/gmime/gmime-param.h
index b589e62..734f1f4 100644
--- a/gmime/gmime-param.h
+++ b/gmime/gmime-param.h
@@ -24,6 +24,7 @@
 
 #include <glib.h>
 #include <glib-object.h>
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 
 G_BEGIN_DECLS
@@ -50,25 +51,6 @@ typedef struct _GMimeParamListClass GMimeParamListClass;
 
 
 /**
- * GMimeParamEncodingMethod:
- * @GMIME_PARAM_ENCODING_METHOD_DEFAULT: Use the default encoding method set on the #GMimeFormatOptions.
- * @GMIME_PARAM_ENCODING_METHOD_RFC2231: Use the encoding method described in rfc2231.
- * @GMIME_PARAM_ENCODING_METHOD_RFC2047: Use the encoding method described in rfc2047.
- *
- * The MIME specifications specify that the proper method for encoding Content-Type and
- * Content-Disposition parameter values is the method described in
- * <a href="https://tools.ietf.org/html/rfc2231";>rfc2231</a>. However, it is common for
- * some older email clients to improperly encode using the method described in
- * <a href="https://tools.ietf.org/html/rfc2047";>rfc2047</a> instead.
- **/
-typedef enum {
-       GMIME_PARAM_ENCODING_METHOD_DEFAULT = 0,
-       GMIME_PARAM_ENCODING_METHOD_RFC2231 = 1,
-       GMIME_PARAM_ENCODING_METHOD_RFC2047 = 2
-} GMimeParamEncodingMethod;
-
-
-/**
  * GMimeParam:
  * @method: The encoding method used for the parameter value.
  * @charset: The charset to use when encoding the parameter value.
@@ -146,7 +128,7 @@ GMimeParam *g_mime_param_list_get_parameter_at (GMimeParamList *list, int index)
 gboolean g_mime_param_list_remove (GMimeParamList *list, const char *name);
 gboolean g_mime_param_list_remove_at (GMimeParamList *list, int index);
 
-void g_mime_param_list_encode (GMimeParamList *list, gboolean fold, GString *str);
+void g_mime_param_list_encode (GMimeParamList *list, GMimeFormatOptions *options, gboolean fold, GString 
*str);
 
 G_END_DECLS
 
diff --git a/gmime/gmime-part.c b/gmime/gmime-part.c
index dfbaa9f..5c6bd33 100644
--- a/gmime/gmime-part.c
+++ b/gmime/gmime-part.c
@@ -66,7 +66,8 @@ static void mime_part_header_changed  (GMimeObject *object, GMimeHeader *header)
 static void mime_part_header_removed  (GMimeObject *object, GMimeHeader *header);
 static void mime_part_headers_cleared (GMimeObject *object);
 
-static ssize_t mime_part_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only);
+static ssize_t mime_part_write_to_stream (GMimeObject *object, GMimeFormatOptions *options,
+                                         gboolean content_only, GMimeStream *stream);
 static void mime_part_encode (GMimeObject *object, GMimeEncodingConstraint constraint);
 
 /* GMimePart class methods */
@@ -312,7 +313,7 @@ write_content (GMimePart *part, GMimeStream *stream)
         */
        
        if (part->encoding != g_mime_data_wrapper_get_encoding (part->content)) {
-               GMimeStream *filtered_stream;
+               GMimeStream *filtered;
                const char *filename;
                GMimeFilter *filter;
                
@@ -329,20 +330,20 @@ write_content (GMimePart *part, GMimeStream *stream)
                        /* fall thru... */
                case GMIME_CONTENT_ENCODING_QUOTEDPRINTABLE:
                case GMIME_CONTENT_ENCODING_BASE64:
-                       filtered_stream = g_mime_stream_filter_new (stream);
+                       filtered = g_mime_stream_filter_new (stream);
                        filter = g_mime_filter_basic_new (part->encoding, TRUE);
-                       g_mime_stream_filter_add (GMIME_STREAM_FILTER (filtered_stream), filter);
+                       g_mime_stream_filter_add ((GMimeStreamFilter *) filtered, filter);
                        g_object_unref (filter);
                        break;
                default:
-                       filtered_stream = stream;
                        g_object_ref (stream);
+                       filtered = stream;
                        break;
                }
                
-               nwritten = g_mime_data_wrapper_write_to_stream (part->content, filtered_stream);
-               g_mime_stream_flush (filtered_stream);
-               g_object_unref (filtered_stream);
+               nwritten = g_mime_data_wrapper_write_to_stream (part->content, filtered);
+               g_mime_stream_flush (filtered);
+               g_object_unref (filtered);
                
                if (nwritten == -1)
                        return -1;
@@ -358,12 +359,12 @@ write_content (GMimePart *part, GMimeStream *stream)
                        total += nwritten;
                }
        } else {
-               GMimeStream *content_stream;
+               GMimeStream *content;
                
-               content_stream = g_mime_data_wrapper_get_stream (part->content);
-               g_mime_stream_reset (content_stream);
-               nwritten = g_mime_stream_write_to_stream (content_stream, stream);
-               g_mime_stream_reset (content_stream);
+               content = g_mime_data_wrapper_get_stream (part->content);
+               g_mime_stream_reset (content);
+               nwritten = g_mime_stream_write_to_stream (content, stream);
+               g_mime_stream_reset (content);
                
                if (nwritten == -1)
                        return -1;
@@ -375,14 +376,14 @@ write_content (GMimePart *part, GMimeStream *stream)
 }
 
 static ssize_t
-mime_part_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean content_only)
+mime_part_write_to_stream (GMimeObject *object, GMimeFormatOptions *options, gboolean content_only, 
GMimeStream *stream)
 {
        GMimePart *mime_part = (GMimePart *) object;
        ssize_t nwritten, total = 0;
        
        if (!content_only) {
                /* write the content headers */
-               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, stream)) == -1)
+               if ((nwritten = g_mime_header_list_write_to_stream (object->headers, options, stream)) == -1)
                        return -1;
                
                total += nwritten;
diff --git a/gmime/gmime-utils.c b/gmime/gmime-utils.c
index 746c55d..9cb7b2e 100644
--- a/gmime/gmime-utils.c
+++ b/gmime/gmime-utils.c
@@ -2614,7 +2614,7 @@ g_string_append_len_quoted (GString *out, const char *in, size_t len)
 }
 
 static char *
-rfc2047_encode (const char *in, gushort safemask, const char *user_charset)
+rfc2047_encode (GMimeFormatOptions *options, const char *in, gushort safemask, const char *user_charset)
 {
        rfc822_word *words, *word, *prev = NULL;
        const char *charset, *start;
@@ -2707,6 +2707,7 @@ rfc2047_encode (const char *in, gushort safemask, const char *user_charset)
 
 /**
  * g_mime_utils_header_encode_phrase:
+ * @options: a #GMimeFormatOptions
  * @phrase: phrase to encode
  * @charset: the charset to use or %NULL to use the default
  *
@@ -2716,17 +2717,18 @@ rfc2047_encode (const char *in, gushort safemask, const char *user_charset)
  * addresses.
  **/
 char *
-g_mime_utils_header_encode_phrase (const char *phrase, const char *charset)
+g_mime_utils_header_encode_phrase (GMimeFormatOptions *options, const char *phrase, const char *charset)
 {
        if (phrase == NULL)
                return NULL;
        
-       return rfc2047_encode (phrase, IS_PSAFE, charset);
+       return rfc2047_encode (options, phrase, IS_PSAFE, charset);
 }
 
 
 /**
  * g_mime_utils_header_encode_text:
+ * @options: a #GMimeFormatOptions
  * @text: text to encode
  * @charset: the charset to use or %NULL to use the default
  *
@@ -2736,17 +2738,18 @@ g_mime_utils_header_encode_phrase (const char *phrase, const char *charset)
  * headers like "Subject".
  **/
 char *
-g_mime_utils_header_encode_text (const char *text, const char *charset)
+g_mime_utils_header_encode_text (GMimeFormatOptions *options, const char *text, const char *charset)
 {
        if (text == NULL)
                return NULL;
        
-       return rfc2047_encode (text, IS_ESAFE, charset);
+       return rfc2047_encode (options, text, IS_ESAFE, charset);
 }
 
 
 static char *
-header_fold_tokens (const char *field, const char *value, size_t vlen, rfc2047_token *tokens, gboolean 
structured)
+header_fold_tokens (GMimeFormatOptions *options, const char *field, const char *value,
+                   size_t vlen, rfc2047_token *tokens, gboolean structured)
 {
        rfc2047_token *token, *next;
        size_t lwsp, tab, len, n;
@@ -2873,15 +2876,16 @@ header_fold_tokens (const char *field, const char *value, size_t vlen, rfc2047_t
 
 /**
  * g_mime_utils_structured_header_fold:
- * @header: header field and value string
  * @options: a #GMimeParserOptions
+ * @format: a #GMimeFormatOptions
+ * @header: header field and value string
  *
  * Folds a structured header according to the rules in rfc822.
  *
  * Returns: an allocated string containing the folded header.
  **/
 char *
-g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *header)
+g_mime_utils_structured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const char 
*header)
 {
        rfc2047_token *tokens;
        const char *value;
@@ -2906,7 +2910,7 @@ g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *he
                value++;
        
        tokens = tokenize_rfc2047_phrase (options, value, &len);
-       folded = header_fold_tokens (field, value, len, tokens, TRUE);
+       folded = header_fold_tokens (format, field, value, len, tokens, TRUE);
        g_free (field);
        
        return folded;
@@ -2916,6 +2920,7 @@ g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *he
 /**
  * _g_mime_utils_structured_header_fold:
  * @options: a #GMimeParserOptions
+ * @format: a #GMimeFormatOptions
  * @field: header field
  * @value: header value
  *
@@ -2924,7 +2929,8 @@ g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *he
  * Returns: an allocated string containing the folded header.
  **/
 char *
-_g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *field, const char *value)
+_g_mime_utils_structured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format,
+                                     const char *field, const char *value)
 {
        rfc2047_token *tokens;
        size_t len;
@@ -2937,13 +2943,14 @@ _g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *f
        
        tokens = tokenize_rfc2047_phrase (options, value, &len);
        
-       return header_fold_tokens (field, value, len, tokens, TRUE);
+       return header_fold_tokens (format, field, value, len, tokens, TRUE);
 }
 
 
 /**
  * g_mime_utils_unstructured_header_fold:
  * @options: a #GMimeParserOptions
+ * @format: a #GMimeFormatOptions
  * @header: header field and value string
  *
  * Folds an unstructured header according to the rules in rfc822.
@@ -2951,7 +2958,7 @@ _g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *f
  * Returns: an allocated string containing the folded header.
  **/
 char *
-g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *header)
+g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const char 
*header)
 {
        rfc2047_token *tokens;
        const char *value;
@@ -2976,7 +2983,7 @@ g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *
                value++;
        
        tokens = tokenize_rfc2047_text (options, value, &len);
-       folded = header_fold_tokens (field, value, len, tokens, FALSE);
+       folded = header_fold_tokens (format, field, value, len, tokens, FALSE);
        g_free (field);
        
        return folded;
@@ -2986,6 +2993,7 @@ g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *
 /**
  * _g_mime_utils_unstructured_header_fold:
  * @options: a #GMimeParserOptions
+ * @format: a #GMimeFormatOptions
  * @field: header field
  * @value: header value
  *
@@ -2994,7 +3002,7 @@ g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *
  * Returns: an allocated string containing the folded header.
  **/
 char *
-_g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *field, const char *value)
+_g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const char 
*field, const char *value)
 {
        rfc2047_token *tokens;
        size_t len;
@@ -3007,33 +3015,34 @@ _g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char
        
        tokens = tokenize_rfc2047_text (options, value, &len);
        
-       return header_fold_tokens (field, value, len, tokens, FALSE);
+       return header_fold_tokens (format, field, value, len, tokens, FALSE);
 }
 
 
 /**
  * g_mime_utils_header_printf:
  * @options: a #GMimeParserOptions
- * @format: string format
+ * @format: a #GMimeFormatOptions
+ * @text: text with printf-style formatters
  * @...: arguments
  *
  * Allocates a buffer containing a formatted header specified by the
  * @Varargs.
  *
  * Returns: an allocated string containing the folded header specified
- * by @format and the following arguments.
+ * by @text and the following arguments.
  **/
 char *
-g_mime_utils_header_printf (GMimeParserOptions *options, const char *format, ...)
+g_mime_utils_header_printf (GMimeParserOptions *options, GMimeFormatOptions *format, const char *text, ...)
 {
        char *buf, *ret;
        va_list ap;
        
-       va_start (ap, format);
-       buf = g_strdup_vprintf (format, ap);
+       va_start (ap, text);
+       buf = g_strdup_vprintf (text, ap);
        va_end (ap);
        
-       ret = g_mime_utils_unstructured_header_fold (options, buf);
+       ret = g_mime_utils_unstructured_header_fold (options, format, buf);
        g_free (buf);
        
        return ret;
diff --git a/gmime/gmime-utils.h b/gmime/gmime-utils.h
index 57950a4..b624b03 100644
--- a/gmime/gmime-utils.h
+++ b/gmime/gmime-utils.h
@@ -27,6 +27,7 @@
 #include <time.h>
 #include <stdarg.h>
 
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 #include <gmime/gmime-encodings.h>
 
@@ -68,9 +69,9 @@ void g_mime_references_free (GMimeReferences *refs);
 const GMimeReferences *g_mime_references_get_next (const GMimeReferences *ref);
 const char *g_mime_references_get_message_id (const GMimeReferences *ref);
 
-char  *g_mime_utils_structured_header_fold (GMimeParserOptions *options, const char *header);
-char  *g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, const char *header);
-char  *g_mime_utils_header_printf (GMimeParserOptions *options, const char *format, ...) G_GNUC_PRINTF (2, 
3);
+char  *g_mime_utils_structured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const 
char *header);
+char  *g_mime_utils_unstructured_header_fold (GMimeParserOptions *options, GMimeFormatOptions *format, const 
char *header);
+char  *g_mime_utils_header_printf (GMimeParserOptions *options, GMimeFormatOptions *format, const char 
*text, ...) G_GNUC_PRINTF (3, 4);
 
 char  *g_mime_utils_quote_string (const char *str);
 void   g_mime_utils_unquote_string (char *str);
@@ -84,10 +85,10 @@ char *g_mime_utils_decode_8bit (GMimeParserOptions *options, const char *text, s
 
 /* utilities to (de/en)code headers */
 char *g_mime_utils_header_decode_text (GMimeParserOptions *options, const char *text);
-char *g_mime_utils_header_encode_text (const char *text, const char *charset);
+char *g_mime_utils_header_encode_text (GMimeFormatOptions *options, const char *text, const char *charset);
 
 char *g_mime_utils_header_decode_phrase (GMimeParserOptions *options, const char *phrase);
-char *g_mime_utils_header_encode_phrase (const char *phrase, const char *charset);
+char *g_mime_utils_header_encode_phrase (GMimeFormatOptions *options, const char *phrase, const char 
*charset);
 
 G_END_DECLS
 
diff --git a/gmime/gmime.c b/gmime/gmime.c
index 2f1da33..9fcc858 100644
--- a/gmime/gmime.c
+++ b/gmime/gmime.c
@@ -116,6 +116,7 @@ g_mime_init (void)
        g_type_init ();
 #endif
        
+       g_mime_format_options_init ();
        g_mime_parser_options_init ();
        g_mime_charset_map_init ();
        g_mime_iconv_utils_init ();
@@ -225,6 +226,7 @@ g_mime_shutdown (void)
        
        g_mime_object_type_registry_shutdown ();
        g_mime_crypto_context_shutdown ();
+       g_mime_format_options_shutdown ();
        g_mime_parser_options_shutdown ();
        g_mime_charset_map_shutdown ();
        g_mime_iconv_utils_shutdown ();
diff --git a/gmime/internet-address.c b/gmime/internet-address.c
index 3ca008e..0b47a24 100644
--- a/gmime/internet-address.c
+++ b/gmime/internet-address.c
@@ -252,6 +252,7 @@ internet_address_get_charset (InternetAddress *ia)
 /**
  * internet_address_to_string:
  * @ia: Internet Address object
+ * @options: a #GMimeFormatOptions
  * @encode: %TRUE if the address should be rfc2047 encoded
  *
  * Allocates a string containing the contents of the #InternetAddress
@@ -261,7 +262,7 @@ internet_address_get_charset (InternetAddress *ia)
  * rfc822 format.
  **/
 char *
-internet_address_to_string (InternetAddress *ia, gboolean encode)
+internet_address_to_string (InternetAddress *ia, GMimeFormatOptions *options, gboolean encode)
 {
        guint32 flags = encode ? INTERNET_ADDRESS_ENCODE : 0;
        size_t linelen = 0;
@@ -269,7 +270,7 @@ internet_address_to_string (InternetAddress *ia, gboolean encode)
        char *str;
        
        string = g_string_new ("");
-       INTERNET_ADDRESS_GET_CLASS (ia)->to_string (ia, flags, &linelen, string);
+       INTERNET_ADDRESS_GET_CLASS (ia)->to_string (ia, options, flags, &linelen, string);
        str = string->str;
        
        g_string_free (string, FALSE);
@@ -282,7 +283,8 @@ static void internet_address_mailbox_class_init (InternetAddressMailboxClass *kl
 static void internet_address_mailbox_init (InternetAddressMailbox *mailbox, InternetAddressMailboxClass 
*klass);
 static void internet_address_mailbox_finalize (GObject *object);
 
-static void mailbox_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *out);
+static void mailbox_to_string (InternetAddress *ia, GMimeFormatOptions *options, guint32 flags,
+                              size_t *linelen, GString *out);
 
 
 static GObjectClass *mailbox_parent_class = NULL;
@@ -414,7 +416,8 @@ static void internet_address_group_class_init (InternetAddressGroupClass *klass)
 static void internet_address_group_init (InternetAddressGroup *group, InternetAddressGroupClass *klass);
 static void internet_address_group_finalize (GObject *object);
 
-static void group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *out);
+static void group_to_string (InternetAddress *ia, GMimeFormatOptions *options, guint32 flags,
+                            size_t *linelen, GString *out);
 
 
 static GObjectClass *group_parent_class = NULL;
@@ -1034,14 +1037,14 @@ internet_address_list_set_address (InternetAddressList *list, int index, Interne
 
 
 static char *
-encoded_name (const char *raw, gboolean rfc2047_encode, const char *charset)
+encoded_name (GMimeFormatOptions *options, const char *raw, gboolean rfc2047_encode, const char *charset)
 {
        char *name;
        
        g_return_val_if_fail (raw != NULL, NULL);
        
        if (rfc2047_encode) {
-               name = g_mime_utils_header_encode_phrase (raw, charset);
+               name = g_mime_utils_header_encode_phrase (options, raw, charset);
        } else {
                name = g_mime_utils_quote_string (raw);
        }
@@ -1112,7 +1115,7 @@ append_folded_name (GString *string, size_t *linelen, const char *name)
 }
 
 static void
-mailbox_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *string)
+mailbox_to_string (InternetAddress *ia, GMimeFormatOptions *options, guint32 flags, size_t *linelen, GString 
*string)
 {
        InternetAddressMailbox *mailbox = (InternetAddressMailbox *) ia;
        gboolean encode = flags & INTERNET_ADDRESS_ENCODE;
@@ -1121,7 +1124,7 @@ mailbox_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString
        size_t len;
        
        if (ia->name && *ia->name) {
-               name = encoded_name (ia->name, encode, ia->charset);
+               name = encoded_name (options, ia->name, encode, ia->charset);
                len = strlen (name);
                
                if (fold && (*linelen + len) > GMIME_FOLD_LEN) {
@@ -1174,7 +1177,8 @@ mailbox_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString
 }
 
 static void
-_internet_address_list_to_string (const InternetAddressList *list, guint32 flags, size_t *linelen, GString 
*string)
+_internet_address_list_to_string (const InternetAddressList *list, GMimeFormatOptions *options, guint32 
flags,
+                                 size_t *linelen, GString *string)
 {
        InternetAddress *ia;
        guint i;
@@ -1182,7 +1186,7 @@ _internet_address_list_to_string (const InternetAddressList *list, guint32 flags
        for (i = 0; i < list->array->len; i++) {
                ia = (InternetAddress *) list->array->pdata[i];
                
-               INTERNET_ADDRESS_GET_CLASS (ia)->to_string (ia, flags, linelen, string);
+               INTERNET_ADDRESS_GET_CLASS (ia)->to_string (ia, options, flags, linelen, string);
                
                if (i + 1 < list->array->len) {
                        g_string_append (string, ", ");
@@ -1192,7 +1196,7 @@ _internet_address_list_to_string (const InternetAddressList *list, guint32 flags
 }
 
 static void
-group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *string)
+group_to_string (InternetAddress *ia, GMimeFormatOptions *options, guint32 flags, size_t *linelen, GString 
*string)
 {
        InternetAddressGroup *group = (InternetAddressGroup *) ia;
        gboolean encode = flags & INTERNET_ADDRESS_ENCODE;
@@ -1201,7 +1205,7 @@ group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *s
        size_t len = 0;
        
        if (ia->name != NULL) {
-               name = encoded_name (ia->name, encode, ia->charset);
+               name = encoded_name (options, ia->name, encode, ia->charset);
                len = strlen (name);
                
                if (fold && *linelen > 1 && (*linelen + len + 1) > GMIME_FOLD_LEN) {
@@ -1216,7 +1220,7 @@ group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *s
        *linelen += len + 2;
        g_free (name);
        
-       _internet_address_list_to_string (group->members, flags, linelen, string);
+       _internet_address_list_to_string (group->members, options, flags, linelen, string);
        g_string_append_c (string, ';');
        *linelen += 1;
 }
@@ -1225,6 +1229,7 @@ group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *s
 /**
  * internet_address_list_to_string:
  * @list: list of internet addresses
+ * @options: a #GMimeFormatOptions
  * @encode: %TRUE if the address should be rfc2047 encoded
  *
  * Allocates a string buffer containing the rfc822 formatted addresses
@@ -1234,7 +1239,7 @@ group_to_string (InternetAddress *ia, guint32 flags, size_t *linelen, GString *s
  * or %NULL if no addresses are contained in the list.
  **/
 char *
-internet_address_list_to_string (InternetAddressList *list, gboolean encode)
+internet_address_list_to_string (InternetAddressList *list, GMimeFormatOptions *options, gboolean encode)
 {
        guint32 flags = encode ? INTERNET_ADDRESS_ENCODE : 0;
        size_t linelen = 0;
@@ -1247,7 +1252,7 @@ internet_address_list_to_string (InternetAddressList *list, gboolean encode)
                return NULL;
        
        string = g_string_new ("");
-       _internet_address_list_to_string (list, flags, &linelen, string);
+       _internet_address_list_to_string (list, options, flags, &linelen, string);
        str = string->str;
        
        g_string_free (string, FALSE);
@@ -1265,7 +1270,7 @@ internet_address_list_to_string (InternetAddressList *list, gboolean encode)
  * @str, folding appropriately.
  **/
 void
-internet_address_list_writer (InternetAddressList *list, GString *str)
+internet_address_list_writer (InternetAddressList *list, GMimeFormatOptions *options, GString *str)
 {
        guint32 flags = INTERNET_ADDRESS_ENCODE | INTERNET_ADDRESS_FOLD;
        size_t linelen = str->len;
@@ -1273,7 +1278,7 @@ internet_address_list_writer (InternetAddressList *list, GString *str)
        g_return_if_fail (IS_INTERNET_ADDRESS_LIST (list));
        g_return_if_fail (str != NULL);
        
-       _internet_address_list_to_string (list, flags, &linelen, str);
+       _internet_address_list_to_string (list, options, flags, &linelen, str);
 }
 
 
diff --git a/gmime/internet-address.h b/gmime/internet-address.h
index 683d185..dd4e89b 100644
--- a/gmime/internet-address.h
+++ b/gmime/internet-address.h
@@ -25,6 +25,7 @@
 #include <glib.h>
 #include <glib-object.h>
 
+#include <gmime/gmime-format-options.h>
 #include <gmime/gmime-parser-options.h>
 
 G_BEGIN_DECLS
@@ -90,7 +91,8 @@ struct _InternetAddressClass {
        GObjectClass parent_class;
        
        /* public virtual methods */
-       void (* to_string) (InternetAddress *ia, guint32 flags, size_t *linelen, GString *out);
+       void (* to_string) (InternetAddress *ia, GMimeFormatOptions *options, guint32 flags,
+                           size_t *linelen, GString *out);
 };
 
 
@@ -102,7 +104,7 @@ const char *internet_address_get_name (InternetAddress *ia);
 void internet_address_set_charset (InternetAddress *ia, const char *charset);
 const char *internet_address_get_charset (InternetAddress *ia);
 
-char *internet_address_to_string (InternetAddress *ia, gboolean encode);
+char *internet_address_to_string (InternetAddress *ia, GMimeFormatOptions *options, gboolean encode);
 
 
 /**
@@ -204,11 +206,11 @@ int internet_address_list_index_of (InternetAddressList *list, InternetAddress *
 InternetAddress *internet_address_list_get_address (InternetAddressList *list, int index);
 void internet_address_list_set_address (InternetAddressList *list, int index, InternetAddress *ia);
 
-char *internet_address_list_to_string (InternetAddressList *list, gboolean encode);
+char *internet_address_list_to_string (InternetAddressList *list, GMimeFormatOptions *options, gboolean 
encode);
 
 InternetAddressList *internet_address_list_parse (GMimeParserOptions *options, const char *str);
 
-void internet_address_list_writer (InternetAddressList *list, GString *str);
+void internet_address_list_writer (InternetAddressList *list, GMimeFormatOptions *options, GString *str);
 
 G_END_DECLS
 
diff --git a/tests/test-mbox.c b/tests/test-mbox.c
index ca5df2a..c990a68 100644
--- a/tests/test-mbox.c
+++ b/tests/test-mbox.c
@@ -103,6 +103,7 @@ static void
 test_parser (GMimeParser *parser, GMimeStream *mbox, GMimeStream *summary)
 {
        gint64 message_begin, message_end, headers_begin, headers_end, marker_offset;
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        InternetAddressList *list;
        GMimeMessage *message;
        char *marker, *buf;
@@ -133,14 +134,14 @@ test_parser (GMimeParser *parser, GMimeStream *mbox, GMimeStream *summary)
                
                if ((list = g_mime_message_get_from (message)) != NULL &&
                    internet_address_list_length (list) > 0) {
-                       buf = internet_address_list_to_string (list, FALSE);
+                       buf = internet_address_list_to_string (list, format, FALSE);
                        g_mime_stream_printf (summary, "From: %s\n", buf);
                        g_free (buf);
                }
                
                if ((list = g_mime_message_get_addresses (message, GMIME_ADDRESS_TYPE_TO)) != NULL &&
                    internet_address_list_length (list) > 0) {
-                       buf = internet_address_list_to_string (list, FALSE);
+                       buf = internet_address_list_to_string (list, format, FALSE);
                        g_mime_stream_printf (summary, "To: %s\n", buf);
                        g_free (buf);
                }
@@ -160,7 +161,7 @@ test_parser (GMimeParser *parser, GMimeStream *mbox, GMimeStream *summary)
                
                if (mbox) {
                        g_mime_stream_printf (mbox, "%s%s\n", nmsg > 0 ? "\n" : "", marker);
-                       g_mime_object_write_to_stream ((GMimeObject *) message, mbox);
+                       g_mime_object_write_to_stream ((GMimeObject *) message, format, mbox);
                }
                
                g_object_unref (message);
diff --git a/tests/test-mime.c b/tests/test-mime.c
index ae6dbd3..537ea88 100644
--- a/tests/test-mime.c
+++ b/tests/test-mime.c
@@ -216,6 +216,7 @@ static struct {
 static void
 test_addrspec (GMimeParserOptions *options, gboolean test_broken)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        InternetAddressList *addrlist;
        InternetAddress *address;
        const char *charset;
@@ -244,12 +245,12 @@ test_addrspec (GMimeParserOptions *options, gboolean test_broken)
                                throw (exception_new ("expected NULL charset but address has a charset of 
'%s': %s", charset, addrspec[i].input));
                        }
                        
-                       str = internet_address_list_to_string (addrlist, FALSE);
+                       str = internet_address_list_to_string (addrlist, format, FALSE);
                        if (strcmp (addrspec[i].display, str) != 0)
                                throw (exception_new ("display strings do not match.\ninput: %s\nexpected: 
%s\nactual: %s", addrspec[i].input, addrspec[i].display, str));
                        g_free (str);
                        
-                       str = internet_address_list_to_string (addrlist, TRUE);
+                       str = internet_address_list_to_string (addrlist, format, TRUE);
                        if (strcmp (addrspec[i].encoded, str) != 0)
                                throw (exception_new ("encoded strings do not match.\nexpected: %s\nactual: 
%s", addrspec[i].encoded, str));
                        
@@ -286,12 +287,12 @@ test_addrspec (GMimeParserOptions *options, gboolean test_broken)
                                        throw (exception_new ("expected NULL charset but address has a 
charset of '%s': %s", charset, broken_addrspec[i].input));
                                }
                                
-                               str = internet_address_list_to_string (addrlist, FALSE);
+                               str = internet_address_list_to_string (addrlist, format, FALSE);
                                if (strcmp (broken_addrspec[i].display, str) != 0)
                                        throw (exception_new ("display strings do not match.\ninput: 
%s\nexpected: %s\nactual: %s", broken_addrspec[i].input, broken_addrspec[i].display, str));
                                g_free (str);
                                
-                               str = internet_address_list_to_string (addrlist, TRUE);
+                               str = internet_address_list_to_string (addrlist, format, TRUE);
                                if (strcmp (broken_addrspec[i].encoded, str) != 0)
                                        throw (exception_new ("encoded strings do not match.\nexpected: 
%s\nactual: %s", broken_addrspec[i].encoded, str));
                                
@@ -450,6 +451,7 @@ static struct {
 static void
 test_rfc2047 (GMimeParserOptions *options, gboolean test_broken)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        char *enc, *dec;
        guint i;
        
@@ -461,7 +463,7 @@ test_rfc2047 (GMimeParserOptions *options, gboolean test_broken)
                        if (strcmp (rfc2047_text[i].decoded, dec) != 0)
                                throw (exception_new ("decoded text does not match: %s", dec));
                        
-                       enc = g_mime_utils_header_encode_text (dec, NULL);
+                       enc = g_mime_utils_header_encode_text (format, dec, NULL);
                        if (strcmp (rfc2047_text[i].encoded, enc) != 0)
                                throw (exception_new ("encoded text does not match: actual=\"%s\", 
expected=\"%s\"", enc, rfc2047_text[i].encoded));
 
@@ -486,7 +488,7 @@ test_rfc2047 (GMimeParserOptions *options, gboolean test_broken)
                        if (strcmp (broken_rfc2047_text[i].decoded, dec) != 0)
                                throw (exception_new ("decoded text does not match: %s", dec));
                        
-                       enc = g_mime_utils_header_encode_text (dec, NULL);
+                       enc = g_mime_utils_header_encode_text (format, dec, NULL);
                        if (strcmp (broken_rfc2047_text[i].encoded, enc) != 0)
                                throw (exception_new ("encoded text does not match: %s", enc));
                        
@@ -508,7 +510,7 @@ test_rfc2047 (GMimeParserOptions *options, gboolean test_broken)
                        if (strcmp (rfc2047_phrase[i].decoded, dec) != 0)
                                throw (exception_new ("decoded phrase does not match"));
                        
-                       enc = g_mime_utils_header_encode_phrase (dec, NULL);
+                       enc = g_mime_utils_header_encode_phrase (format, dec, NULL);
                        if (strcmp (rfc2047_phrase[i].encoded, enc) != 0)
                                throw (exception_new ("encoded phrase does not match"));
                        
@@ -534,6 +536,7 @@ static struct {
 static void
 test_header_folding (GMimeParserOptions *options)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        char *folded;
        guint i;
        
@@ -541,7 +544,7 @@ test_header_folding (GMimeParserOptions *options)
                folded = NULL;
                testsuite_check ("header_folding[%u]", i);
                try {
-                       folded = g_mime_utils_unstructured_header_fold (options, header_folding[i].input);
+                       folded = g_mime_utils_unstructured_header_fold (options, format, 
header_folding[i].input);
                        if (strcmp (header_folding[i].folded, folded) != 0)
                                throw (exception_new ("folded text does not match: -->%s<-- vs -->%s<--", 
header_folding[i].folded, folded));
                        
@@ -584,6 +587,7 @@ static struct {
 static void
 test_rfc2184 (GMimeParserOptions *options)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeParamEncodingMethod method;
        GMimeParamList *params;
        GMimeParam *param;
@@ -603,7 +607,7 @@ test_rfc2184 (GMimeParserOptions *options)
                str = g_string_new ("Content-Disposition: attachment");
                n = str->len;
                
-               g_mime_param_list_encode (params, TRUE, str);
+               g_mime_param_list_encode (params, format, TRUE, str);
                g_object_unref (params);
                params = NULL;
                
diff --git a/tests/test-parser.c b/tests/test-parser.c
index c3b41d8..51b530f 100644
--- a/tests/test-parser.c
+++ b/tests/test-parser.c
@@ -156,6 +156,7 @@ print_mime_struct_iter (GMimeMessage *message)
 static void
 test_parser (GMimeStream *stream)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeParser *parser;
        GMimeMessage *message;
        char *text;
@@ -173,7 +174,7 @@ test_parser (GMimeStream *stream)
        g_object_unref (parser);
        
        ZenTimerStart (NULL);
-       text = g_mime_object_to_string ((GMimeObject *) message);
+       text = g_mime_object_to_string ((GMimeObject *) message, format);
        ZenTimerStop (NULL);
        ZenTimerReport (NULL, "gmime::message_to_string");
        /*fprintf (stdout, "Result should match previous MIME message dump\n\n%s\n", text);*/
@@ -183,7 +184,7 @@ test_parser (GMimeStream *stream)
        {
                char *raw;
                
-               raw = g_mime_object_get_headers ((GMimeObject *) message);
+               raw = g_mime_object_get_headers ((GMimeObject *) message, format);
                fprintf (stdout, "\nTesting raw headers...\n\n%s\n", raw);
                g_free (raw);
        }
@@ -196,7 +197,7 @@ test_parser (GMimeStream *stream)
                fprintf (stdout, "\nTesting preservation of headers...\n\n");
                stream = g_mime_stream_file_new (stdout);
                g_mime_stream_file_set_owner ((GMimeStreamFile *) stream, FALSE);
-               g_mime_header_list_write_to_stream (GMIME_OBJECT (message)->headers, stream);
+               g_mime_header_list_write_to_stream (GMIME_OBJECT (message)->headers, format, stream);
                g_mime_stream_flush (stream);
                g_object_unref (stream);
                fprintf (stdout, "\n");
@@ -206,7 +207,7 @@ test_parser (GMimeStream *stream)
 #ifdef TEST_WRITE_TO_STREAM
        stream = g_mime_stream_pipe_new (2);
        g_mime_stream_pipe_set_owner ((GMimeStreamPipe *) stream, FALSE);
-       g_mime_object_write_to_stream (GMIME_OBJECT (message), stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        g_mime_stream_flush (stream);
        g_object_unref (stream);
 #endif
diff --git a/tests/test-partial.c b/tests/test-partial.c
index bc94939..9ac1c88 100644
--- a/tests/test-partial.c
+++ b/tests/test-partial.c
@@ -135,6 +135,7 @@ int main (int argc, char **argv)
        GMimeStream *stream, *combined, *expected;
        GMimeMessage *message, **messages;
        GMimeMessagePartial **parts;
+       GMimeFormatOptions *format;
        GString *input, *output;
        GMimeParser *parser;
        GPtrArray *partials;
@@ -151,6 +152,8 @@ int main (int argc, char **argv)
        
        testsuite_start ("message/partial");
        
+       format = g_mime_format_options_get_default ();
+       
        output = g_string_new (datadir);
        g_string_append_c (output, G_DIR_SEPARATOR);
        g_string_append (output, "output");
@@ -218,7 +221,7 @@ int main (int argc, char **argv)
                                g_object_unref (parts[i]);
                        
                        combined = g_mime_stream_mem_new ();
-                       g_mime_object_write_to_stream (GMIME_OBJECT (message), combined);
+                       g_mime_object_write_to_stream (GMIME_OBJECT (message), format, combined);
                        g_mime_stream_reset (combined);
                        
                        if (!(expected = g_mime_stream_file_open (output->str, "r", NULL))) {
@@ -271,7 +274,7 @@ int main (int argc, char **argv)
                        }
                        
                        combined = g_mime_stream_mem_new ();
-                       g_mime_object_write_to_stream (GMIME_OBJECT (message), combined);
+                       g_mime_object_write_to_stream (GMIME_OBJECT (message), format, combined);
                        g_mime_stream_reset (combined);
                        g_mime_stream_reset (expected);
                        g_object_unref (message);
diff --git a/tests/test-pgpmime.c b/tests/test-pgpmime.c
index 0f9acb5..45f5e6c 100644
--- a/tests/test-pgpmime.c
+++ b/tests/test-pgpmime.c
@@ -163,6 +163,7 @@ print_verify_results (GMimeSignatureList *signatures)
 static GMimeMessage *
 create_message (GMimeObject *body)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        InternetAddressList *list;
        InternetAddress *mailbox;
        GMimeMessage *message;
@@ -191,7 +192,7 @@ create_message (GMimeObject *body)
        g_mime_message_set_mime_part (message, body);
        
        stream = g_mime_stream_mem_new ();
-       g_mime_object_write_to_stream ((GMimeObject *) message, stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        g_mime_stream_reset (stream);
        g_object_unref (message);
        
@@ -269,6 +270,7 @@ static void
 create_encrypted_message (GMimeCryptoContext *ctx, gboolean sign,
                          GMimeStream **cleartext_out, GMimeStream **stream_out)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeStream *cleartext, *stream;
        GMimeMultipartEncrypted *mpe;
        InternetAddressList *list;
@@ -284,7 +286,7 @@ create_encrypted_message (GMimeCryptoContext *ctx, gboolean sign,
        
        /* hold onto this for comparison later */
        cleartext = g_mime_stream_mem_new ();
-       g_mime_object_write_to_stream ((GMimeObject *) part, cleartext);
+       g_mime_object_write_to_stream ((GMimeObject *) part, format, cleartext);
        g_mime_stream_reset (cleartext);
        
        /* encrypt the part */
@@ -325,7 +327,7 @@ create_encrypted_message (GMimeCryptoContext *ctx, gboolean sign,
        g_object_unref (mpe);
        
        stream = g_mime_stream_mem_new ();
-       g_mime_object_write_to_stream ((GMimeObject *) message, stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        g_object_unref (message);
        
        *stream_out = stream;
@@ -337,6 +339,7 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
                          GMimeStream *cleartext, GMimeStream *stream,
                          const char *session_key)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        GMimeSignatureStatus status;
        GMimeStream *test_stream;
        GMimeMultipartEncrypted *mpe;
@@ -407,10 +410,10 @@ test_multipart_encrypted (GMimeCryptoContext *ctx, gboolean sign,
        }
        
        test_stream = g_mime_stream_mem_new ();
-       g_mime_object_write_to_stream (decrypted, test_stream);
+       g_mime_object_write_to_stream (decrypted, format, test_stream);
        
-       buf[0] = GMIME_STREAM_MEM (cleartext)->buffer;
-       buf[1] = GMIME_STREAM_MEM (test_stream)->buffer;
+       buf[0] = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) cleartext);
+       buf[1] = g_mime_stream_mem_get_byte_array ((GMimeStreamMem *) test_stream);
        
        if (buf[0]->len != buf[1]->len || memcmp (buf[0]->data, buf[1]->data, buf[0]->len) != 0)
                ex = exception_new ("decrypted data does not match original cleartext");
diff --git a/tests/test-smime.c b/tests/test-smime.c
index f59f7d4..d89c603 100644
--- a/tests/test-smime.c
+++ b/tests/test-smime.c
@@ -165,6 +165,7 @@ print_verify_results (GMimeSignatureList *signatures)
 static GMimeMessage *
 create_message (GMimeObject *body)
 {
+       GMimeFormatOptions *format = g_mime_format_options_get_default ();
        InternetAddressList *list;
        InternetAddress *mailbox;
        GMimeMessage *message;
@@ -193,7 +194,7 @@ create_message (GMimeObject *body)
        g_mime_message_set_mime_part (message, body);
        
        stream = g_mime_stream_mem_new ();
-       g_mime_object_write_to_stream ((GMimeObject *) message, stream);
+       g_mime_object_write_to_stream ((GMimeObject *) message, format, stream);
        g_mime_stream_reset (stream);
        g_object_unref (message);
        



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