From: Markus Valentin Date: Wed, 22 Dec 2021 11:12:51 +0000 (+0100) Subject: imapc: Fix doveadm copy with imapc X-Git-Tag: 2.4.0~4620 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0426053c50933780012164144095e9ec10951a37;p=thirdparty%2Fdovecot%2Fcore.git imapc: Fix doveadm copy with imapc When copying to a mailbox with imapc it does not sync the destination mailbox when opening. This created "Error: Syncing mailbox '$mailboxname' failed: Internal error occurred." Prevent this error by checking for the MAILBOX_FLAG_SAVEONLY flag which is used by doveadm to create the destination mailbox. If that flag is set ignore that there was no initial fetching done. --- diff --git a/src/lib-storage/index/imapc/imapc-mail-fetch.c b/src/lib-storage/index/imapc/imapc-mail-fetch.c index 222237829a..1b0eee7100 100644 --- a/src/lib-storage/index/imapc/imapc-mail-fetch.c +++ b/src/lib-storage/index/imapc/imapc-mail-fetch.c @@ -213,6 +213,12 @@ imapc_mail_send_fetch(struct mail *_mail, enum mail_fetch_field fields, i_assert(headers == NULL || IMAPC_BOX_HAS_FEATURE(mbox, IMAPC_FEATURE_FETCH_HEADERS)); + if (!mbox->selected) { + mail_storage_set_error(_mail->box->storage, + MAIL_ERROR_NOTPOSSIBLE, "Can't fetch mails before selecting mailbox"); + return -1; + } + if (!mail_stream_access_start(_mail)) return -1; diff --git a/src/lib-storage/index/imapc/imapc-sync.c b/src/lib-storage/index/imapc/imapc-sync.c index e3ba294dc9..68de93b8ca 100644 --- a/src/lib-storage/index/imapc/imapc-sync.c +++ b/src/lib-storage/index/imapc/imapc-sync.c @@ -561,6 +561,21 @@ imapc_noop_if_needed(struct imapc_mailbox *mbox, enum mailbox_sync_flags flags) } } +static bool imapc_mailbox_need_initial_fetch(struct imapc_mailbox *mbox) +{ + if (mbox->box.deleting) { + /* If the mailbox is about to be deleted there is no need to + expect initial fetch to be done */ + return FALSE; + } + if ((mbox->box.flags & MAILBOX_FLAG_SAVEONLY) != 0) { + /* The mailbox is opened only for saving there is no need to + expect initial fetchting do be done. */ + return FALSE; + } + return TRUE; +} + struct mailbox_sync_context * imapc_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) { @@ -580,7 +595,7 @@ imapc_mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags) if (imapc_storage_client_handle_auth_failure(mbox->storage->client)) ret = -1; else if (!mbox->state_fetched_success && !mbox->state_fetching_uid1 && - !mbox->box.deleting) { + imapc_mailbox_need_initial_fetch(mbox)) { /* initial FETCH failed already */ ret = -1; }