]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
trash plugin: Count more correctly the number of bytes/messages needed to get under...
authorTimo Sirainen <tss@iki.fi>
Wed, 29 Apr 2015 08:27:50 +0000 (10:27 +0200)
committerTimo Sirainen <tss@iki.fi>
Wed, 29 Apr 2015 08:27:50 +0000 (10:27 +0200)
If there already were some messages saved, those weren't counted when
figuring out how many/much mails are still needed to be expunged.

Patch by Alexei Gradinari

src/plugins/trash/trash-plugin.c

index 939cbf9f89213f192bc4a771f0d6a7e6f36cbbdf..035900f30429ad2b385a1cf39cc9af68ed3e2708 100644 (file)
@@ -222,6 +222,8 @@ trash_quota_test_alloc(struct quota_transaction_context *ctx,
                       uoff_t size, bool *too_large_r)
 {
        int ret, i;
+       uint64_t size_needed = 0;
+       unsigned int count_needed = 0;
 
        for (i = 0; ; i++) {
                ret = trash_next_quota_test_alloc(ctx, size, too_large_r);
@@ -241,9 +243,15 @@ trash_quota_test_alloc(struct quota_transaction_context *ctx,
                        break;
                }
 
+               if (ctx->bytes_ceil != (uint64_t)-1 &&
+                   ctx->bytes_ceil < size + ctx->bytes_over)
+                       size_needed = size + ctx->bytes_over - ctx->bytes_ceil;
+               if (ctx->count_ceil != (uint64_t)-1 &&
+                   ctx->count_ceil < 1 + ctx->count_over)
+                       count_needed = 1 + ctx->count_over - ctx->count_ceil;
+
                /* not enough space. try deleting some from mailbox. */
-               ret = trash_try_clean_mails(ctx, size + ctx->bytes_over,
-                                           1 + ctx->count_over);
+               ret = trash_try_clean_mails(ctx, size_needed, count_needed);
                if (ret <= 0)
                        return 0;
        }