]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imapc: Fix doveadm copy with imapc
authorMarkus Valentin <markus.valentin@open-xchange.com>
Wed, 22 Dec 2021 11:12:51 +0000 (12:12 +0100)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Mon, 24 Jan 2022 09:58:21 +0000 (09:58 +0000)
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.

src/lib-storage/index/imapc/imapc-mail-fetch.c
src/lib-storage/index/imapc/imapc-sync.c

index 222237829adf07df8a0f6fcadfd071d45d3fba62..1b0eee7100179c2047935b0426978feaee58519c 100644 (file)
@@ -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;
 
index e3ba294dc98ecdf8a00b23968eec73b6ef652d75..68de93b8ca139e028da177a1c6a3b73636edd7a5 100644 (file)
@@ -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;
        }