[gmime] Track whether or not the end boundary should be written for multiparts



commit 2f07094fdb66fd3c662d20e79cc7d2c86b65d480
Author: Jeffrey Stedfast <jestedfa microsoft com>
Date:   Fri Feb 3 22:07:20 2017 -0500

    Track whether or not the end boundary should be written for multiparts

 gmime/gmime-multipart.c |   15 +++++++++------
 gmime/gmime-multipart.h |    1 +
 gmime/gmime-parser.c    |    2 ++
 3 files changed, 12 insertions(+), 6 deletions(-)
---
diff --git a/gmime/gmime-multipart.c b/gmime/gmime-multipart.c
index 7c4a411..6a77456 100644
--- a/gmime/gmime-multipart.c
+++ b/gmime/gmime-multipart.c
@@ -133,6 +133,7 @@ static void
 g_mime_multipart_init (GMimeMultipart *multipart, GMimeMultipartClass *klass)
 {
        multipart->children = g_ptr_array_new ();
+       multipart->write_end_boundary = TRUE;
        multipart->preface = NULL;
        multipart->postface = NULL;
 }
@@ -206,15 +207,17 @@ multipart_write_to_stream (GMimeObject *object, GMimeStream *stream, gboolean co
                        return -1;
                
                total += nwritten;
-               
-               if (g_mime_stream_write (stream, "\n", 1) == -1)
-                       return -1;
-               
-               total++;
+
+               if (!GMIME_IS_MULTIPART (part) || ((GMimeMultipart *) part)->write_end_boundary) {
+                       if (g_mime_stream_write (stream, "\n", 1) == -1)
+                               return -1;
+                       
+                       total++;
+               }
        }
        
        /* write the end-boundary (but only if a boundary is set) */
-       if (boundary) {
+       if (multipart->write_end_boundary && boundary) {
                if ((nwritten = g_mime_stream_printf (stream, "--%s--\n", boundary)) == -1)
                        return -1;
                
diff --git a/gmime/gmime-multipart.h b/gmime/gmime-multipart.h
index b95362a..77f3e27 100644
--- a/gmime/gmime-multipart.h
+++ b/gmime/gmime-multipart.h
@@ -52,6 +52,7 @@ typedef struct _GMimeMultipartClass GMimeMultipartClass;
 struct _GMimeMultipart {
        GMimeObject parent_object;
        
+       gboolean write_end_boundary;
        GPtrArray *children;
        char *boundary;
        char *preface;
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index e0e3c5e..4755331 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -1838,10 +1838,12 @@ parser_construct_multipart (GMimeParser *parser, ContentType *content_type, gboo
                
                if (*found == FOUND_END_BOUNDARY && found_immediate_boundary (priv, TRUE)) {
                        /* eat end boundary */
+                       multipart->write_end_boundary = TRUE;
                        parser_skip_line (parser);
                        parser_pop_boundary (parser);
                        *found = parser_scan_multipart_postface (parser, multipart);
                } else {
+                       multipart->write_end_boundary = FALSE;
                        parser_pop_boundary (parser);
                }
        } else {


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