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

plugins: imapsieve: Migrate plugin settings to new config structure

parent 9c324fa1
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ lib95_imap_sieve_plugin_la_SOURCES = \ ...@@ -20,6 +20,7 @@ lib95_imap_sieve_plugin_la_SOURCES = \
ext-imapsieve.c \ ext-imapsieve.c \
ext-imapsieve-environment.c \ ext-imapsieve-environment.c \
imap-sieve.c \ imap-sieve.c \
imap-sieve-settings.c \
imap-sieve-storage.c \ imap-sieve-storage.c \
imap-sieve-plugin.c imap-sieve-plugin.c
lib95_imap_sieve_plugin_la_LIBADD = \ lib95_imap_sieve_plugin_la_LIBADD = \
...@@ -35,6 +36,7 @@ lib90_sieve_imapsieve_plugin_la_CPPFLAGS = \ ...@@ -35,6 +36,7 @@ lib90_sieve_imapsieve_plugin_la_CPPFLAGS = \
noinst_HEADERS = \ noinst_HEADERS = \
ext-imapsieve-common.h \ ext-imapsieve-common.h \
imap-sieve.h \ imap-sieve.h \
imap-sieve-settings.h \
imap-sieve-storage.h \ imap-sieve-storage.h \
imap-sieve-plugin.h \ imap-sieve-plugin.h \
sieve-imapsieve-plugin.h sieve-imapsieve-plugin.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 "imap-sieve-settings.h"
#undef DEF
#define DEF(type, name) \
SETTING_DEFINE_STRUCT_##type("imapsieve_"#name, name, \
struct imap_sieve_settings)
static const struct setting_define imap_sieve_setting_defines[] = {
DEF(STR, url),
DEF(BOOL, expunge_discarded),
SETTING_DEFINE_LIST_END,
};
static const struct imap_sieve_settings imap_sieve_default_settings = {
.url = "",
.expunge_discarded = FALSE,
};
static bool
imap_sieve_settings_check(void *_set ATTR_UNUSED, pool_t pool ATTR_UNUSED,
const char **error_r ATTR_UNUSED);
const struct setting_parser_info imap_sieve_setting_parser_info = {
.name = "imapsieve",
.defines = imap_sieve_setting_defines,
.defaults = &imap_sieve_default_settings,
.struct_size = sizeof(struct imap_sieve_settings),
.check_func = imap_sieve_settings_check,
.pool_offset1 = 1 + offsetof(struct imap_sieve_settings, pool),
};
/* <settings checks> */
static bool
imap_sieve_settings_check(void *_set, pool_t pool ATTR_UNUSED,
const char **error_r)
{
struct imap_sieve_settings *set = _set;
if (*set->url != '\0' && !str_begins_icase_with(set->url, "sieve:")) {
*error_r = "Invalid URL for imapsieve_url setting: "
"Not a Sieve URL";
return FALSE;
}
return TRUE;
}
/* </settings checks> */
#ifndef IMAP_SIEVE_SETTINGS_H
#define IMAP_SIEVE_SETTINGS_H
struct imap_sieve_settings {
pool_t pool;
const char *url;
bool expunge_discarded;
};
extern const struct setting_parser_info imap_sieve_setting_parser_info;
#endif
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "istream.h" #include "istream.h"
#include "ostream.h" #include "ostream.h"
#include "module-context.h" #include "module-context.h"
#include "settings.h"
#include "mail-user.h" #include "mail-user.h"
#include "mail-storage-private.h" #include "mail-storage-private.h"
#include "mailbox-attribute.h" #include "mailbox-attribute.h"
...@@ -15,6 +16,7 @@ ...@@ -15,6 +16,7 @@
#include "imap-util.h" #include "imap-util.h"
#include "imap-sieve.h" #include "imap-sieve.h"
#include "imap-sieve-settings.h"
#include "imap-sieve-storage.h" #include "imap-sieve-storage.h"
#define MAILBOX_ATTRIBUTE_IMAPSIEVE_SCRIPT "imapsieve/script" #define MAILBOX_ATTRIBUTE_IMAPSIEVE_SCRIPT "imapsieve/script"
...@@ -1175,23 +1177,24 @@ void imap_sieve_storage_client_created(struct client *client) ...@@ -1175,23 +1177,24 @@ void imap_sieve_storage_client_created(struct client *client)
{ {
struct mail_user *user = client->user; struct mail_user *user = client->user;
struct imap_sieve_user *isuser = IMAP_SIEVE_USER_CONTEXT_REQUIRE(user); struct imap_sieve_user *isuser = IMAP_SIEVE_USER_CONTEXT_REQUIRE(user);
const char *url, *set; const struct imap_sieve_settings *set;
const char *error;
url = mail_user_plugin_getenv(user, "imapsieve_url"); if (settings_get(client->event, &imap_sieve_setting_parser_info, 0,
// FIXME: parse the URL and report error if it is bad &set, &error) < 0) {
if (url != NULL && str_begins_icase_with(url, "sieve:")) { e_error(client->event, "%s", error);
return;
}
if (*set->url != '\0') {
client_add_capability(client, client_add_capability(client,
t_strconcat("IMAPSIEVE=", url, NULL)); t_strconcat("IMAPSIEVE=", set->url, NULL));
} else {
url = NULL;
} }
isuser->client = client; isuser->client = client;
isuser->user_script = (url != NULL && *url != '\0'); isuser->user_script = (*set->url != '\0');
isuser->expunge_discarded = set->expunge_discarded;
set = mail_user_plugin_getenv(user, "imapsieve_expunge_discarded"); settings_free(set);
isuser->expunge_discarded = (set != NULL &&
strcasecmp(set, "yes") == 0);
} }
/* /*
......
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.