From: Aki Tuomi Date: Thu, 29 Aug 2024 10:42:34 +0000 (+0300) Subject: imap: Use new var_expand X-Git-Tag: 2.4.1~595 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=863f05d7d6c148548115be63d22b4453a7ce0243;p=thirdparty%2Fdovecot%2Fcore.git imap: Use new var_expand --- diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 186a863253..3870fa7ca9 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -13,8 +13,8 @@ #include "ostream.h" #include "ostream-multiplex.h" #include "time-util.h" -#include "var-expand.h" #include "settings.h" +#include "var-expand-new.h" #include "master-service.h" #include "imap-resp-code.h" #include "imap-util.h" @@ -308,39 +308,46 @@ void client_command_cancel(struct client_command_context **_cmd) const char *client_stats(struct client *client) { const struct var_expand_table logout_tab[] = { - { 'i', dec2str(i_stream_get_absolute_offset(client->input)), "input" }, - { 'o', dec2str(client->output->offset), "output" }, - { '\0', client->user->session_id, "session" }, - { '\0', dec2str(client->fetch_hdr_count), "fetch_hdr_count" }, - { '\0', dec2str(client->fetch_hdr_bytes), "fetch_hdr_bytes" }, - { '\0', dec2str(client->fetch_body_count), "fetch_body_count" }, - { '\0', dec2str(client->fetch_body_bytes), "fetch_body_bytes" }, - { '\0', dec2str(client->deleted_count), "deleted" }, - { '\0', dec2str(client->expunged_count), "expunged" }, - { '\0', dec2str(client->trashed_count), "trashed" }, - { '\0', dec2str(client->autoexpunged_count), "autoexpunged" }, - { '\0', dec2str(client->append_count), "appended" }, - { '\0', NULL, NULL } + { .key = "input", .value = dec2str(i_stream_get_absolute_offset(client->input)) }, + { .key = "output", .value = dec2str(client->output->offset) }, + { .key = "session", .value = client->user->session_id }, + { .key = "fetch_hdr_count", .value = dec2str(client->fetch_hdr_count) }, + { .key = "fetch_hdr_bytes", .value = dec2str(client->fetch_hdr_bytes) }, + { .key = "fetch_body_count", .value = dec2str(client->fetch_body_count) }, + { .key = "fetch_body_bytes", .value = dec2str(client->fetch_body_bytes) }, + { .key = "deleted", .value = dec2str(client->deleted_count) }, + { .key = "expunged", .value = dec2str(client->expunged_count) }, + { .key = "trashed", .value = dec2str(client->trashed_count) }, + { .key = "autoexpunged", .value = dec2str(client->autoexpunged_count) }, + { .key = "appended", .value = dec2str(client->append_count) }, + VAR_EXPAND_TABLE_END + }; + const struct var_expand_params *user_params = + mail_user_var_expand_params(client->user); + const struct var_expand_params params = { + .tables_arr = (const struct var_expand_table*[]){ + logout_tab, + user_params->table, + NULL + }, + .providers = user_params->providers, + .context = user_params->context, + .event = client->event, }; - const struct var_expand_table *user_tab = - mail_user_var_expand_table(client->user); - const struct var_expand_table *tab = - t_var_expand_merge_tables(logout_tab, user_tab); string_t *str; const char *error; + event_add_int(client->event, "net_in_bytes", i_stream_get_absolute_offset(client->input)); + event_add_int(client->event, "net_out_bytes", client->output->offset); + str = t_str_new(128); - if (var_expand_with_funcs(str, client->set->imap_logout_format, - tab, mail_user_var_expand_func_table, - client->user, &error) <= 0) { + if (var_expand_new(str, client->set->imap_logout_format, + ¶ms, &error) < 0) { e_error(client->event, "Failed to expand imap_logout_format=%s: %s", client->set->imap_logout_format, error); } - event_add_int(client->event, "net_in_bytes", i_stream_get_absolute_offset(client->input)); - event_add_int(client->event, "net_out_bytes", client->output->offset); - return str_c(str); } diff --git a/src/imap/imap-settings.c b/src/imap/imap-settings.c index 04191d8daf..b61106b5e1 100644 --- a/src/imap/imap-settings.c +++ b/src/imap/imap-settings.c @@ -91,7 +91,7 @@ static const struct imap_settings imap_default_settings = { .imap_idle_notify_interval = 2*60, .imap_capability = ARRAY_INIT, .imap_client_workarounds = ARRAY_INIT, - .imap_logout_format = "in=%i out=%o deleted=%{deleted} " + .imap_logout_format = "in=%{input} out=%{output} deleted=%{deleted} " "expunged=%{expunged} trashed=%{trashed} " "hdr_count=%{fetch_hdr_count} hdr_bytes=%{fetch_hdr_bytes} " "body_count=%{fetch_body_count} body_bytes=%{fetch_body_bytes}",