# HG changeset patch # User Timo Sirainen # Date 1496943279 -10800 # Node ID 961af1f77dc9d8cce0fe060daefd9dbd6ec6b01a # Parent 876f2875287fdadd7b2c7dac987db6a735d0577a imap-quota: If quota lookups fail, return NO for GETQUOTA/GETQUOTAROOT diff -r 876f2875287f -r 961af1f77dc9 src/plugins/imap-quota/imap-quota-plugin.c --- a/src/plugins/imap-quota/imap-quota-plugin.c Thu Jun 08 20:34:27 2017 +0300 +++ b/src/plugins/imap-quota/imap-quota-plugin.c Thu Jun 08 20:34:39 2017 +0300 @@ -31,7 +31,7 @@ QUOTA_USER_SEPARATOR, name); } -static void +static int quota_reply_write(string_t *str, struct mail_user *user, struct mail_user *owner, struct quota_root *root) { @@ -61,15 +61,13 @@ i++; } } - if (ret == 0 && str_len(str) == prefix_len) { + if (ret <= 0 && str_len(str) == prefix_len) { /* this quota root doesn't have any quota actually enabled. */ str_truncate(str, orig_len); - return; + return ret; } str_append(str, ")\r\n"); - - if (ret < 0) - str_append(str, "* BAD Internal quota calculation error\r\n"); + return 1; } static bool cmd_getquotaroot(struct client_command_context *cmd) @@ -82,6 +80,7 @@ struct quota_root *root; const char *mailbox, *orig_mailbox, *name; string_t *quotaroot_reply, *quota_reply; + int ret; /* */ if (!client_read_string_args(cmd, 1, &mailbox)) @@ -109,6 +108,7 @@ str_append(quotaroot_reply, "* QUOTAROOT "); imap_append_astring(quotaroot_reply, orig_mailbox); + ret = 0; iter = quota_root_iter_init(box); while ((root = quota_root_iter_next(iter)) != NULL) { if (quota_root_is_hidden(root)) @@ -117,13 +117,16 @@ name = imap_quota_root_get_name(client->user, ns->owner, root); imap_append_astring(quotaroot_reply, name); - quota_reply_write(quota_reply, client->user, ns->owner, root); + if (quota_reply_write(quota_reply, client->user, ns->owner, root) < 0) + ret = -1; } quota_root_iter_deinit(&iter); mailbox_free(&box); /* send replies */ - if (str_len(quota_reply) == 0) + if (ret < 0) + client_send_tagline(cmd, "NO Internal quota calculation error."); + else if (str_len(quota_reply) == 0) client_send_tagline(cmd, "OK No quota."); else { client_send_line(client, str_c(quotaroot_reply)); @@ -172,11 +175,13 @@ } quota_reply = t_str_new(128); - quota_reply_write(quota_reply, cmd->client->user, owner, root); - o_stream_nsend(cmd->client->output, str_data(quota_reply), - str_len(quota_reply)); - - client_send_tagline(cmd, "OK Getquota completed."); + if (quota_reply_write(quota_reply, cmd->client->user, owner, root) < 0) + client_send_tagline(cmd, "NO Internal quota calculation error."); + else { + o_stream_nsend(cmd->client->output, str_data(quota_reply), + str_len(quota_reply)); + client_send_tagline(cmd, "OK Getquota completed."); + } return TRUE; }