]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lazy-expunge: Fixed using a mailbox (instead of namespace) as lazy_expunge destination.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 20 Apr 2016 14:10:17 +0000 (17:10 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 20 Apr 2016 16:07:24 +0000 (19:07 +0300)
The initial implementation in f2d7ae020bda762f78e8e639a69fb129230cbb7d was
completely broken.

src/plugins/lazy-expunge/lazy-expunge-plugin.c

index 59530e080c6ecd6d4ab0da0c5efc9b6b5213c446..8a357d79ce751dbe909633cdb4c248ced012ad22 100644 (file)
@@ -209,6 +209,30 @@ static int lazy_expunge_mail_is_last_instace(struct mail *_mail)
        return refcount <= 1 ? 1 : 0;
 }
 
+static bool lazy_expunge_is_internal_mailbox(struct mailbox *box)
+{
+       struct mail_namespace *ns = box->list->ns;
+       struct lazy_expunge_mail_user *luser =
+               LAZY_EXPUNGE_USER_CONTEXT(ns->user);
+       struct lazy_expunge_mailbox_list *llist =
+               LAZY_EXPUNGE_LIST_CONTEXT(box->list);
+
+       if (llist == NULL) {
+               /* lazy_expunge not enabled at all */
+               return FALSE;
+       }
+       if (llist->internal_namespace) {
+               /* lazy-expunge namespace */
+               return TRUE;
+       }
+       if (luser->lazy_mailbox_vname != NULL &&
+           strcmp(luser->lazy_mailbox_vname, box->vname) == 0) {
+               /* lazy-expunge mailbox */
+               return TRUE;
+       }
+       return FALSE;
+}
+
 static void lazy_expunge_mail_expunge(struct mail *_mail)
 {
        struct mail_namespace *ns = _mail->box->list->ns;
@@ -218,8 +242,6 @@ static void lazy_expunge_mail_expunge(struct mail *_mail)
        union mail_module_context *mmail = LAZY_EXPUNGE_MAIL_CONTEXT(mail);
        struct lazy_expunge_transaction *lt =
                LAZY_EXPUNGE_CONTEXT(_mail->transaction);
-       struct lazy_expunge_mailbox_list *llist;
-       struct mailbox *real_box;
        struct mail *real_mail;
        struct mail_save_context *save_ctx;
        const char *error;
@@ -231,9 +253,7 @@ static void lazy_expunge_mail_expunge(struct mail *_mail)
                lt->failed = TRUE;
                return;
        }
-       real_box = real_mail->box;
-       llist = LAZY_EXPUNGE_LIST_CONTEXT(real_box->list);
-       if (llist != NULL && llist->internal_namespace) {
+       if (lazy_expunge_is_internal_mailbox(real_mail->box)) {
                mmail->super.expunge(_mail);
                return;
        }
@@ -399,13 +419,17 @@ static void lazy_expunge_mailbox_allocated(struct mailbox *box)
        box->vlast = &mbox->super;
        MODULE_CONTEXT_SET_SELF(box, lazy_expunge_mail_storage_module, mbox);
 
-       if (!llist->internal_namespace) {
+       if (!lazy_expunge_is_internal_mailbox(box)) {
                v->transaction_begin = lazy_expunge_transaction_begin;
                v->transaction_commit = lazy_expunge_transaction_commit;
                v->transaction_rollback = lazy_expunge_transaction_rollback;
                v->rename_box = lazy_expunge_mailbox_rename;
-       } else {
+       } else if (llist->internal_namespace) {
                v->rename_box = lazy_expunge_mailbox_rename;
+       } else {
+               /* internal mailbox in a non-internal namespace -
+                  don't add any unnecessary restrictions to it. if it's not
+                  wanted, just use the ACL plugin. */
        }
 }
 
@@ -441,16 +465,16 @@ lazy_expunge_mail_namespaces_created(struct mail_namespace *namespaces)
                return;
 
        luser->lazy_ns = mail_namespace_find_prefix(namespaces, luser->env);
-       if (luser->lazy_ns == NULL) {
+       if (luser->lazy_ns != NULL) {
+               /* we don't want to override this namespace's expunge operation. */
+               llist = LAZY_EXPUNGE_LIST_CONTEXT(luser->lazy_ns->list);
+               llist->internal_namespace = TRUE;
+       } else {
                /* store the the expunged mails to the specified mailbox. */
                luser->lazy_ns = mail_namespace_find(namespaces, luser->env);
                luser->lazy_mailbox_vname = luser->env;
        }
        mail_namespace_ref(luser->lazy_ns);
-
-       /* we don't want to override this namespace's expunge operation. */
-       llist = LAZY_EXPUNGE_LIST_CONTEXT(luser->lazy_ns->list);
-       llist->internal_namespace = TRUE;
 }
 
 static void lazy_expunge_user_deinit(struct mail_user *user)