From: Karl Fleischmann Date: Thu, 6 Mar 2025 13:48:18 +0000 (+0100) Subject: lib-imap, imap: Move imap_logout_format statistics into separate struct X-Git-Tag: 2.4.1~41 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=56fcb2295586b80109b6142e356f379fd8a46b1f;p=thirdparty%2Fdovecot%2Fcore.git lib-imap, imap: Move imap_logout_format statistics into separate struct --- diff --git a/src/imap/cmd-append.c b/src/imap/cmd-append.c index a72f16fa0d..3c29c1f9c9 100644 --- a/src/imap/cmd-append.c +++ b/src/imap/cmd-append.c @@ -738,7 +738,7 @@ static bool cmd_append_finish_parsing(struct client_command_context *cmd) } str_append(msg, msg_suffix); str_append_c(msg, '.'); - ctx->client->append_count += save_count; + ctx->client->logout_stats.append_count += save_count; pool_unref(&changes.pool); if (ctx->box == cmd->client->mailbox) { diff --git a/src/imap/cmd-close.c b/src/imap/cmd-close.c index 1f4dfebefb..2a2070fbff 100644 --- a/src/imap/cmd-close.c +++ b/src/imap/cmd-close.c @@ -18,7 +18,7 @@ bool cmd_close(struct client_command_context *cmd) i_assert(client->mailbox_change_lock == NULL); storage = mailbox_get_storage(mailbox); - if (imap_expunge(mailbox, NULL, &client->expunged_count) < 0) { + if (imap_expunge(mailbox, NULL, &client->logout_stats.expunged_count) < 0) { errstr = mailbox_get_last_error(mailbox, &error); if (error != MAIL_ERROR_PERM) client_send_untagged_storage_error(client, storage); diff --git a/src/imap/cmd-copy.c b/src/imap/cmd-copy.c index aecd43bb8f..6d12ced70f 100644 --- a/src/imap/cmd-copy.c +++ b/src/imap/cmd-copy.c @@ -68,7 +68,7 @@ static void copy_update_trashed(struct client *client, struct mailbox *box, if (set != NULL && array_not_empty(&set->special_use) && str_array_icase_find(settings_boollist_get(&set->special_use), "\\Trash")) - client->trashed_count += count; + client->logout_stats.trashed_count += count; } static bool client_is_disconnected(struct client *client) diff --git a/src/imap/cmd-expunge.c b/src/imap/cmd-expunge.c index 7388937a08..e5747b267e 100644 --- a/src/imap/cmd-expunge.c +++ b/src/imap/cmd-expunge.c @@ -15,7 +15,7 @@ cmd_expunge_finish(struct client_command_context *cmd, int ret; ret = imap_expunge(client->mailbox, search_args == NULL ? NULL : - search_args->args, &client->expunged_count); + search_args->args, &client->logout_stats.expunged_count); if (search_args != NULL) mail_search_args_unref(&search_args); if (ret < 0) { diff --git a/src/imap/cmd-store.c b/src/imap/cmd-store.c index 2c6aa9d27b..ab24612082 100644 --- a/src/imap/cmd-store.c +++ b/src/imap/cmd-store.c @@ -227,7 +227,7 @@ bool cmd_store(struct client_command_context *cmd) client_send_box_error(cmd, client->mailbox); return TRUE; } - client->deleted_count += deleted_count; + client->logout_stats.deleted_count += deleted_count; if (array_count(&modified_set) == 0) tagged_reply = "OK Store completed."; diff --git a/src/imap/imap-client.c b/src/imap/imap-client.c index 56e6aea85c..1ec8400bc4 100644 --- a/src/imap/imap-client.c +++ b/src/imap/imap-client.c @@ -312,15 +312,15 @@ const char *client_stats(struct client *client) { .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) }, + { .key = "fetch_hdr_count", .value = dec2str(client->logout_stats.fetch_hdr_count) }, + { .key = "fetch_hdr_bytes", .value = dec2str(client->logout_stats.fetch_hdr_bytes) }, + { .key = "fetch_body_count", .value = dec2str(client->logout_stats.fetch_body_count) }, + { .key = "fetch_body_bytes", .value = dec2str(client->logout_stats.fetch_body_bytes) }, + { .key = "deleted", .value = dec2str(client->logout_stats.deleted_count) }, + { .key = "expunged", .value = dec2str(client->logout_stats.expunged_count) }, + { .key = "trashed", .value = dec2str(client->logout_stats.trashed_count) }, + { .key = "autoexpunged", .value = dec2str(client->logout_stats.autoexpunged_count) }, + { .key = "appended", .value = dec2str(client->logout_stats.append_count) }, VAR_EXPAND_TABLE_END }; const struct var_expand_params *user_params = @@ -547,7 +547,7 @@ static void client_default_destroy(struct client *client, const char *reason) hibernations it could also be doing unnecessarily much work. */ imap_refresh_proctitle(); if (!client->hibernated) { - client->autoexpunged_count = mail_user_autoexpunge(client->user); + client->logout_stats.autoexpunged_count = mail_user_autoexpunge(client->user); client_log_disconnect(client, reason); } mail_user_deinit(&client->user); diff --git a/src/imap/imap-client.h b/src/imap/imap-client.h index fa632ff66a..fd1153d97f 100644 --- a/src/imap/imap-client.h +++ b/src/imap/imap-client.h @@ -2,6 +2,7 @@ #define IMAP_CLIENT_H #include "imap-commands.h" +#include "imap-stats.h" #include "message-size.h" #define CLIENT_COMMAND_QUEUE_MAX_SIZE 4 @@ -206,11 +207,7 @@ struct client { uint64_t highest_fetch_modseq; ARRAY_TYPE(seq_range) fetch_failed_uids; - /* For imap_logout_format statistics: */ - unsigned int fetch_hdr_count, fetch_body_count; - uint64_t fetch_hdr_bytes, fetch_body_bytes; - unsigned int deleted_count, expunged_count, trashed_count; - unsigned int autoexpunged_count, append_count; + struct imap_logout_stats logout_stats; /* SEARCHRES extension: Last saved SEARCH result */ ARRAY_TYPE(seq_range) search_saved_uidset; diff --git a/src/imap/imap-fetch-body.c b/src/imap/imap-fetch-body.c index 0c8f87f298..c5d433308a 100644 --- a/src/imap/imap-fetch-body.c +++ b/src/imap/imap-fetch-body.c @@ -173,11 +173,11 @@ static void fetch_state_update_stats(struct imap_fetch_context *ctx, const struct imap_msgpart *msgpart) { if (!imap_msgpart_contains_body(msgpart)) { - ctx->client->fetch_hdr_count++; - ctx->state.cur_stats_sizep = &ctx->client->fetch_hdr_bytes; + ctx->client->logout_stats.fetch_hdr_count++; + ctx->state.cur_stats_sizep = &ctx->client->logout_stats.fetch_hdr_bytes; } else { - ctx->client->fetch_body_count++; - ctx->state.cur_stats_sizep = &ctx->client->fetch_body_bytes; + ctx->client->logout_stats.fetch_body_count++; + ctx->state.cur_stats_sizep = &ctx->client->logout_stats.fetch_body_bytes; } } diff --git a/src/lib-imap/Makefile.am b/src/lib-imap/Makefile.am index 3a4c7269f7..c3d5540a9e 100644 --- a/src/lib-imap/Makefile.am +++ b/src/lib-imap/Makefile.am @@ -34,6 +34,7 @@ headers = \ imap-parser.h \ imap-resp-code.h \ imap-quote.h \ + imap-stats.h \ imap-url.h \ imap-seqset.h \ imap-utf7.h \ diff --git a/src/lib-imap/imap-stats.h b/src/lib-imap/imap-stats.h new file mode 100644 index 0000000000..9cda562efc --- /dev/null +++ b/src/lib-imap/imap-stats.h @@ -0,0 +1,12 @@ +#ifndef IMAP_STATS_H +#define IMAP_STATS_H + +/* Statistics that are used in the imap_logout_format message. */ +struct imap_logout_stats { + unsigned int fetch_hdr_count, fetch_body_count; + uint64_t fetch_hdr_bytes, fetch_body_bytes; + unsigned int deleted_count, expunged_count, trashed_count; + unsigned int autoexpunged_count, append_count; +}; + +#endif /* IMAP_STATS_H */