]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Use mail_ext_attachment prefix for settings related to external attachments
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 2 Jan 2024 02:09:24 +0000 (21:09 -0500)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
This is mainly to differentiate them from mail_attachment_detection_options
setting, which is unrelated.

mail_attachment_dir setting was also renamed to mail_ext_attachment_path,
which causes settings parsing to automatically expand ~/ to home directory,
so it doesn't need to be done later on explicitly.

src/lib-storage/index/dbox-common/dbox-attachment.c
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-single/sdbox-copy.c
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/index-attachment.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h

index cfc3f62689768bd683221850fe4ecc80daf89258..09702a26162cba278f0a4509240e14b874137ff7 100644 (file)
@@ -33,7 +33,8 @@ dbox_attachment_file_get_stream_from(struct dbox_file *file,
        if (file->storage->attachment_dir == NULL) {
                mail_storage_set_critical(&file->storage->storage,
                        "%s contains references to external attachments, "
-                       "but mail_attachment_dir is unset", file->cur_path);
+                       "but mail_ext_attachment_path is unset",
+                       file->cur_path);
                return -1;
        }
 
index 539d62ab755c8e37d8f667f64f39350f49e21ad6..87b065a8c342aa68f89a0027dfbba53a557db625 100644 (file)
@@ -94,28 +94,28 @@ int dbox_storage_create(struct mail_storage *_storage,
        const struct mail_storage_settings *set = _storage->set;
        const char *error;
 
-       if (*set->mail_attachment_dir != '\0') {
+       if (*set->mail_ext_attachment_path != '\0') {
                const char *dir;
                int ret;
 
                dir = mail_user_home_expand(_storage->user,
-                                           set->mail_attachment_dir);
+                                           set->mail_ext_attachment_path);
                storage->attachment_dir = p_strdup(_storage->pool, dir);
 
                struct event *event = event_create(_storage->event);
                event_set_ptr(event, SETTINGS_EVENT_FILTER_NAME,
-                             "mail_attachment");
+                             "mail_ext_attachment");
                ret = mailbox_list_init_fs(ns->list, event,
                                           storage->attachment_dir,
                                           &storage->attachment_fs, &error);
                event_unref(&event);
                if (ret == 0) {
-                       *error_r = "mail_attachment_dir is set, "
-                               "but mail_attachment { fs_driver } is missing";
+                       *error_r = "mail_ext_attachment_path is set, "
+                               "but mail_ext_attachment { fs_driver } is missing";
                        return -1;
                }
                if (ret < 0) {
-                       *error_r = t_strdup_printf("mail_attachment: %s",
+                       *error_r = t_strdup_printf("mail_ext_attachment: %s",
                                                   error);
                        return -1;
                }
index 54e3bb5e350c7e4035a3af64c4943aba8cf02195..79639c9db577333dc1cd365613923e6bac08dc2c 100644 (file)
@@ -31,8 +31,8 @@ sdbox_file_copy_attachments(struct sdbox_file *src_file,
                   dest_storage->attachment_dir) != 0 ||
            strcmp(fs_get_driver(src_storage->attachment_fs),
                   fs_get_driver(dest_storage->attachment_fs)) != 0 ||
-           strcmp(src_storage->storage.set->mail_attachment_hash,
-                  dest_storage->storage.set->mail_attachment_hash) != 0) {
+           strcmp(src_storage->storage.set->mail_ext_attachment_hash,
+                  dest_storage->storage.set->mail_ext_attachment_hash) != 0) {
                /* different attachment dirs/settings between storages.
                   have to copy the slow way. */
                return 0;
index 42de9a048fdf9372d9e94022fc92a662900bec5f..1ad945e0a25f430f567e997d2d90bf21601e091a 100644 (file)
@@ -49,7 +49,7 @@ static int sdbox_storage_create(struct mail_storage *_storage,
        if (storage->attachment_fs != NULL) {
                props = fs_get_properties(storage->attachment_fs);
                if ((props & FS_PROPERTY_RENAME) == 0) {
-                       *error_r = "mail_attachment: "
+                       *error_r = "mail_ext_attachment: "
                                "FS driver doesn't support renaming";
                        return -1;
                }
index ef729ec67d5baa9c6c54cbbc43acaad7fb466462..0fa0db6e0345eb12c7252bdb0ffe07f03c0b782e 100644 (file)
@@ -32,12 +32,6 @@ struct mail_save_attachment {
        ARRAY_TYPE(mail_attachment_extref) extrefs;
 };
 
-static const char *index_attachment_dir_get(struct mail_storage *storage)
-{
-       return mail_user_home_expand(storage->user,
-                                    storage->set->mail_attachment_dir);
-}
-
 static bool index_attachment_want(const struct istream_attachment_header *hdr,
                                  void *context)
 {
@@ -91,7 +85,7 @@ index_attachment_open_ostream(struct istream_attachment_info *info,
        struct mail_storage *storage = ctx->transaction->box->storage;
        struct mail_attachment_extref *extref;
        enum fs_open_flags flags = 0;
-       const char *attachment_dir, *path, *digest = info->hash;
+       const char *path, *digest = info->hash;
        guid_128_t guid_128;
 
        i_assert(attach->cur_file == NULL);
@@ -106,8 +100,8 @@ index_attachment_open_ostream(struct istream_attachment_info *info,
        }
 
        guid_128_generate(guid_128);
-       attachment_dir = index_attachment_dir_get(storage);
-       path = t_strdup_printf("%s/%c%c/%c%c/%s-%s", attachment_dir,
+       path = t_strdup_printf("%s/%c%c/%c%c/%s-%s",
+                              storage->set->mail_ext_attachment_path,
                               digest[0], digest[1],
                               digest[2], digest[3], digest,
                               guid_128_to_string(guid_128));
@@ -117,8 +111,8 @@ index_attachment_open_ostream(struct istream_attachment_info *info,
        extref = array_append_space(&attach->extrefs);
        extref->start_offset = info->start_offset;
        extref->size = info->encoded_size;
-       extref->path = p_strdup(attach->pool,
-                               path + strlen(attachment_dir) + 1);
+       extref->path = p_strdup(attach->pool, path +
+                       strlen(storage->set->mail_ext_attachment_path) + 1);
        extref->base64_blocks_per_line = info->base64_blocks_per_line;
        extref->base64_have_crlf = info->base64_have_crlf;
 
@@ -163,16 +157,16 @@ void index_attachment_save_begin(struct mail_save_context *ctx,
 
        i_assert(ctx->data.attach == NULL);
 
-       if (*storage->set->mail_attachment_dir == '\0')
+       if (*storage->set->mail_ext_attachment_path == '\0')
                return;
 
        i_zero(&set);
-       set.min_size = storage->set->mail_attachment_min_size;
-       if (hash_format_init(storage->set->mail_attachment_hash,
+       set.min_size = storage->set->mail_ext_attachment_min_size;
+       if (hash_format_init(storage->set->mail_ext_attachment_hash,
                             &set.hash_format, &error) < 0) {
                /* we already checked this when verifying settings */
                i_panic("mail_attachment_hash=%s unexpectedly failed: %s",
-                       storage->set->mail_attachment_hash, error);
+                       storage->set->mail_ext_attachment_hash, error);
        }
        set.want_attachment = index_attachment_want;
        set.open_temp_fd = index_attachment_open_temp_fd;
@@ -275,7 +269,7 @@ index_attachment_delete_real(struct mail_storage *storage,
        const char *path;
        int ret;
 
-       path = t_strdup_printf("%s/%s", index_attachment_dir_get(storage), name);
+       path = t_strdup_printf("%s/%s", storage->set->mail_ext_attachment_path, name);
        file = fs_file_init(fs, path, FS_OPEN_MODE_READONLY);
        if ((ret = fs_delete(file)) < 0)
                mail_storage_set_critical(storage, "%s", fs_file_last_error(file));
index b407b49dc09b826f52cae6b68f8a4edb3f936ddd..d2c493a7c608af79c4979bfee90d2e45dd8c5a08 100644 (file)
@@ -33,11 +33,11 @@ static const struct setting_define mail_storage_setting_defines[] = {
        { .type = SET_FILTER_NAME, .key = "layout_maildir++" },
        { .type = SET_FILTER_NAME, .key = "layout_imapdir" },
        { .type = SET_FILTER_NAME, .key = "layout_fs" },
-       { .type = SET_FILTER_NAME, .key = "mail_attachment",
+       { .type = SET_FILTER_NAME, .key = "mail_ext_attachment",
          .required_setting = "fs_driver", },
-       DEF(STR, mail_attachment_dir),
-       DEF(STR_NOVARS_HIDDEN, mail_attachment_hash),
-       DEF(SIZE, mail_attachment_min_size),
+       DEF(STR, mail_ext_attachment_path),
+       DEF(STR_NOVARS_HIDDEN, mail_ext_attachment_hash),
+       DEF(SIZE, mail_ext_attachment_min_size),
        DEF(STR, mail_attachment_detection_options),
        { .type = SET_FILTER_NAME, .key = "mail_attribute",
          .required_setting = "dict_driver", },
@@ -118,9 +118,9 @@ static const struct setting_define mail_storage_setting_defines[] = {
 };
 
 const struct mail_storage_settings mail_storage_default_settings = {
-       .mail_attachment_dir = "",
-       .mail_attachment_hash = "%{sha1}",
-       .mail_attachment_min_size = 1024*128,
+       .mail_ext_attachment_path = "",
+       .mail_ext_attachment_hash = "%{sha1}",
+       .mail_ext_attachment_min_size = 1024*128,
        .mail_attachment_detection_options = "",
        .mail_prefetch_count = 0,
        .mail_cache_fields = "flags",
@@ -700,17 +700,18 @@ mail_storage_settings_ext_check(struct event *event ATTR_UNUSED,
                return FALSE;
        }
 
-       if (strchr(set->mail_attachment_hash, '/') != NULL) {
+       if (strchr(set->mail_ext_attachment_hash, '/') != NULL) {
                *error_r = "mail_attachment_hash setting "
                        "must not contain '/' characters";
                return FALSE;
        }
-       if (hash_format_init(set->mail_attachment_hash, &format, &error) < 0) {
+       if (hash_format_init(set->mail_ext_attachment_hash,
+                            &format, &error) < 0) {
                *error_r = t_strconcat("Invalid mail_attachment_hash setting: ",
                                       error, NULL);
                return FALSE;
        }
-       if (strchr(set->mail_attachment_hash, '-') != NULL) {
+       if (strchr(set->mail_ext_attachment_hash, '-') != NULL) {
                *error_r = "mail_attachment_hash setting "
                        "must not contain '-' characters";
                return FALSE;
index 0cdf15fb18bd8fdc940f9398d9a36b06f1e99a59..3207108ffa53415ffde7c2b5af1f4f39684c6d5b 100644 (file)
@@ -19,9 +19,9 @@ struct settings_instance;
 struct mail_storage_settings {
        pool_t pool;
        const char *mail_driver;
-       const char *mail_attachment_dir;
-       const char *mail_attachment_hash;
-       uoff_t mail_attachment_min_size;
+       const char *mail_ext_attachment_path;
+       const char *mail_ext_attachment_hash;
+       uoff_t mail_ext_attachment_min_size;
        unsigned int mail_prefetch_count;
        const char *mail_cache_fields;
        const char *mail_always_cache_fields;