struct mail_deliver_mailbox {
union mailbox_module_context module_ctx;
- bool delivery_box;
};
struct mail_deliver_transaction {
const char *name, struct mailbox **box_r,
enum mail_error *error_r, const char **error_str_r)
{
- struct mail_namespace *ns;
struct mailbox *box;
- enum mailbox_flags flags =
- MAILBOX_FLAG_SAVEONLY | MAILBOX_FLAG_POST_SESSION;
+ enum mailbox_flags flags = 0;
*box_r = NULL;
*error_r = MAIL_ERROR_NONE;
return -1;
}
- ns = mail_namespace_find(ctx->user->namespaces, name);
- if (strcmp(name, ns->prefix) == 0 &&
- (ns->flags & NAMESPACE_FLAG_INBOX_USER) != 0) {
- /* delivering to a namespace prefix means we actually want to
- deliver to the INBOX instead */
- name = "INBOX";
- ns = mail_namespace_find_inbox(ctx->user->namespaces);
- }
-
- if (strcasecmp(name, "INBOX") == 0) {
- /* deliveries to INBOX must always succeed,
- regardless of ACLs */
- flags |= MAILBOX_FLAG_IGNORE_ACLS;
- }
-
- *box_r = box = mailbox_alloc(ns->list, name, flags);
- mailbox_set_reason(box, "lib-lda delivery");
- /* flag that this mailbox is used for delivering the mail.
- the context isn't set in pigeonhole testuite. */
- struct mail_deliver_mailbox *mbox = MAIL_DELIVER_STORAGE_CONTEXT(box);
- if (mbox != NULL)
- mbox->delivery_box = TRUE;
+ 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_delivery(ctx->user, name, flags);
if (mailbox_open(box) == 0)
return 0;
-
*error_str_r = mailbox_get_last_internal_error(box, error_r);
- if (!ctx->lda_mailbox_autocreate || *error_r != MAIL_ERROR_NOTFOUND)
- return -1;
-
- /* try creating it. */
- if (mailbox_create(box, NULL, FALSE) < 0) {
- *error_str_r = mailbox_get_last_internal_error(box, error_r);
- if (*error_r != MAIL_ERROR_EXISTS)
- return -1;
- /* someone else just created it */
- }
- if (ctx->lda_mailbox_autosubscribe) {
- /* (try to) subscribe to it */
- (void)mailbox_set_subscribed(box, TRUE);
- }
-
- /* and try opening again */
- if (mailbox_open(box) < 0) {
- *error_str_r = mailbox_get_last_internal_error(box, error_r);
- return -1;
- }
- return 0;
+ return -1;
}
static bool mail_deliver_check_duplicate(struct mail_deliver_session *session,
we also want to do this only for commits generated by sieve.
other plugins or storage backends may be creating transactions as
well, which we need to ignore. */
- if (mbox->delivery_box)
+ if ((box->flags & MAILBOX_FLAG_POST_SESSION) != 0)
muser->deliver_ctx->cache = &dt->cache;
if (mbox->module_ctx.super.transaction_commit(ctx, changes_r) < 0)
if (muser->deliver_ctx == NULL)
return;
+ if ((box->flags & MAILBOX_FLAG_POST_SESSION) != 0)
+ mailbox_set_reason(box, "lib-lda delivery");
+
mbox = p_new(box->pool, struct mail_deliver_mailbox, 1);
mbox->module_ctx.super = *v;
box->vlast = &mbox->module_ctx.super;