]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lazy-expunge: Use mailbox_move() instead of mailbox_copy()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 26 Feb 2017 12:32:44 +0000 (14:32 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Sun, 26 Feb 2017 12:32:44 +0000 (14:32 +0200)
This allows some optimizations to be performed that are only possible when
moving messages.

It's slightly strange now that mail_expunge() is triggered twice for the
same source mail, but lazy_expunge plugin is called very early so most
plugins won't see it called twice. Currently only acl plugin sees it, and
it doesn't care.

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

index 3c10d5366b88ea9a6a88bd55aaa97cac7950c954..3eda8268f8194d2e73903f73184750205a930ada 100644 (file)
@@ -30,6 +30,7 @@
 struct lazy_expunge_mail {
        union mail_module_context module_ctx;
        bool moving;
+       bool recursing;
 };
 
 struct lazy_expunge_mail_user {
@@ -288,6 +289,10 @@ static void lazy_expunge_mail_expunge(struct mail *_mail)
 
        if (lt->delayed_error != MAIL_ERROR_NONE)
                return;
+       if (mmail->recursing) {
+               mmail->module_ctx.super.expunge(_mail);
+               return;
+       }
 
        /* Clear this in case the mail is used for non-move later on. */
        mmail->moving = FALSE;
@@ -344,9 +349,11 @@ static void lazy_expunge_mail_expunge(struct mail *_mail)
        save_ctx = mailbox_save_alloc(lt->dest_trans);
        mailbox_save_copy_flags(save_ctx, _mail);
        save_ctx->data.flags &= ~MAIL_DELETED;
-       if (mailbox_copy(&save_ctx, _mail) < 0 && !_mail->expunged)
+
+       mmail->recursing = TRUE;
+       if (mailbox_move(&save_ctx, _mail) < 0 && !_mail->expunged)
                lazy_expunge_set_error(lt, lt->dest_box->storage);
-       mmail->module_ctx.super.expunge(_mail);
+       mmail->recursing = FALSE;
 }
 
 static int lazy_expunge_copy(struct mail_save_context *ctx, struct mail *_mail)