]> dgit.raspbian.org Git - dovecot.git/commitdiff
[PATCH 1/2] lib-lda: mail-deliver - Autocreate delivery mailbox via explicit mailbox_...
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 11 Jun 2026 17:20:32 +0000 (17:20 +0000)
committerNoah Meyerhans <noahm@debian.org>
Wed, 16 Sep 2026 19:06:35 +0000 (15:06 -0400)
Instead of relying on MAILBOX_FLAG_AUTO_CREATE to have mailbox_open()
implicitly create the target, open it and, on MAIL_ERROR_NOTFOUND,
create it explicitly when lda_mailbox_autocreate is enabled. This makes
the creation go through the normal mailbox_create() path (including ACL
checks) and removes one of the two users of the autocreate mailbox flags.

Gbp-Pq: Name 0001-lib-lda-mail-deliver-Autocreate-delivery-mailbox-via.patch

src/lib-lda/mail-deliver.c

index a8ea1ea3b34ca6c2b57e00d9716b7b43e9ed7b93..6c2dc8087a119bc7b3eeffca32066b69b234e7b4 100644 (file)
@@ -244,16 +244,35 @@ int mail_deliver_save_open(struct mail_deliver_save_open_context *ctx,
                return -1;
        }
 
-       if (ctx->lda_mailbox_autocreate)
-               flags |= MAILBOX_FLAG_AUTO_CREATE;
-       if (ctx->lda_mailbox_autosubscribe)
-               flags |= MAILBOX_FLAG_AUTO_SUBSCRIBE;
        *box_r = box = mailbox_alloc_for_user(ctx->user, name, flags);
 
        if (mailbox_open(box) == 0)
                return 0;
        *error_str_r = mailbox_get_last_internal_error(box, error_r);
-       return -1;
+
+       /* Autocreate the mailbox if it does not exist yet and
+          lda_mailbox_autocreate is enabled. */
+       if (*error_r != MAIL_ERROR_NOTFOUND || !ctx->lda_mailbox_autocreate)
+               return -1;
+
+       if (mailbox_create(box, NULL, FALSE) < 0) {
+               enum mail_error error;
+
+               *error_str_r = mailbox_get_last_internal_error(box, &error);
+               if (error != MAIL_ERROR_EXISTS) {
+                       *error_r = error;
+                       return -1;
+               }
+               /* Someone else just created it; fall through and open it. */
+       } else if (ctx->lda_mailbox_autosubscribe) {
+               (void)mailbox_set_subscribed(box, TRUE);
+       }
+
+       if (mailbox_open(box) < 0) {
+               *error_str_r = mailbox_get_last_internal_error(box, error_r);
+               return -1;
+       }
+       return 0;
 }
 
 static bool mail_deliver_check_duplicate(struct mail_deliver_session *session,