From: Aki Tuomi Date: Thu, 1 Apr 2021 09:41:40 +0000 (+0300) Subject: imap-zlib: Support per-algorithm compression level X-Git-Tag: 2.3.15~108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4b8d368a910b0349968bc02d0a6aa69013449247;p=thirdparty%2Fdovecot%2Fcore.git imap-zlib: Support per-algorithm compression level --- diff --git a/src/config/old-set-parser.c b/src/config/old-set-parser.c index 444e0ddac4..d5302f8689 100644 --- a/src/config/old-set-parser.c +++ b/src/config/old-set-parser.c @@ -733,6 +733,21 @@ static void socket_apply(struct config_parser_context *ctx) i_zero(&ctx->old->socket_set); } +static bool +old_settings_handle_path(struct config_parser_context *ctx, + const char *key, const char *value) +{ + if (strcmp(str_c(ctx->str), "plugin/0/") == 0) { + if (strcmp(key, "imap_zlib_compress_level") == 0) { + obsolete(ctx, "%s has been replaced by imap_compress_deflate_level", key); + config_apply_line(ctx, key, + t_strdup_printf("plugin/0/imap_compress_deflate_level=%s", value), NULL); + return TRUE; + } + } + return FALSE; +} + bool old_settings_handle(struct config_parser_context *ctx, enum config_line_type type, const char *key, const char *value) @@ -759,7 +774,7 @@ bool old_settings_handle(struct config_parser_context *ctx, return old_settings_handle_root(ctx, key, value); } - break; + return old_settings_handle_path(ctx, key, value); case CONFIG_LINE_TYPE_SECTION_BEGIN: if (ctx->old->auth_section > 0) return old_auth_section(ctx, key, value); diff --git a/src/plugins/imap-zlib/imap-zlib-plugin.c b/src/plugins/imap-zlib/imap-zlib-plugin.c index 1035fbefb9..df5508bf13 100644 --- a/src/plugins/imap-zlib/imap-zlib-plugin.c +++ b/src/plugins/imap-zlib/imap-zlib-plugin.c @@ -102,11 +102,16 @@ static bool cmd_compress(struct client_command_context *cmd) client_skip_line(client); client_send_tagline(cmd, "OK Begin compression."); - value = mail_user_plugin_getenv(client->user, - "imap_zlib_compress_level"); - if (value == NULL || str_to_int(value, &level) < 0 || - level < handler->get_min_level() || level > handler->get_max_level()) { - i_error("imap_zlib_compress_level: Level must be between %d..%d", + const char *setting = t_strdup_printf("imap_compress_%s_level", + handler->name); + value = mail_user_plugin_getenv(client->user, setting); + if (value == NULL) { + level = handler->get_default_level(); + } else if (str_to_int(value, &level) < 0 || + level < handler->get_min_level() || + level > handler->get_max_level()) { + i_error("%s: Level must be between %d..%d", + setting, handler->get_min_level(), handler->get_max_level()); level = handler->get_default_level();