From: Timo Sirainen Date: Fri, 2 May 2014 08:06:27 +0000 (+0300) Subject: imap: If FETCH BINARY fails because of invalid MIME part data, return [UNKNOWN-CTE... X-Git-Tag: 2.2.13.rc1~61 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6165a82cdc4eeb33a7bbbd8cd9489e42f8efd4a0;p=thirdparty%2Fdovecot%2Fcore.git imap: If FETCH BINARY fails because of invalid MIME part data, return [UNKNOWN-CTE] error. --- diff --git a/src/imap/cmd-fetch.c b/src/imap/cmd-fetch.c index c5e1c58819..f48d639634 100644 --- a/src/imap/cmd-fetch.c +++ b/src/imap/cmd-fetch.c @@ -198,8 +198,10 @@ static bool cmd_fetch_finish(struct imap_fetch_context *ctx, } errstr = mailbox_get_last_error(cmd->client->mailbox, &error); - if (error == MAIL_ERROR_CONVERSION) { - /* BINARY found unsupported Content-Transfer-Encoding */ + if (error == MAIL_ERROR_CONVERSION || + error == MAIL_ERROR_INVALIDDATA) { + /* a) BINARY found unsupported Content-Transfer-Encoding + b) Content was invalid */ tagged_reply = t_strdup_printf( "NO ["IMAP_RESP_CODE_UNKNOWN_CTE"] %s", errstr); } else { diff --git a/src/imap/imap-fetch-body.c b/src/imap/imap-fetch-body.c index 6439ee6f91..4676aa5970 100644 --- a/src/imap/imap-fetch-body.c +++ b/src/imap/imap-fetch-body.c @@ -163,16 +163,8 @@ static int fetch_body_msgpart(struct imap_fetch_context *ctx, struct mail *mail, return 1; } - if (imap_msgpart_open(mail, body->msgpart, &result) < 0) { - if (!body->binary || - mailbox_get_last_mail_error(mail->box) != MAIL_ERROR_INVALIDDATA) - return -1; - /* tried to do BINARY fetch for a MIME part with broken - content */ - str = get_prefix(&ctx->state, body, (uoff_t)-1, FALSE); - o_stream_nsend(ctx->client->output, str_data(str), str_len(str)); - return 1; - } + if (imap_msgpart_open(mail, body->msgpart, &result) < 0) + return -1; ctx->state.cur_input = result.input; ctx->state.cur_size = result.size; ctx->state.cur_size_field = result.size_field; @@ -197,13 +189,8 @@ static int fetch_binary_size(struct imap_fetch_context *ctx, struct mail *mail, return 1; } - if (imap_msgpart_size(mail, body->msgpart, &size) < 0) { - if (mailbox_get_last_mail_error(mail->box) != MAIL_ERROR_INVALIDDATA) - return -1; - /* tried to do BINARY.SIZE fetch for a MIME part with broken - content */ - size = 0; - } + if (imap_msgpart_size(mail, body->msgpart, &size) < 0) + return -1; str = t_str_new(128); if (ctx->state.cur_first)