From: Timo Sirainen Date: Thu, 11 Jun 2026 17:20:32 +0000 (+0000) Subject: [PATCH 1/2] lib-lda: mail-deliver - Autocreate delivery mailbox via explicit mailbox_... X-Git-Tag: archive/raspbian/1%2.4.1+dfsg1-6+rpi1+deb13u7^2~104 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b103d3992713f5b8d47d33cc70eac0696e7be546;p=dovecot.git [PATCH 1/2] lib-lda: mail-deliver - Autocreate delivery mailbox via explicit mailbox_create() 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 --- diff --git a/src/lib-lda/mail-deliver.c b/src/lib-lda/mail-deliver.c index a8ea1ea..6c2dc80 100644 --- a/src/lib-lda/mail-deliver.c +++ b/src/lib-lda/mail-deliver.c @@ -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,