dovecot-2.2: imap-quota: SETQUOTA supports now also user at domain:...

dovecot at dovecot.org dovecot at dovecot.org
Fri Dec 20 04:23:15 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/623b1d9414a6
changeset: 17082:623b1d9414a6
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Dec 20 04:23:04 2013 +0200
description:
imap-quota: SETQUOTA supports now also user at domain:quotaroot name.

diffstat:

 src/plugins/imap-quota/imap-quota-plugin.c |  47 +++++++++++++++++------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diffs (83 lines):

diff -r b7b4ff5a9eec -r 623b1d9414a6 src/plugins/imap-quota/imap-quota-plugin.c
--- a/src/plugins/imap-quota/imap-quota-plugin.c	Fri Dec 20 01:06:02 2013 +0200
+++ b/src/plugins/imap-quota/imap-quota-plugin.c	Fri Dec 20 04:23:04 2013 +0200
@@ -126,9 +126,30 @@
 	return TRUE;
 }
 
+static bool
+parse_quota_root(struct mail_user *user, const char *root_name,
+		 struct mail_user **owner_r, struct quota_root **root_r)
+{
+	const char *p;
+
+	*owner_r = user;
+	*root_r = quota_root_lookup(user, root_name);
+	if (*root_r != NULL || !user->admin)
+		return *root_r != NULL;
+
+	/* we're an admin. see if there's a quota root for another user. */
+	p = strchr(root_name, QUOTA_USER_SEPARATOR);
+	if (p != NULL) {
+		*owner_r = mail_user_find(user, t_strdup_until(root_name, p));
+		*root_r = *owner_r == NULL ? NULL :
+			quota_root_lookup(*owner_r, p + 1);
+	}
+	return *root_r != NULL;
+}
+
 static bool cmd_getquota(struct client_command_context *cmd)
 {
-	struct mail_user *owner = cmd->client->user;
+	struct mail_user *owner;
         struct quota_root *root;
 	const char *root_name;
 	string_t *quota_reply;
@@ -137,19 +158,7 @@
 	if (!client_read_string_args(cmd, 1, &root_name))
 		return FALSE;
 
-	root = quota_root_lookup(cmd->client->user, root_name);
-	if (root == NULL && cmd->client->user->admin) {
-		/* we're an admin. see if there's a quota root for another
-		   user. */
-		const char *p = strchr(root_name, QUOTA_USER_SEPARATOR);
-		if (p != NULL) {
-			owner = mail_user_find(cmd->client->user,
-					       t_strdup_until(root_name, p));
-			root = owner == NULL ? NULL :
-				quota_root_lookup(owner, p + 1);
-		}
-	}
-	if (root == NULL) {
+	if (!parse_quota_root(cmd->client->user, root_name, &owner, &root)) {
 		client_send_tagline(cmd, "NO Quota root doesn't exist.");
 		return TRUE;
 	}
@@ -166,6 +175,7 @@
 static bool cmd_setquota(struct client_command_context *cmd)
 {
 	struct quota_root *root;
+	struct mail_user *owner;
         const struct imap_arg *args, *list_args;
 	const char *root_name, *name, *value_str, *error;
 	uint64_t value;
@@ -180,14 +190,13 @@
 		return TRUE;
 	}
 
-	root = quota_root_lookup(cmd->client->user, root_name);
-	if (root == NULL) {
-		client_send_tagline(cmd, "NO Quota root doesn't exist.");
+	if (!cmd->client->user->admin) {
+		client_send_tagline(cmd, "NO Quota can be changed only by admin.");
 		return TRUE;
 	}
 
-	if (!cmd->client->user->admin) {
-		client_send_tagline(cmd, "NO Quota can be changed only by admin.");
+	if (!parse_quota_root(cmd->client->user, root_name, &owner, &root)) {
+		client_send_tagline(cmd, "NO Quota root doesn't exist.");
 		return TRUE;
 	}
 


More information about the dovecot-cvs mailing list