Skip to content

Commit

Permalink
quota-status: Support recipient_delimiter
Browse files Browse the repository at this point in the history
  • Loading branch information
cmouse committed Jul 4, 2017
1 parent 9f04297 commit 7dd64d2
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/plugins/quota/Makefile.am
Expand Up @@ -63,7 +63,9 @@ lib10_doveadm_quota_plugin_la_SOURCES = \
doveadm-quota.c

quota_status_SOURCES = \
quota-status.c
quota-status.c \
quota-status-settings.c

quota_status_CPPFLAGS = $(AM_CPPFLAGS) $(BINARY_CFLAGS)
quota_status_LDADD = \
$(quota_common_objects) \
Expand Down Expand Up @@ -109,6 +111,8 @@ pkginc_lib_HEADERS = \
quota-fs.h \
quota-plugin.h \
quota-private.h
noinst_HEADERS = \
quota-status-settings.h

EXTRA_DIST = rquota.x

Expand Down
37 changes: 37 additions & 0 deletions src/plugins/quota/quota-status-settings.c
@@ -0,0 +1,37 @@
/* Copyright (c) 2017 Dovecot authors, see the included COPYING file */

#include "lib.h"
#include "settings-parser.h"
#include "service-settings.h"
#include "mail-storage-settings.h"
#include "quota-status-settings.h"

#undef DEF
#define DEF(type, name) \
{ type, #name, offsetof(struct quota_status_settings, name), NULL }

static const struct setting_define quota_status_setting_defines[] = {
DEF(SET_STR, recipient_delimiter),

SETTING_DEFINE_LIST_END
};

static const struct quota_status_settings quota_status_default_settings = {
.recipient_delimiter = "+",
};

static const struct setting_parser_info *quota_status_setting_dependencies[] = {
NULL
};

const struct setting_parser_info quota_status_setting_parser_info = {
.module_name = "mail",
.defines = quota_status_setting_defines,
.defaults = &quota_status_default_settings,

.type_offset = (size_t)-1,
.struct_size = sizeof(struct quota_status_settings),

.parent_offset = (size_t)-1,
.dependencies = quota_status_setting_dependencies
};
10 changes: 10 additions & 0 deletions src/plugins/quota/quota-status-settings.h
@@ -0,0 +1,10 @@
#ifndef QUOTA_STATUS_SETTINGS_H
#define QUOTA_STATUS_SETTINGS_H 1

struct quota_status_settings {
char *recipient_delimiter;
};

extern const struct setting_parser_info quota_status_setting_parser_info;

#endif
22 changes: 19 additions & 3 deletions src/plugins/quota/quota-status.c
Expand Up @@ -4,14 +4,17 @@
#include "ostream.h"
#include "connection.h"
#include "restrict-access.h"
#include "settings-parser.h"
#include "master-service.h"
#include "master-service-settings.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "mail-storage-settings.h"
#include "mail-storage-service.h"
#include "message-address.h"
#include "quota-private.h"
#include "quota-plugin.h"
#include "quota-status-settings.h"

enum quota_protocol {
QUOTA_PROTOCOL_UNKNOWN = 0,
Expand All @@ -25,6 +28,7 @@ struct quota_client {
uoff_t size;
};

static struct quota_status_settings *quota_status_settings;
static pool_t quota_status_pool;
static enum quota_protocol protocol;
static struct mail_storage_service_ctx *storage_service;
Expand Down Expand Up @@ -79,6 +83,8 @@ static void client_handle_request(struct quota_client *client)
struct mail_storage_service_user *service_user;
struct mail_user *user;
const char *value = NULL, *error;
const char *detail ATTR_UNUSED;
char delim ATTR_UNUSED;
int ret;

if (client->recipient == NULL) {
Expand All @@ -87,8 +93,9 @@ static void client_handle_request(struct quota_client *client)
}

i_zero(&input);
input.username = client->recipient;

message_detail_address_parse(quota_status_settings->recipient_delimiter,
client->recipient, &input.username, &delim,
&detail);
ret = mail_storage_service_lookup_next(storage_service, &input,
&service_user, &user, &error);
restrict_access_allow_coredumps(TRUE);
Expand Down Expand Up @@ -190,15 +197,20 @@ static void main_preinit(void)

static void main_init(void)
{
static const struct setting_parser_info *set_roots[] = {
&quota_status_setting_parser_info,
NULL
};
struct mail_storage_service_input input;
const struct setting_parser_info *user_info;
const struct setting_parser_context *set_parser;
const struct mail_user_settings *user_set;
const struct quota_status_settings *set;
const char *value, *error;
pool_t pool;

clients = connection_list_init(&client_set, &client_vfuncs);
storage_service = mail_storage_service_init(master_service, NULL,
storage_service = mail_storage_service_init(master_service, set_roots,
MAIL_STORAGE_SERVICE_FLAG_USERDB_LOOKUP |
MAIL_STORAGE_SERVICE_FLAG_TEMP_PRIV_DROP |
MAIL_STORAGE_SERVICE_FLAG_ENABLE_CORE_DUMPS |
Expand All @@ -217,6 +229,10 @@ static void main_init(void)
i_fatal("%s", error);
user_set = master_service_settings_parser_get_others(master_service,
set_parser)[0];
set = master_service_settings_get_others(master_service)[1];

quota_status_settings = settings_dup(&quota_status_setting_parser_info, set,
quota_status_pool);
value = mail_user_set_plugin_getenv(user_set, "quota_status_nouser");
nouser_reply = p_strdup(quota_status_pool,
value != NULL ? value : "REJECT Unknown user");
Expand Down

0 comments on commit 7dd64d2

Please sign in to comment.