case QUOTA_ALLOC_RESULT_OVER_QUOTA_LIMIT:
case QUOTA_ALLOC_RESULT_OVER_QUOTA:
return qt->quota->set->quota_exceeded_msg;
+ case QUOTA_ALLOC_RESULT_OVER_QUOTA_MAILBOX_LIMIT:
+ return "Too many messages in the mailbox";
}
i_unreached();
}
}
}
+ const char *max_box_count =
+ mail_user_plugin_getenv(user, "quota_mailbox_message_count");
+ if (max_box_count != NULL) {
+ const char *error;
+ if (str_parse_uint(max_box_count,
+ "a_set->max_messages_per_mailbox,
+ &error) < 0) {
+ *error_r = t_strdup_printf(
+ "quota_mailbox_message_count: %s", error);
+ return -1;
+ }
+ }
+
p_array_init("a_set->root_sets, pool, 4);
if (i_strocpy(root_name, "quota", sizeof(root_name)) < 0)
i_unreached();
enum quota_get_result *error_result_r,
const char **error_r)
{
+ const struct quota_settings *set = ctx->quota->set;
struct quota_root *const *roots;
const char *mailbox_name, *error;
unsigned int i, count;
}
}
}
+
+ if (set->max_messages_per_mailbox != 0) {
+ struct mailbox_status status;
+ mailbox_get_open_status(ctx->box, STATUS_MESSAGES, &status);
+ if (status.messages <= set->max_messages_per_mailbox) {
+ diff = set->max_messages_per_mailbox - status.messages;
+ if (ctx->count_ceil > diff)
+ ctx->count_ceil = diff;
+ } else {
+ /* over quota */
+ ctx->count_ceil = 0;
+ diff = status.messages - set->max_messages_per_mailbox;
+ if (ctx->count_over < diff)
+ ctx->count_over = diff;
+ }
+ }
return 0;
}
if (!quota_transaction_is_over(ctx, size))
return QUOTA_ALLOC_RESULT_OK;
+ if (ctx->quota->set->max_messages_per_mailbox != 0) {
+ struct mailbox_status status;
+ mailbox_get_open_status(ctx->box, STATUS_MESSAGES, &status);
+ unsigned int new_count = status.messages + ctx->count_used;
+ if (new_count >= ctx->quota->set->max_messages_per_mailbox)
+ return QUOTA_ALLOC_RESULT_OVER_QUOTA_MAILBOX_LIMIT;
+ }
+
/* limit reached. */
roots = array_get(&ctx->quota->roots, &count);
for (i = 0; i < count; i++) {
QUOTA_ALLOC_RESULT_OVER_QUOTA,
/* Mail size is larger than even the maximum allowed quota. */
QUOTA_ALLOC_RESULT_OVER_QUOTA_LIMIT,
+ /* Maximum number of messages per mailbox was reached */
+ QUOTA_ALLOC_RESULT_OVER_QUOTA_MAILBOX_LIMIT,
/* Blocked by ongoing background quota calculation. */
QUOTA_ALLOC_RESULT_BACKGROUND_CALC,
};