Mercurial > dovecot > original-hg > dovecot-2.2
changeset 17082:623b1d9414a6
imap-quota: SETQUOTA supports now also user@domain:quotaroot name.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 20 Dec 2013 04:23:04 +0200 |
parents | b7b4ff5a9eec |
children | f8ffa5e47e6f |
files | src/plugins/imap-quota/imap-quota-plugin.c |
diffstat | 1 files changed, 28 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- 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; }