bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "lib.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "settings-parser.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "mail-storage-settings.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include "pop3c-settings.h"
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#include <stddef.h>
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#undef DEF
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen#define DEF(type, name) \
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen { type, #name, offsetof(struct pop3c_settings, name), NULL }
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic const struct setting_define pop3c_setting_defines[] = {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_STR, pop3c_host),
009217abb57a24a4076092e8e4e165545747839eStephan Bosch DEF(SET_IN_PORT, pop3c_port),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_STR_VARS, pop3c_user),
0ca3b9cb0f2a322a25ce7f229dc3d3a0b46be17bTimo Sirainen DEF(SET_STR_VARS, pop3c_master_user),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_STR, pop3c_password),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_ENUM, pop3c_ssl),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_BOOL, pop3c_ssl_verify),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen DEF(SET_STR, pop3c_rawlog_dir),
5f4e547bb810403e8cfb19a49d8fe34713507ffdTimo Sirainen DEF(SET_BOOL, pop3c_quick_received_date),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi DEF(SET_STR, pop3c_features),
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen SETTING_DEFINE_LIST_END
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen};
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic const struct pop3c_settings pop3c_default_settings = {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .pop3c_host = "",
83e6a1162fe1cf262ec679f30f43e12dfee750c0Timo Sirainen .pop3c_port = 110,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .pop3c_user = "%u",
0ca3b9cb0f2a322a25ce7f229dc3d3a0b46be17bTimo Sirainen .pop3c_master_user = "",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .pop3c_password = "",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .pop3c_ssl = "no:pop3s:starttls",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .pop3c_ssl_verify = TRUE,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
5f4e547bb810403e8cfb19a49d8fe34713507ffdTimo Sirainen .pop3c_rawlog_dir = "",
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi .pop3c_quick_received_date = FALSE,
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi .pop3c_features = ""
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi};
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi/* <settings checks> */
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomistruct pop3c_feature_list {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi const char *name;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi enum pop3c_features num;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen};
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomistatic const struct pop3c_feature_list pop3c_feature_list[] = {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi { "no-pipelining", POP3C_FEATURE_NO_PIPELINING },
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi { NULL, 0 }
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi};
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomistatic int
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomipop3c_settings_parse_features(struct pop3c_settings *set,
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi const char **error_r)
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi{
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi enum pop3c_features features = 0;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi const struct pop3c_feature_list *list;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi const char *const *str;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi str = t_strsplit_spaces(set->pop3c_features, " ,");
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi for (; *str != NULL; str++) {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi list = pop3c_feature_list;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi for (; list->name != NULL; list++) {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi if (strcasecmp(*str, list->name) == 0) {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi features |= list->num;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi break;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi }
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi }
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi if (list->name == NULL) {
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi *error_r = t_strdup_printf("pop3c_features: "
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi "Unknown feature: %s", *str);
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi return -1;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi }
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi }
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi set->parsed_features = features;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi return 0;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi}
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomistatic bool pop3c_settings_check(void *_set, pool_t pool ATTR_UNUSED,
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi const char **error_r)
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi{
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi struct pop3c_settings *set = _set;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi if (pop3c_settings_parse_features(set, error_r) < 0)
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi return FALSE;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi return TRUE;
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi}
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi/* </settings checks> */
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenstatic const struct setting_parser_info pop3c_setting_parser_info = {
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .module_name = "pop3c",
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .defines = pop3c_setting_defines,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .defaults = &pop3c_default_settings,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .type_offset = (size_t)-1,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .struct_size = sizeof(struct pop3c_settings),
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .parent_offset = (size_t)-1,
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen .parent = &mail_user_setting_parser_info,
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi
ec3eb53293a282b409fe128153038522c294dda3Aki Tuomi .check_func = pop3c_settings_check
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen};
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainenconst struct setting_parser_info *pop3c_get_setting_parser_info(void)
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen{
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen return &pop3c_setting_parser_info;
01435c38e7d671d5a892c4b802cfb204881cd454Timo Sirainen}