]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Use new var_expand
authorAki Tuomi <aki.tuomi@open-xchange.com>
Thu, 29 Aug 2024 10:42:34 +0000 (13:42 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Fri, 17 Jan 2025 08:40:00 +0000 (10:40 +0200)
src/imap/imap-client.c
src/imap/imap-settings.c

index 186a86325322ce625ca28f64af007bc502f665cd..3870fa7ca9187371218dc2bad286fa4b2a542682 100644 (file)
@@ -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,
+                          &params, &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);
 }
 
index 04191d8dafefa539e488752e08e9f12bf30dc9ff..b61106b5e160ccd7c23aae03fbc478e27ae12c58 100644 (file)
@@ -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}",