From: Timo Sirainen Date: Mon, 15 Sep 2003 18:04:12 +0000 (+0300) Subject: If client requests invalid body part, return it as NIL. X-Git-Tag: 1.1.alpha1~4329 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=580ff40767acd55ba6e640dcac315c88a17426c0;p=thirdparty%2Fdovecot%2Fcore.git If client requests invalid body part, return it as NIL. --HG-- branch : HEAD --- diff --git a/src/imap/imap-fetch-body-section.c b/src/imap/imap-fetch-body-section.c index 2a90224ce1..4ac16d5ffe 100644 --- a/src/imap/imap-fetch-body-section.c +++ b/src/imap/imap-fetch-body-section.c @@ -397,9 +397,8 @@ static int fetch_header(struct imap_fetch_context *ctx, struct mail *mail, } /* 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_find(struct mail *mail, const struct imap_fetch_body_data *body, 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 @@ part_find(struct mail *mail, const struct imap_fetch_body_data *body, } else { /* only 1 allowed with non-multipart messages */ if (num != 1) - return NULL; + part = NULL; } if (part != NULL && @@ -441,8 +440,9 @@ part_find(struct mail *mail, const struct imap_fetch_body_data *body, } } + *part_r = part; *section = path; - return part; + return TRUE; } /* fetch BODY[1.2] or BODY[1.2.TEXT] */ @@ -488,10 +488,15 @@ static int fetch_part(struct imap_fetch_context *ctx, struct mail *mail, const struct message_part *part; const char *section; - part = part_find(mail, body, §ion); - if (part == NULL) + if (!part_find(mail, body, &part, §ion)) 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;