From: Timo Sirainen Date: Tue, 2 Jan 2024 02:09:24 +0000 (-0500) Subject: lib-storage: Use mail_ext_attachment prefix for settings related to external attachments X-Git-Tag: 2.4.1~1192 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=081ef7a94945dd134cf49f31b05f1a0062bfb8c0;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Use mail_ext_attachment prefix for settings related to external attachments 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. --- diff --git a/src/lib-storage/index/dbox-common/dbox-attachment.c b/src/lib-storage/index/dbox-common/dbox-attachment.c index cfc3f62689..09702a2616 100644 --- a/src/lib-storage/index/dbox-common/dbox-attachment.c +++ b/src/lib-storage/index/dbox-common/dbox-attachment.c @@ -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; } diff --git a/src/lib-storage/index/dbox-common/dbox-storage.c b/src/lib-storage/index/dbox-common/dbox-storage.c index 539d62ab75..87b065a8c3 100644 --- a/src/lib-storage/index/dbox-common/dbox-storage.c +++ b/src/lib-storage/index/dbox-common/dbox-storage.c @@ -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; } diff --git a/src/lib-storage/index/dbox-single/sdbox-copy.c b/src/lib-storage/index/dbox-single/sdbox-copy.c index 54e3bb5e35..79639c9db5 100644 --- a/src/lib-storage/index/dbox-single/sdbox-copy.c +++ b/src/lib-storage/index/dbox-single/sdbox-copy.c @@ -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; diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 42de9a048f..1ad945e0a2 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -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; } diff --git a/src/lib-storage/index/index-attachment.c b/src/lib-storage/index/index-attachment.c index ef729ec67d..0fa0db6e03 100644 --- a/src/lib-storage/index/index-attachment.c +++ b/src/lib-storage/index/index-attachment.c @@ -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)); diff --git a/src/lib-storage/mail-storage-settings.c b/src/lib-storage/mail-storage-settings.c index b407b49dc0..d2c493a7c6 100644 --- a/src/lib-storage/mail-storage-settings.c +++ b/src/lib-storage/mail-storage-settings.c @@ -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; diff --git a/src/lib-storage/mail-storage-settings.h b/src/lib-storage/mail-storage-settings.h index 0cdf15fb18..3207108ffa 100644 --- a/src/lib-storage/mail-storage-settings.h +++ b/src/lib-storage/mail-storage-settings.h @@ -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;