[gmime] Default multipart/digest subparts to message/rfc822



commit 5ef4316af0b4809ea907cc0df4bb730dd372f139
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Thu Aug 8 08:18:48 2013 -0400

    Default multipart/digest subparts to message/rfc822
    
    2013-08-08  Jeffrey Stedfast  <fejj gnome org>
    
        * gmime/gmime-parser.c (parser_content_type): If no Content-Type
        header exists and the parent is a multipart/digest, default to
        message/rfc822 instead of text/plain.
        (parser_construct_leaf_part): If the Content-Type header didn't
        exist, use the default content-type values instead of assuming
        text/plain.

 ChangeLog            |    9 +++++++++
 gmime/gmime-parser.c |   21 +++++++++++++--------
 2 files changed, 22 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 2afba9d..1e4c18a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2013-08-08  Jeffrey Stedfast  <fejj gnome org>
+
+       * gmime/gmime-parser.c (parser_content_type): If no Content-Type
+       header exists and the parent is a multipart/digest, default to
+       message/rfc822 instead of text/plain.
+       (parser_construct_leaf_part): If the Content-Type header didn't
+       exist, use the default content-type values instead of assuming
+       text/plain.
+
 2013-08-07  Jeffrey Stedfast  <fejj gnome org>
 
        According to Rfc2046 Section 5.1.1, boundary markers may optionally
diff --git a/gmime/gmime-parser.c b/gmime/gmime-parser.c
index ebf4e58..3012ad1 100644
--- a/gmime/gmime-parser.c
+++ b/gmime/gmime-parser.c
@@ -1234,7 +1234,7 @@ content_type_is_type (ContentType *content_type, const char *type, const char *s
 }
 
 static ContentType *
-parser_content_type (GMimeParser *parser)
+parser_content_type (GMimeParser *parser, GMimeContentType *parent)
 {
        struct _GMimeParserPrivate *priv = parser->priv;
        ContentType *content_type;
@@ -1244,8 +1244,13 @@ parser_content_type (GMimeParser *parser)
        
        if (!(value = header_raw_find (priv->headers, "Content-Type", NULL)) ||
            !g_mime_parse_content_type (&value, &content_type->type, &content_type->subtype)) {
-               content_type->type = g_strdup ("text");
-               content_type->subtype = g_strdup ("plain");
+               if (parent != NULL && g_mime_content_type_is_type (parent, "multipart", "digest")) {
+                       content_type->type = g_strdup ("message");
+                       content_type->subtype = g_strdup ("rfc822");
+               } else {
+                       content_type->type = g_strdup ("text");
+                       content_type->subtype = g_strdup ("plain");
+               }
        }
        
        content_type->exists = value != NULL;
@@ -1644,7 +1649,7 @@ parser_scan_message_part (GMimeParser *parser, GMimeMessagePart *mpart, int *fou
                header = header->next;
        }
        
-       content_type = parser_content_type (parser);
+       content_type = parser_content_type (parser, NULL);
        if (content_type_is_type (content_type, "multipart", "*"))
                object = parser_construct_multipart (parser, content_type, TRUE, found);
        else
@@ -1676,7 +1681,7 @@ parser_construct_leaf_part (GMimeParser *parser, ContentType *content_type, gboo
        if (!content_type->exists) {
                GMimeContentType *mime_type;
                
-               mime_type = g_mime_content_type_new ("text", "plain");
+               mime_type = g_mime_content_type_new (content_type->type, content_type->subtype);
                _g_mime_object_set_content_type (object, mime_type);
                g_object_unref (mime_type);
        }
@@ -1801,7 +1806,7 @@ parser_scan_multipart_subparts (GMimeParser *parser, GMimeMultipart *multipart)
                        break;
                }
                
-               content_type = parser_content_type (parser);
+               content_type = parser_content_type (parser, ((GMimeObject *) multipart)->content_type);
                if (content_type_is_type (content_type, "multipart", "*"))
                        subpart = parser_construct_multipart (parser, content_type, FALSE, &found);
                else
@@ -1900,7 +1905,7 @@ parser_construct_part (GMimeParser *parser)
                        return NULL;
        }
        
-       content_type = parser_content_type (parser);
+       content_type = parser_content_type (parser, NULL);
        if (content_type_is_type (content_type, "multipart", "*"))
                object = parser_construct_multipart (parser, content_type, TRUE, &found);
        else
@@ -1975,7 +1980,7 @@ parser_construct_message (GMimeParser *parser)
                        priv->bounds->content_end = parser_offset (priv, NULL) + content_length;
        }
        
-       content_type = parser_content_type (parser);
+       content_type = parser_content_type (parser, NULL);
        if (content_type_is_type (content_type, "multipart", "*"))
                object = parser_construct_multipart (parser, content_type, TRUE, &found);
        else


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