]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Add mail_storage_2nd_settings_reset()
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Thu, 30 Nov 2023 13:39:31 +0000 (15:39 +0200)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:10 +0000 (12:34 +0200)
This isn't very useful yet in this commit, but following commits will
add more settings that are reset.

src/doveadm/doveadm-mail-import.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h

index dda8ba9fca0100623a0d2e937f3cfd95220a665f..502d5e90932b3e1e73a75d6566989fa145ed46c2 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib.h"
 #include "array.h"
 #include "str.h"
+#include "settings.h"
 #include "mail-storage.h"
 #include "mail-storage-service.h"
 #include "mail-namespace.h"
index f0951bdce3dbefad85423f96ceef8ceda4d10758..2bb02b590606256096a85668dca2e63757356510 100644 (file)
@@ -863,3 +863,64 @@ bool mail_user_set_get_postmaster_smtp(const struct mail_user_settings *set,
        get_postmaster_address_error(set, error_r);
        return FALSE;
 }
+
+#define OFFSET(name) offsetof(struct mail_storage_settings, name)
+static const size_t mail_storage_2nd_reset_offsets[] = {
+       OFFSET(mail_location),
+};
+
+static void
+mail_storage_2nd_setting_reset_def(struct settings_instance *instance,
+                                  const struct setting_define *def,
+                                  const char *key_prefix)
+{
+       const char *value;
+
+       switch (def->type) {
+       case SET_BOOL: {
+               const bool *v = CONST_PTR_OFFSET(&mail_storage_default_settings,
+                                                def->offset);
+               value = *v ? "yes" : "no";
+               break;
+       }
+       case SET_STR: {
+               const char *const *v =
+                       CONST_PTR_OFFSET(&mail_storage_default_settings,
+                                        def->offset);
+               value = *v;
+               break;
+       }
+       default:
+               i_panic("Unsupported type %d", def->type);
+       }
+       settings_override(instance,
+                         t_strdup_printf("%s%s", key_prefix, def->key),
+                         value, SETTINGS_OVERRIDE_TYPE_2ND_DEFAULT);
+}
+
+static void
+mail_storage_2nd_setting_reset_offset(struct settings_instance *instance,
+                                     size_t offset, const char *key_prefix)
+{
+       for (unsigned int i = 0; mail_storage_setting_defines[i].key != NULL; i++) {
+               if (mail_storage_setting_defines[i].offset == offset) {
+                       mail_storage_2nd_setting_reset_def(instance,
+                               &mail_storage_setting_defines[i], key_prefix);
+                       return;
+               }
+       }
+       i_panic("mail_storage_setting_defines didn't have offset %zu", offset);
+}
+
+void mail_storage_2nd_settings_reset(struct settings_instance *instance,
+                                    const char *key_prefix)
+{
+       unsigned int i;
+
+       T_BEGIN {
+               for (i = 0; i < N_ELEMENTS(mail_storage_2nd_reset_offsets); i++) {
+                       mail_storage_2nd_setting_reset_offset(instance,
+                               mail_storage_2nd_reset_offsets[i], key_prefix);
+               }
+       } T_END;
+}
index 684105ccc9259812f55af8418b467e47e7da1954..f8d65b31323c97083e89b0354730627af4e2081e 100644 (file)
@@ -10,6 +10,7 @@ struct mail_storage;
 struct message_address;
 struct smtp_address;
 struct setting_parser_context;
+struct settings_instance;
 
 struct mail_storage_settings {
        pool_t pool;
@@ -166,4 +167,13 @@ bool mail_user_set_get_postmaster_smtp(const struct mail_user_settings *set,
                                       const struct smtp_address **address_r,
                                       const char **error_r);
 
+/* Reset "2nd storage" settings to defaults using
+   SETTINGS_OVERRIDE_TYPE_2ND_DEFAULT, so the actually intended settings
+   can be overridden on top of them. For example with "doveadm import" command
+   the -o parameters should apply only to the import destination, not to the
+   import source. This allows clearing away such unwanted storage-specific
+   settings. */
+void mail_storage_2nd_settings_reset(struct settings_instance *instance,
+                                    const char *key_prefix);
+
 #endif