changeset 1777:88744e967222 HEAD

If client requests invalid body part, return it as NIL.
author Timo Sirainen <tss@iki.fi>
date Mon, 15 Sep 2003 21:04:12 +0300
parents 850bf9389a73
children 8edd874f53a3
files src/imap/imap-fetch-body-section.c
diffstat 1 files changed, 13 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-fetch-body-section.c	Mon Sep 15 20:49:04 2003 +0300
+++ b/src/imap/imap-fetch-body-section.c	Mon Sep 15 21:04:12 2003 +0300
@@ -397,9 +397,8 @@
 }
 
 /* Find message_part for section (eg. 1.3.4) */
-static const struct message_part *
-part_find(struct mail *mail, const struct imap_fetch_body_data *body,
-	  const char **section)
+static int part_find(struct mail *mail, const struct imap_fetch_body_data *body,
+		     const struct message_part **part_r, const char **section)
 {
 	const struct message_part *part;
 	const char *path;
@@ -407,7 +406,7 @@
 
 	part = mail->get_parts(mail);
 	if (part == NULL)
-		return NULL;
+		return FALSE;
 
 	path = body->section;
 	while (*path >= '0' && *path <= '9' && part != NULL) {
@@ -431,7 +430,7 @@
 		} else {
 			/* only 1 allowed with non-multipart messages */
 			if (num != 1)
-				return NULL;
+				part = NULL;
 		}
 
 		if (part != NULL &&
@@ -441,8 +440,9 @@
 		}
 	}
 
+	*part_r = part;
 	*section = path;
-	return part;
+	return TRUE;
 }
 
 /* fetch BODY[1.2] or BODY[1.2.TEXT] */
@@ -488,10 +488,15 @@
 	const struct message_part *part;
 	const char *section;
 
-	part = part_find(mail, body, &section);
-	if (part == NULL)
+	if (!part_find(mail, body, &part, &section))
 		return FALSE;
 
+	if (part == NULL) {
+		/* part doesn't exist */
+		return o_stream_send_str(ctx->output, ctx->prefix) > 0 &&
+			o_stream_send_str(ctx->output, " NIL") > 0;
+	}
+
 	stream = mail->get_stream(mail, NULL, NULL);
 	if (stream == NULL)
 		return FALSE;