imap-settings.c revision 7bafda1813454621e03615e83d55bccfa7cc56bd
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "lib.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "buffer.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "settings-parser.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "service-settings.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "mail-storage-settings.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include "imap-settings.h"
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include <stddef.h>
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include <stdlib.h>
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#include <unistd.h>
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic bool imap_settings_verify(void *_set, pool_t pool,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch const char **error_r);
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* <settings checks> */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic struct file_listener_settings imap_unix_listeners_array[] = {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch { "login/imap", 0666, "", "" }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch};
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic struct file_listener_settings *imap_unix_listeners[] = {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch &imap_unix_listeners_array[0]
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch};
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic buffer_t imap_unix_listeners_buf = {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch imap_unix_listeners, sizeof(imap_unix_listeners), { 0, }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch};
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch/* </settings checks> */
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstruct service_settings imap_service_settings = {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .name = "imap",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .protocol = "imap",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .type = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .executable = "imap",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .user = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .group = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .privileged_group = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .extra_groups = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .chroot = "",
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .drop_priv_before_exec = FALSE,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .process_min_avail = 0,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .process_limit = 0,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .client_limit = 0,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .service_count = 1,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .vsz_limit = -1U,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen .unix_listeners = { { &imap_unix_listeners_buf,
f9d2a1f21ad65262bc630f0834d7eead06a1bac3Timo Sirainen sizeof(imap_unix_listeners[0]) } },
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .fifo_listeners = ARRAY_INIT,
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch .inet_listeners = ARRAY_INIT
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch};
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#undef DEF
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#undef DEFLIST
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#define DEF(type, name) \
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch { type, #name, offsetof(struct imap_settings, name), NULL }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch#define DEFLIST(field, name, defines) \
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch { SET_DEFLIST, name, offsetof(struct imap_settings, field), defines }
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Boschstatic const struct setting_define imap_setting_defines[] = {
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_BOOL, mail_debug),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_BOOL, verbose_proctitle),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_SIZE, imap_max_line_length),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_TIME, imap_idle_notify_interval),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_STR, imap_capability),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_STR, imap_client_workarounds),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_STR, imap_logout_format),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_STR, imap_id_send),
3fcb3d2d1f3583025ff62bae95ec706920f398b1Stephan Bosch DEF(SET_STR, imap_id_log),
SETTING_DEFINE_LIST_END
};
static const struct imap_settings imap_default_settings = {
.mail_debug = FALSE,
.verbose_proctitle = FALSE,
/* RFC-2683 recommends at least 8000 bytes. Some clients however don't
break large message sets to multiple commands, so we're pretty
liberal by default. */
.imap_max_line_length = 64*1024,
.imap_idle_notify_interval = 2*60,
.imap_capability = "",
.imap_client_workarounds = "outlook-idle",
.imap_logout_format = "bytes=%i/%o",
.imap_id_send = "",
.imap_id_log = ""
};
static const struct setting_parser_info *imap_setting_dependencies[] = {
&mail_user_setting_parser_info,
NULL
};
const struct setting_parser_info imap_setting_parser_info = {
.module_name = "imap",
.defines = imap_setting_defines,
.defaults = &imap_default_settings,
.type_offset = (size_t)-1,
.struct_size = sizeof(struct imap_settings),
.parent_offset = (size_t)-1,
.check_func = imap_settings_verify,
.dependencies = imap_setting_dependencies
};
/* <settings checks> */
struct imap_client_workaround_list {
const char *name;
enum imap_client_workarounds num;
};
static const struct imap_client_workaround_list imap_client_workaround_list[] = {
{ "delay-newmail", WORKAROUND_DELAY_NEWMAIL },
{ "outlook-idle", 0 }, /* only for backwards compatibility */
{ "netscape-eoh", WORKAROUND_NETSCAPE_EOH },
{ "tb-extra-mailbox-sep", WORKAROUND_TB_EXTRA_MAILBOX_SEP },
{ NULL, 0 }
};
static int
imap_settings_parse_workarounds(struct imap_settings *set,
const char **error_r)
{
enum imap_client_workarounds client_workarounds = 0;
const struct imap_client_workaround_list *list;
const char *const *str;
str = t_strsplit_spaces(set->imap_client_workarounds, " ,");
for (; *str != NULL; str++) {
list = imap_client_workaround_list;
for (; list->name != NULL; list++) {
if (strcasecmp(*str, list->name) == 0) {
client_workarounds |= list->num;
break;
}
}
if (list->name == NULL) {
*error_r = t_strdup_printf("imap_client_workarounds: "
"Unknown workaround: %s", *str);
return -1;
}
}
set->parsed_workarounds = client_workarounds;
return 0;
}
static bool
imap_settings_verify(void *_set, pool_t pool ATTR_UNUSED, const char **error_r)
{
struct imap_settings *set = _set;
if (imap_settings_parse_workarounds(set, error_r) < 0)
return FALSE;
return TRUE;
}
/* </settings checks> */