[gmime/gmime-2-4] Preserve MIME-Version headers



commit 0c8c896657112c6797e8d0cd40a50e36aaad43dc
Author: Jeffrey Stedfast <fejj gnome org>
Date:   Fri Mar 26 09:02:36 2010 -0400

    Preserve MIME-Version headers
    
    2010-02-06  Jeffrey Stedfast  <fejj novell com>
    
    	* gmime/gmime-message.c (process_header): Return TRUE if we
    	* match
    	MIME-Version.
    	(message_prepend_header): Don't drop MIME-Version headers.
    	(message_append_header): Same.
    	(message_set_header): Here too.
    	(message_get_header): Only return the hard-coded "1.0" value for
    	MIME-Version if it is not set on the header object.
    	(message_remove_header): Allow the MIME-Version header to be
    	removed.
    	(message_get_headers): Only write our own MIME-Version header if
    	one isn't already set in the message headers.
    	(message_write_to_stream): Same here.

 ChangeLog             |   15 +++++++++++++++
 gmime/gmime-message.c |   44 +++++++++++++++++++++-----------------------
 2 files changed, 36 insertions(+), 23 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 953692e..b786f1c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2010-02-06  Jeffrey Stedfast  <fejj novell com>
+
+	* gmime/gmime-message.c (process_header): Return TRUE if we match
+	MIME-Version.
+	(message_prepend_header): Don't drop MIME-Version headers.
+	(message_append_header): Same.
+	(message_set_header): Here too.
+	(message_get_header): Only return the hard-coded "1.0" value for
+	MIME-Version if it is not set on the header object.
+	(message_remove_header): Allow the MIME-Version header to be
+	removed.
+	(message_get_headers): Only write our own MIME-Version header if
+	one isn't already set in the message headers.
+	(message_write_to_stream): Same here.
+
 2010-02-02  Jeffrey Stedfast  <fejj novell com>
 
 	* README: Bumped version
diff --git a/gmime/gmime-message.c b/gmime/gmime-message.c
index c18a472..dfbdbaf 100644
--- a/gmime/gmime-message.c
+++ b/gmime/gmime-message.c
@@ -661,6 +661,7 @@ enum {
 	HEADER_SUBJECT,
 	HEADER_DATE,
 	HEADER_MESSAGE_ID,
+	HEADER_MIME_VERSION,
 	HEADER_UNKNOWN
 };
 
@@ -673,6 +674,7 @@ static const char *message_headers[] = {
 	"Subject",
 	"Date",
 	"Message-Id",
+	"MIME-Version",
 };
 
 enum {
@@ -764,6 +766,8 @@ process_header (GMimeObject *object, int action, const char *header, const char
 		g_free (message->message_id);
 		message->message_id = g_mime_utils_decode_message_id (value);
 		break;
+	case HEADER_MIME_VERSION:
+		break;
 	default:
 		return FALSE;
 	}
@@ -776,9 +780,6 @@ message_prepend_header (GMimeObject *object, const char *header, const char *val
 {
 	GMimeMessage *message = (GMimeMessage *) object;
 	
-	if (!g_ascii_strcasecmp ("MIME-Version", header))
-		return;
-	
 	/* Make sure that the header is not a Content-* header, else it
            doesn't belong on a message */
 	if (!g_ascii_strncasecmp ("Content-", header, 8))
@@ -798,9 +799,6 @@ message_append_header (GMimeObject *object, const char *header, const char *valu
 {
 	GMimeMessage *message = (GMimeMessage *) object;
 	
-	if (!g_ascii_strcasecmp ("MIME-Version", header))
-		return;
-	
 	/* Make sure that the header is not a Content-* header, else it
            doesn't belong on a message */
 	if (!g_ascii_strncasecmp ("Content-", header, 8))
@@ -820,9 +818,6 @@ message_set_header (GMimeObject *object, const char *header, const char *value)
 {
 	GMimeMessage *message = (GMimeMessage *) object;
 	
-	if (!g_ascii_strcasecmp ("MIME-Version", header))
-		return;
-	
 	/* Make sure that the header is not a Content-* header, else it
            doesn't belong on a message */
 	if (!g_ascii_strncasecmp ("Content-", header, 8))
@@ -841,18 +836,21 @@ static const char *
 message_get_header (GMimeObject *object, const char *header)
 {
 	GMimeMessage *message = (GMimeMessage *) object;
-	
-	if (!g_ascii_strcasecmp ("MIME-Version", header))
-		return "1.0";
+	const char *value;
 	
 	/* Make sure that the header is not a Content-* header, else it
            doesn't belong on a message */
-	if (g_ascii_strncasecmp ("Content-", header, 8) != 0)
-		return GMIME_OBJECT_CLASS (parent_class)->get_header (object, header);
-	else if (message->mime_part)
+	if (g_ascii_strncasecmp ("Content-", header, 8) != 0) {
+		if ((value = GMIME_OBJECT_CLASS (parent_class)->get_header (object, header)))
+			return value;
+		
+		if (!g_ascii_strcasecmp ("MIME-Version", header))
+			return "1.0";
+	} else if (message->mime_part) {
 		return g_mime_object_get_header (message->mime_part, header);
-	else
-		return NULL;
+	}
+	
+	return NULL;
 }
 
 static gboolean
@@ -863,9 +861,6 @@ message_remove_header (GMimeObject *object, const char *header)
 	GMimeRecipientType type;
 	guint i;
 	
-	if (!g_ascii_strcasecmp ("MIME-Version", header))
-		return FALSE;
-	
 	/* Make sure that the header is not a Content-* header, else it
            doesn't belong on a message */
 	if (!g_ascii_strncasecmp ("Content-", header, 8)) {
@@ -956,7 +951,8 @@ message_get_headers (GMimeObject *object)
 		
 		g_mime_header_list_write_to_stream (object->headers, stream);
 		if (message->mime_part) {
-			if (g_mime_object_get_header (message->mime_part, "Content-Type"))
+			if (g_mime_object_get_header (message->mime_part, "Content-Type") &&
+			    !g_mime_header_list_get (object->headers, "MIME-Version"))
 				g_mime_stream_write_string (stream, "MIME-Version: 1.0\n");
 			g_mime_header_list_write_to_stream (message->mime_part->headers, stream);
 		}
@@ -988,8 +984,10 @@ message_write_to_stream (GMimeObject *object, GMimeStream *stream)
 			
 			total += nwritten;
 			
-			if ((nwritten = g_mime_stream_write_string (stream, "MIME-Version: 1.0\n")) == -1)
-				return -1;
+			if (!g_mime_header_list_get (object->headers, "MIME-Version")) {
+				if ((nwritten = g_mime_stream_write_string (stream, "MIME-Version: 1.0\n")) == -1)
+					return -1;
+			}
 			
 			total += nwritten;
 		}



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