dovecot-2.2: lib-storage: Added STATUS_CHECK_OVER_QUOTA for chec...

dovecot at dovecot.org dovecot at dovecot.org
Wed Sep 26 18:01:30 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/94f9dfa7cbaf
changeset: 15157:94f9dfa7cbaf
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Sep 24 14:31:16 2012 +0300
description:
lib-storage: Added STATUS_CHECK_OVER_QUOTA for checking if user is over quota.

diffstat:

 src/lib-storage/mail-storage.h    |   3 ++-
 src/plugins/quota/quota-storage.c |  31 +++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletions(-)

diffs (61 lines):

diff -r 0a5a3b760e2e -r 94f9dfa7cbaf src/lib-storage/mail-storage.h
--- a/src/lib-storage/mail-storage.h	Mon Sep 24 14:24:58 2012 +0300
+++ b/src/lib-storage/mail-storage.h	Mon Sep 24 14:31:16 2012 +0300
@@ -74,7 +74,8 @@
 	STATUS_HIGHESTMODSEQ	= 0x80,
 	STATUS_PERMANENT_FLAGS	= 0x200,
 	STATUS_FIRST_RECENT_UID	= 0x400,
-	STATUS_LAST_CACHED_SEQ	= 0x800
+	STATUS_LAST_CACHED_SEQ	= 0x800,
+	STATUS_CHECK_OVER_QUOTA	= 0x1000 /* return error if over quota */
 };
 
 enum mailbox_metadata_items {
diff -r 0a5a3b760e2e -r 94f9dfa7cbaf src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c	Mon Sep 24 14:24:58 2012 +0300
+++ b/src/plugins/quota/quota-storage.c	Mon Sep 24 14:31:16 2012 +0300
@@ -66,6 +66,36 @@
 	qmail->super.expunge(_mail);
 }
 
+static int
+quota_get_status(struct mailbox *box, enum mailbox_status_items items,
+		 struct mailbox_status *status_r)
+{
+	struct quota_mailbox *qbox = QUOTA_CONTEXT(box);
+	struct quota_transaction_context *qt;
+	bool too_large;
+	int ret = 0;
+
+	if ((items & STATUS_CHECK_OVER_QUOTA) != 0) {
+		qt = quota_transaction_begin(box);
+		if ((ret = quota_test_alloc(qt, 1, &too_large)) == 0) {
+			mail_storage_set_error(box->storage, MAIL_ERROR_NOSPACE,
+					       qt->quota->set->quota_exceeded_msg);
+			ret = -1;
+		}
+		quota_transaction_rollback(&qt);
+
+		if ((items & ~STATUS_CHECK_OVER_QUOTA) == 0) {
+			/* don't bother calling parent, it may unnecessarily
+			   try to open the mailbox */
+			return ret;
+		}
+	}
+
+	if (qbox->module_ctx.super.get_status(box, items, status_r) < 0)
+		ret = -1;
+	return ret < 0 ? -1 : 0;
+}
+
 static struct mailbox_transaction_context *
 quota_mailbox_transaction_begin(struct mailbox *box,
 				enum mailbox_transaction_flags flags)
@@ -376,6 +406,7 @@
 	qbox->module_ctx.super = *v;
 	box->vlast = &qbox->module_ctx.super;
 
+	v->get_status = quota_get_status;
 	v->transaction_begin = quota_mailbox_transaction_begin;
 	v->transaction_commit = quota_mailbox_transaction_commit;
 	v->transaction_rollback = quota_mailbox_transaction_rollback;


More information about the dovecot-cvs mailing list