changeset 22179:549b74a60b5c

imap-quota: If quota root doesn't have any quotas, don't send empty QUOTA reply For example if GETQUOTA is asked for fs quota, but the user doesn't have fs quota enabled.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 08 Jun 2017 20:24:26 +0300
parents e97e52bd980f
children d48b39c113d0
files src/plugins/imap-quota/imap-quota-plugin.c
diffstat 1 files changed, 7 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/imap-quota/imap-quota-plugin.c	Thu Jun 08 20:29:05 2017 +0300
+++ b/src/plugins/imap-quota/imap-quota-plugin.c	Thu Jun 08 20:24:26 2017 +0300
@@ -38,6 +38,7 @@
         const char *name, *const *list;
 	unsigned int i;
 	uint64_t value, limit;
+	size_t prefix_len, orig_len = str_len(str);
 	int ret = 0;
 
 	str_append(str, "* QUOTA ");
@@ -45,6 +46,7 @@
 	imap_append_astring(str, name);
 
 	str_append(str, " (");
+	prefix_len = str_len(str);
 	list = quota_root_get_resources(root);
 	for (i = 0; *list != NULL; list++) {
 		ret = quota_get_resource(root, "", *list, &value, &limit);
@@ -59,6 +61,11 @@
 			i++;
 		}
 	}
+	if (ret == 0 && str_len(str) == prefix_len) {
+		/* this quota root doesn't have any quota actually enabled. */
+		str_truncate(str, orig_len);
+		return;
+	}
 	str_append(str, ")\r\n");
 
 	if (ret < 0)