diff src/lib-imap/imap-bodystructure.c @ 7014:6835ac721609 HEAD

Add a context structure to all message parts and remove the NULL checks. That way instead of returning a broken reply, imap_bodystructure_write() crashes if caller tries to give it non-parsed MIME parts.
author Timo Sirainen <tss@iki.fi>
date Fri, 21 Dec 2007 21:38:38 +0200
parents 414c9d631a81
children 7ed926ed7aa4
line wrap: on
line diff
--- a/src/lib-imap/imap-bodystructure.c	Fri Dec 21 21:05:14 2007 +0200
+++ b/src/lib-imap/imap-bodystructure.c	Fri Dec 21 21:38:38 2007 +0200
@@ -231,9 +231,15 @@
 	bool parent_rfc822;
 
 	if (hdr == NULL) {
-		/* If there was no Mime-Version, forget all the Content-stuff */
-		if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0 &&
-		    part->context != NULL) {
+		if (part->context == NULL) {
+			/* no Content-* headers. add an empty context
+			   structure anyway. */
+			part->context = part_data =
+				p_new(pool, struct message_part_body_data, 1);
+			part_data->pool = pool;
+		} else if ((part->flags & MESSAGE_PART_FLAG_IS_MIME) == 0) {
+			/* If there was no Mime-Version, forget all
+			   the Content-stuff */
 			part_data = part->context;
 			envelope = part_data->envelope;
 
@@ -277,11 +283,6 @@
 {
 	struct message_part_body_data *data = part->context;
 
-	if (data == NULL) {
-		/* there was no content headers, use an empty structure */
-		data = t_new(struct message_part_body_data, 1);
-	}
-
 	if (part->children != NULL)
 		imap_bodystructure_write(part->children, str, extended);
 	else {
@@ -344,11 +345,6 @@
 	struct message_part_body_data *data = part->context;
 	bool text;
 
-	if (data == NULL) {
-		/* there was no content headers, use an empty structure */
-		data = t_new(struct message_part_body_data, 1);
-	}
-
 	if (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) {
 		str_append(str, "\"message\" \"rfc822\"");
 		text = FALSE;
@@ -401,7 +397,7 @@
 		i_assert(part->children->next == NULL);
 
                 child_data = part->children->context;
-		env_data = child_data != NULL ? child_data->envelope : NULL;
+		env_data = child_data->envelope;
 
 		str_append(str, " (");
 		imap_envelope_write_part_data(env_data, str);
@@ -456,11 +452,6 @@
 
 	i_assert(part->parent == NULL);
 
-	if (data == NULL) {
-		/* no bodystructure headers found */
-		return TRUE;
-	}
-
 	/* if content-type is text/xxx we don't have to check any
 	   multipart stuff */
 	if ((part->flags & MESSAGE_PART_FLAG_TEXT) == 0)