$OpenBSD: patch-src_lib-imap_imap-bodystructure_c,v 1.1 2003/09/23 06:34:32 jolan Exp $
--- src/lib-imap/imap-bodystructure.c.orig	2003-06-24 18:12:56.000000000 -0500
+++ src/lib-imap/imap-bodystructure.c	2003-09-23 00:45:51.000000000 -0500
@@ -365,18 +365,23 @@ static void part_write_body(struct messa
 		data = t_new(struct message_part_body_data, 1);
 	}
 
-	/* "content type" "subtype" */
-	str_append(str, NVL(data->content_type, "\"text\""));
-	str_append_c(str, ' ');
-	if (data->content_subtype != NULL)
-		str_append(str, data->content_subtype);
+	if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822)
+		str_append(str, "\"message\" \"rfc822\"");
 	else {
-		if (data->content_type == NULL ||
-		    strcasecmp(data->content_type, "\"text\"") == 0)
-			str_append(str, "\"plain\"");
-		else
-			str_append(str, "\"unknown\"");
+		/* "content type" "subtype" */
+		str_append(str, NVL(data->content_type, "\"text\""));
+		str_append_c(str, ' ');
 
+		if (data->content_subtype != NULL)
+			str_append(str, data->content_subtype);
+		else {
+			if (data->content_type == NULL ||
+			    strcasecmp(data->content_type, "\"text\"") == 0)
+				str_append(str, "\"plain\"");
+			else
+				str_append(str, "\"unknown\"");
+
+		}
 	}
 
 	/* ("content type param key" "value" ...) */
@@ -405,23 +410,18 @@ static void part_write_body(struct messa
 	} else if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) {
 		/* message/rfc822 contains envelope + body + line count */
 		struct message_part_body_data *child_data;
+		struct message_part_envelope_data *env_data;
 
 		i_assert(part->children != NULL);
 		i_assert(part->children->next == NULL);
 
-                child_data = part->children->context;
+		child_data = part->children->context;
+                env_data = child_data != NULL ? child_data->envelope : NULL;
+
+		str_append(str, " (");
+		imap_envelope_write_part_data(env_data, str);
+		str_append(str, ") ");
 
-		str_append_c(str, ' ');
-		if (child_data != NULL && child_data->envelope != NULL) {
-			str_append_c(str, '(');
-			imap_envelope_write_part_data(child_data->envelope,
-						      str);
-			str_append_c(str, ')');
-		} else {
-			/* buggy message */
-			str_append(str, "NIL");
-		}
-		str_append_c(str, ' ');
 		part_write_bodystructure(part->children, str, extended);
 		str_printfa(str, " %u", part->body_size.lines);
 	}
