Skip to content
Snippets Groups Projects
Commit 18ad56ff authored by Stephan Bosch's avatar Stephan Bosch Committed by Timo Sirainen
Browse files

lib-sieve: enotify extension: mailto method: Migrate settings to new config structure

parent c031d4bd
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,9 @@ AM_CPPFLAGS = \
libsieve_ext_enotify_mailto_la_SOURCES = \
uri-mailto.c \
ntfy-mailto-settings.c \
ntfy-mailto.c
noinst_HEADERS = \
uri-mailto.h
uri-mailto.h \
ntfy-mailto-settings.h
/* Copyright (c) 2024 Pigeonhole authors, see the included COPYING file
*/
#include "lib.h"
#include "array.h"
#include "settings.h"
#include "settings-parser.h"
#include "ntfy-mailto-settings.h"
static bool
ntfy_mailto_settings_check(void *_set, pool_t pool, const char **error_r);
#undef DEF
#define DEF(type, name) \
SETTING_DEFINE_STRUCT_##type("sieve_notify_mailto_"#name, name, \
struct ntfy_mailto_settings)
static const struct setting_define ntfy_mailto_setting_defines[] = {
DEF(STR, envelope_from),
SETTING_DEFINE_LIST_END,
};
static const struct ntfy_mailto_settings ntfy_mailto_default_settings = {
.envelope_from = "",
};
const struct setting_parser_info ntfy_mailto_setting_parser_info = {
.name = "sieve_notify_mailto",
.defines = ntfy_mailto_setting_defines,
.defaults = &ntfy_mailto_default_settings,
.struct_size = sizeof(struct ntfy_mailto_settings),
.check_func = ntfy_mailto_settings_check,
.pool_offset1 = 1 + offsetof(struct ntfy_mailto_settings, pool),
};
/* <settings checks> */
static bool
ntfy_mailto_settings_check(void *_set, pool_t pool, const char **error_r)
{
struct ntfy_mailto_settings *set = _set;
if (!sieve_address_source_parse(pool, set->envelope_from,
&set->parsed.envelope_from)) {
*error_r = t_strdup_printf("sieve_notify_mailto_envelope_from: "
"Invalid address source '%s'",
set->envelope_from);
return FALSE;
}
return TRUE;
}
/* </settings checks> */
#ifndef NTFY_MAILTO_SETTINGS_H
#define NTFY_MAILTO_SETTINGS_H
#include "sieve-address-source.h"
struct ntfy_mailto_settings {
pool_t pool;
const char *envelope_from;
struct {
struct sieve_address_source envelope_from;
} parsed;
};
extern const struct setting_parser_info ntfy_mailto_setting_parser_info;
#endif
......@@ -24,6 +24,7 @@
#include "ioloop.h"
#include "str-sanitize.h"
#include "ostream.h"
#include "settings.h"
#include "message-date.h"
#include "mail-storage.h"
......@@ -33,13 +34,13 @@
#include "sieve-address-source.h"
#include "sieve-message.h"
#include "sieve-smtp.h"
#include "sieve-settings.old.h"
#include "sieve-ext-enotify.h"
#include "rfc2822.h"
#include "uri-mailto.h"
#include "ntfy-mailto-settings.h"
/*
* Configuration
......@@ -53,7 +54,7 @@
*/
static int
ntfy_mailto_load(const struct sieve_enotify_method *nmth, void **context);
ntfy_mailto_load(const struct sieve_enotify_method *nmth, void **context_r);
static void
ntfy_mailto_unload(const struct sieve_enotify_method *nmth);
......@@ -151,24 +152,25 @@ struct ntfy_mailto_action_context {
*/
struct ntfy_mailto_context {
pool_t pool;
struct sieve_address_source envelope_from;
const struct ntfy_mailto_settings *set;
};
static int
ntfy_mailto_load(const struct sieve_enotify_method *nmth, void **context_r)
{
struct sieve_instance *svinst = nmth->svinst;
const struct ntfy_mailto_settings *set;
struct ntfy_mailto_context *mtctx;
pool_t pool;
const char *error;
pool = pool_alloconly_create("ntfy_mailto_context", 256);
mtctx = p_new(pool, struct ntfy_mailto_context, 1);
mtctx->pool = pool;
if (settings_get(svinst->event, &ntfy_mailto_setting_parser_info, 0,
&set, &error) < 0) {
e_error(svinst->event, "%s", error);
return -1;
}
(void)sieve_address_source_parse_from_setting(
svinst, mtctx->pool, "sieve_notify_mailto_envelope_from",
&mtctx->envelope_from);
mtctx = i_new(struct ntfy_mailto_context, 1);
mtctx->set = set;
*context_r = mtctx;
return 0;
......@@ -178,7 +180,10 @@ static void ntfy_mailto_unload(const struct sieve_enotify_method *nmth)
{
struct ntfy_mailto_context *mtctx = nmth->context;
pool_unref(&mtctx->pool);
if (mtctx == NULL)
return;
settings_free(mtctx->set);
i_free(mtctx);
}
/*
......@@ -516,7 +521,7 @@ ntfy_mailto_send(const struct sieve_enotify_exec_env *nenv,
const struct sieve_script_env *senv = nenv->scriptenv;
struct ntfy_mailto_action_context *mtactx = nact->method_context;
struct ntfy_mailto_context *mtctx = nenv->method->context;
struct sieve_address_source env_from = mtctx->envelope_from;
struct sieve_address_source env_from = mtctx->set->parsed.envelope_from;
const char *from = NULL;
const struct smtp_address *from_smtp = NULL;
const char *subject = mtactx->uri->subject;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.