]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mailbox.mailbox_not_original flag
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Wed, 2 Mar 2022 23:05:27 +0000 (18:05 -0500)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 6 Jul 2022 20:51:20 +0000 (20:51 +0000)
src/lib-storage/mail-storage-private.h
src/lib-storage/mail-storage.c

index bc462bbd222cd1bdaff84e0bb3fb1d8323987410..8b92aa88eab67a11ac3294432ef771c391397ffb 100644 (file)
@@ -500,6 +500,9 @@ struct mailbox {
        /* mailbox_open() returned MAIL_ERROR_NOTFOUND because the mailbox
           doesn't have the LOOKUP ACL right. */
        bool acl_no_lookup_right:1;
+       /* mailbox_alloc() opened a different mailbox than asked (e.g. virtual
+          plugin opened the backend mailbox). */
+       bool mailbox_not_original:1;
 };
 
 struct mail_vfuncs {
index 5b54bf9a725232447d7cbf4336eb2154e23f90ad..559fdc55f34f7d9d0a1203e473c4797f8d9c674e 100644 (file)
@@ -871,6 +871,7 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
        }
 
        T_BEGIN {
+               const char *orig_vname = vname;
                enum mailbox_list_get_storage_flags storage_flags = 0;
                if ((flags & MAILBOX_FLAG_SAVEONLY) != 0)
                        storage_flags |= MAILBOX_LIST_GET_STORAGE_FLAG_SAVEONLY;
@@ -887,6 +888,8 @@ struct mailbox *mailbox_alloc(struct mailbox_list *list, const char *vname,
                box->open_error = open_error;
                if (open_error != 0)
                        mail_storage_set_error(storage, open_error, errstr);
+               if (strcmp(orig_vname, vname) != 0)
+                       box->mailbox_not_original = TRUE;
                hook_mailbox_allocated(box);
        } T_END;
 
@@ -2485,6 +2488,16 @@ int mailbox_transaction_commit_get_changes(
           finished */
        box->transaction_count--;
        event_reason_end(&reason);
+       if (ret == 0 && box->mailbox_not_original) {
+               /* The mailbox name changed while opening it. This is
+                  intentional when virtual mailbox is opened for saving mails,
+                  which causes the backend mailbox to be opened instead. In
+                  this situation the UIDVALIDITY / UIDs are for the physical
+                  mailbox, not the virtual mailbox. Use this flag to prevent
+                  IMAP APPEND from returning any UIDs in the tagged reply,
+                  since they would be wrong. */
+               changes_r->no_read_perm = TRUE;
+       }
        if (ret < 0 && changes_r->pool != NULL)
                pool_unref(&changes_r->pool);
        return ret;