From: Timo Sirainen Date: Wed, 29 Apr 2015 08:27:50 +0000 (+0200) Subject: trash plugin: Count more correctly the number of bytes/messages needed to get under... X-Git-Tag: 2.2.17.rc1~130 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcdf3baace79a5ebaaa8f8b4baadae258e972c1b;p=thirdparty%2Fdovecot%2Fcore.git trash plugin: Count more correctly the number of bytes/messages needed to get under quota. 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 --- diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index 939cbf9f89..035900f304 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -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; }