struct mailbox *destbox;
bool move;
- struct msgset_generator_context srcset_ctx;
unsigned int copy_count;
uint32_t uid_validity;
+ ARRAY_TYPE(seq_range) src_uids;
ARRAY_TYPE(seq_range) saved_uids;
bool hide_saved_uids;
struct mail *mail;
const char *cmd_reason;
struct mail_transaction_commit_changes changes;
+ ARRAY_TYPE(seq_range) src_uids;
int ret;
i_assert(o_stream_is_corked(client->output) ||
search_ctx = mailbox_search_init(src_trans, search_args,
NULL, 0, NULL);
+ t_array_init(&src_uids, 64);
ret = 1;
while (mailbox_search_next(search_ctx, &mail) && ret > 0) {
if (mail->expunged) {
if (ret < 0 && mail->expunged)
ret = 0;
- msgset_generator_next(©_ctx->srcset_ctx, mail->uid);
+ if (ret > 0)
+ seq_range_array_add(&src_uids, mail->uid);
}
if (ret < 0) {
/* UIDVALIDITY unexpectedly changed */
copy_ctx->hide_saved_uids = TRUE;
}
+ 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));
copy_ctx.cmd = cmd;
copy_ctx.destbox = destbox;
copy_ctx.move = move;
+ i_array_init(©_ctx.src_uids, 8);
i_array_init(©_ctx.saved_uids, 8);
- src_uidset = t_str_new(256);
- msgset_generator_init(©_ctx.srcset_ctx, src_uidset);
do {
T_BEGIN {
ret = fetch_and_copy(©_ctx, search_args);
imap_search_seqset_iter_next(seqset_iter));
imap_search_seqset_iter_deinit(&seqset_iter);
mail_search_args_unref(&search_args);
- msgset_generator_finish(©_ctx.srcset_ctx);
+
+ src_uidset = t_str_new(256);
+ imap_write_seq_range(src_uidset, ©_ctx.src_uids);
msg = t_str_new(256);
- if (ret <= 0)
- ;
- else if (copy_ctx.copy_count == 0) {
+ if (ret <= 0) {
+ if (move && array_count(©_ctx.src_uids) > 0) {
+ /* some of the messages were successfully moved */
+ cmd_move_send_untagged(©_ctx, msg, src_uidset);
+ }
+ } else if (copy_ctx.copy_count == 0) {
str_append(msg, "OK No messages found.");
} else if (seq_range_count(©_ctx.saved_uids) == 0 ||
copy_ctx.hide_saved_uids) {
str_append(msg, "] Copy completed.");
}
+ array_free(©_ctx.src_uids);
array_free(©_ctx.saved_uids);
if (destbox != client->mailbox) {