<commit_before>/* Copyright (C) 2005 <NAME> */

#include "common.h"
#include "str.h"
#include "imap-quote.h"
#include "commands.h"
#include "quota.h"
#include "quota-plugin.h"
#include "imap-quota-plugin.h"

#include <stdlib.h>

const char *imap_quota_plugin_version = PACKAGE_VERSION;

static void
quota_send(struct client_command_context *cmd, struct quota_root *root)
{
        const char *const *list;
	string_t *str;
	unsigned int i;
	uint64_t value, limit;
	int ret;

	t_push();

	str = t_str_new(128);
	str_append(str, "* QUOTA ");
	imap_quote_append_string(str, quota_root_get_name(root), FALSE);

	str_append(str, " (");
	list = quota_root_get_resources(root);
	for (i = 0; *list != NULL; list++) {
		ret = quota_get_resource(root, "", *list, &value, &limit);
		if (ret > 0) {
			if (i > 0)
				str_append_c(str, ' ');
			str_printfa(str, "%s %llu %llu", *list,
				    (unsigned long long)value,
				    (unsigned long long)limit);
			i++;
		} else if (ret < 0) {
			client_send_line(cmd->client, 
				"* BAD Internal quota calculation error");
		}
	}
	str_append_c(str, ')');
	client_send_line(cmd->client, str_c(str));

	t_pop();
}

static bool cmd_getquotaroot(struct client_command_context *cmd)
{
	struct mail_storage *storage;
	struct mailbox *box;
	struct quota_root_iter *iter;
        struct quota_root *root;
	const char *mailbox;
	string_t *str;

	/* <mailbox> */
	if (!client_read_string_args(cmd, 1, &mailbox))
		return FALSE;

	storage = client_find_storage(cmd, &mailbox);
	if (storage == NULL)
		return TRUE;

	box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
						    MAILBOX_OPEN_FAST |
						    MAILBOX_OPEN_KEEP_RECENT));
	if (box == NULL) {
		client_send_storage_error(cmd, storage);
		return TRUE;
	}

	if (quota_set == NULL) {
		mailbox_close(&box);
		client_send_tagline(cmd, "OK No quota.");
		return TRUE;
	}

	/* send QUOTAROOT reply */
	str = t_str_new(128);
	str_append(str, "* QUOTAROOT ");
	imap_quote_append_string(str, mailbox, FALSE);

	iter = quota_root_iter_init(quota_set, box);
	while ((root = quota_root_iter_next(iter)) != NULL) {
		str_append_c(str, ' ');
		imap_quote_append_string(str, quota_root_get_name(root), FALSE);
	}
	quota_root_iter_deinit(iter);
	client_send_line(cmd->client, str_c(str));

	/* send QUOTA reply for each quotaroot */
	iter = quota_root_iter_init(quota_set, box);
	while ((root = quota_root_iter_next(iter)) != NULL)
		quota_send(cmd, root);
	quota_root_iter_deinit(iter);

	mailbox_close(&box);

	client_send_tagline(cmd, "OK Getquotaroot completed.");
	return TRUE;
}
<commit_msg>When returning mailbox name with GETQUOTAROOT, return the original name instead of the converted storage name.<commit_after>/* Copyright (C) 2005 <NAME> */

#include "common.h"
#include "str.h"
#include "imap-quote.h"
#include "commands.h"
#include "quota.h"
#include "quota-plugin.h"
#include "imap-quota-plugin.h"

#include <stdlib.h>

const char *imap_quota_plugin_version = PACKAGE_VERSION;

static void
quota_send(struct client_command_context *cmd, struct quota_root *root)
{
        const char *const *list;
	string_t *str;
	unsigned int i;
	uint64_t value, limit;
	int ret;

	t_push();

	str = t_str_new(128);
	str_append(str, "* QUOTA ");
	imap_quote_append_string(str, quota_root_get_name(root), FALSE);

	str_append(str, " (");
	list = quota_root_get_resources(root);
	for (i = 0; *list != NULL; list++) {
		ret = quota_get_resource(root, "", *list, &value, &limit);
		if (ret > 0) {
			if (i > 0)
				str_append_c(str, ' ');
			str_printfa(str, "%s %llu %llu", *list,
				    (unsigned long long)value,
				    (unsigned long long)limit);
			i++;
		} else if (ret < 0) {
			client_send_line(cmd->client, 
				"* BAD Internal quota calculation error");
		}
	}
	str_append_c(str, ')');
	client_send_line(cmd->client, str_c(str));

	t_pop();
}

static bool cmd_getquotaroot(struct client_command_context *cmd)
{
	struct mail_storage *storage;
	struct mailbox *box;
	struct quota_root_iter *iter;
        struct quota_root *root;
	const char *orig_mailbox, *mailbox;
	string_t *str;

	/* <mailbox> */
	if (!client_read_string_args(cmd, 1, &mailbox))
		return FALSE;

	orig_mailbox = mailbox;
	storage = client_find_storage(cmd, &mailbox);
	if (storage == NULL)
		return TRUE;

	box = mailbox_open(storage, mailbox, NULL, (MAILBOX_OPEN_READONLY |
						    MAILBOX_OPEN_FAST |
						    MAILBOX_OPEN_KEEP_RECENT));
	if (box == NULL) {
		client_send_storage_error(cmd, storage);
		return TRUE;
	}

	if (quota_set == NULL) {
		mailbox_close(&box);
		client_send_tagline(cmd, "OK No quota.");
		return TRUE;
	}

	/* send QUOTAROOT reply */
	str = t_str_new(128);
	str_append(str, "* QUOTAROOT ");
	imap_quote_append_string(str, orig_mailbox, FALSE);

	iter = quota_root_iter_init(quota_set, box);
	while ((root = quota_root_iter_next(iter)) != NULL) {
		str_append_c(str, ' ');
		imap_quote_append_string(str, quota_root_get_name(root), FALSE);
	}
	quota_root_iter_deinit(iter);
	client_send_line(cmd->client, str_c(str));

	/* send QUOTA reply for each quotaroot */
	iter = quota_root_iter_init(quota_set, box);
	while ((root = quota_root_iter_next(iter)) != NULL)
		quota_send(cmd, root);
	quota_root_iter_deinit(iter);

	mailbox_close(&box);

	client_send_tagline(cmd, "OK Getquotaroot completed.");
	return TRUE;
}

{'fraction_non_alphanumeric': 0.14027149321266968, 'fraction_numerical': 0.00641025641025641, 'mean_word_length': 4.655650319829424, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6190858', 'n_tokens_mistral': 2225, 'n_tokens_neox': 2036, 'n_words': 438}