From 203b2b709b0477be8753ea4ae7830bedbfebb268 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Thu, 11 Jun 2020 12:59:14 +0300 Subject: [PATCH] imap: Fix assert-crash in COPY/MOVE when storage doesn't return UIDs For example copying mails into virtual storage crashed. Broken by 09413e35f764a2898cbc26cea94218eed6df5cbf Fixes: Panic: file cmd-copy.c: line 152 (fetch_and_copy): assertion failed: (copy_ctx->copy_count == seq_range_count(©_ctx->saved_uids)) --- src/imap/cmd-copy.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index 593434fc5d..64d5af833c 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -140,6 +140,11 @@ static int fetch_and_copy(struct cmd_copy_context *copy_ctx, if (changes.no_read_perm) copy_ctx->hide_saved_uids = TRUE; + if (seq_range_count(&changes.saved_uids) == 0) { + /* storage doesn't support returning UIDs */ + copy_ctx->hide_saved_uids = TRUE; + } + if (copy_ctx->uid_validity == 0) copy_ctx->uid_validity = changes.uid_validity; else if (copy_ctx->uid_validity != changes.uid_validity) { @@ -149,7 +154,8 @@ static int fetch_and_copy(struct cmd_copy_context *copy_ctx, seq_range_array_merge(©_ctx->src_uids, &src_uids); seq_range_array_merge(©_ctx->saved_uids, &changes.saved_uids); - i_assert(copy_ctx->copy_count == seq_range_count(©_ctx->saved_uids)); + i_assert(copy_ctx->copy_count == seq_range_count(©_ctx->saved_uids) || + copy_ctx->hide_saved_uids); copy_update_trashed(client, copy_ctx->destbox, copy_ctx->copy_count); pool_unref(&changes.pool); }