changeset 3491:2dbd7232d7df HEAD

Several fixes to FETCHing MIME body parts. [n.MIME] was completely broken.
author Timo Sirainen <tss@iki.fi>
date Tue, 12 Jul 2005 23:45:59 +0300
parents 937ae4aec137
children ab0fc2c1d8e1
files src/imap/imap-fetch-body.c
diffstat 1 files changed, 30 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-fetch-body.c	Tue Jul 12 23:45:27 2005 +0300
+++ b/src/imap/imap-fetch-body.c	Tue Jul 12 23:45:59 2005 +0300
@@ -343,23 +343,6 @@
 		ctx->cur_have_eoh = TRUE;
 }
 
-static void header_filter_mime(struct message_header_line *hdr,
-			       int *matched, void *context)
-{
-	struct imap_fetch_context *ctx = context;
-
-	if (hdr == NULL)
-		return;
-
-	if (hdr->eoh) {
-		ctx->cur_have_eoh = TRUE;
-		return;
-	}
-
-	*matched = strncasecmp(hdr->name, "Content-", 8) == 0 ||
-		strcasecmp(hdr->name, "Mime-Version") == 0;
-}
-
 static int fetch_header_partial_from(struct imap_fetch_context *ctx,
 				     const struct imap_fetch_body_data *body,
 				     const char *header_section)
@@ -383,12 +366,6 @@
 						      body->fields,
 						      body->fields_count,
 						      header_filter_eoh, ctx);
-	} else if (strcmp(header_section, "MIME") == 0) {
-		/* Mime-Version + Content-* fields */
-		input = i_stream_create_header_filter(ctx->cur_input,
-						      HEADER_FILTER_INCLUDE,
-						      NULL, 0,
-						      header_filter_mime, ctx);
 	} else {
 		i_error("BUG: Accepted invalid section from user: '%s'",
 			header_section);
@@ -494,10 +471,9 @@
 
 		if (part != NULL &&
 		    (part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) &&
-		    ((*path >= '0' && *path <= '9') ||
-		     strncmp(path, "HEADER", 6) == 0)) {
-			/* if remainder of path is a number or "HEADER",
-			   skip the message/rfc822 part */
+		    (*path >= '0' && *path <= '9')) {
+			/* if we continue inside the message/rfc822, skip this
+			   body part */
 			part = part->children;
 		}
 	}
@@ -533,7 +509,32 @@
 	i_stream_ref(ctx->cur_input);
 	ctx->update_partial = TRUE;
 
-	if (*section == '\0' || strcmp(section, "TEXT") == 0) {
+	if (*section == '\0') {
+		/* fetch the whole section */
+		i_stream_seek(ctx->cur_input, part->physical_pos +
+			      part->header_size.physical_size);
+		return fetch_data(ctx, body, &part->body_size);
+	}
+
+	if (strcmp(section, "MIME") == 0) {
+		/* fetch section's MIME header */
+		i_stream_seek(ctx->cur_input, part->physical_pos);
+		return fetch_data(ctx, body, &part->header_size);
+	}
+
+	/* TEXT and HEADER are only for message/rfc822 parts */
+	if ((part->flags & MESSAGE_PART_FLAG_MESSAGE_RFC822) == 0) {
+		string_t *str = get_prefix(ctx, body, 0);
+		if (o_stream_send(ctx->client->output,
+				  str_data(str), str_len(str)) < 0)
+			return -1;
+		return 1;
+	}
+
+	i_assert(part->children != NULL && part->children->next == NULL);
+	part = part->children;
+
+	if (strcmp(section, "TEXT") == 0) {
 		i_stream_seek(ctx->cur_input, part->physical_pos +
 			      part->header_size.physical_size);
 		return fetch_data(ctx, body, &part->body_size);
@@ -545,8 +546,7 @@
 		return fetch_data(ctx, body, &part->header_size);
 	}
 
-	if (strncmp(section, "HEADER", 6) == 0 ||
-	    strcmp(section, "MIME") == 0) {
+	if (strncmp(section, "HEADER", 6) == 0) {
 		i_stream_seek(ctx->cur_input, part->physical_pos);
 		return fetch_header_partial_from(ctx, body, section);
 	}