From: Karl Fleischmann Date: Wed, 1 Mar 2023 13:38:15 +0000 (+0100) Subject: imap: Log Post-login ID parameters as the imap_id_received event X-Git-Tag: 2.4.0~2834 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b06bebedaeb2b41e6a022cdf5f17540c919d329;p=thirdparty%2Fdovecot%2Fcore.git imap: Log Post-login ID parameters as the imap_id_received event Drop the manual filtering of the 'imap_id_log' fields in favor of using a named event and respective log string. --- diff --git a/src/imap/cmd-id.c b/src/imap/cmd-id.c index 98355d4f11..808d17cca5 100644 --- a/src/imap/cmd-id.c +++ b/src/imap/cmd-id.c @@ -2,21 +2,62 @@ #include "imap-common.h" #include "imap-id.h" +#include "str.h" + +static void +cmd_id_log_params(const struct imap_arg *args, struct event *event, + string_t *reply) +{ + if (!imap_arg_get_list(args, &args)) + return; + + const char *key, *value; + struct imap_id_log_entry log_entry = { + .event = event, + .reply = reply, + }; + while (!IMAP_ARG_IS_EOL(&args[0]) && + !IMAP_ARG_IS_EOL(&args[1])) { + if (!imap_arg_get_string(args, &key)) { + /* broken input */ + args += 2; + continue; + } + args++; + if (strlen(key) > IMAP_ID_KEY_MAX_LEN) { + /* broken: ID spec requires fields to be max. 30 + octets */ + args++; + continue; + } + + if (!imap_arg_get_nstring(args, &value)) + value = ""; + imap_id_add_log_entry(&log_entry, key, value); + args++; + } +} bool cmd_id(struct client_command_context *cmd) { const struct imap_settings *set = cmd->client->set; const struct imap_arg *args; - const char *value; if (!client_read_args(cmd, 0, 0, &args)) return FALSE; if (!cmd->client->id_logged) { cmd->client->id_logged = TRUE; - value = imap_id_args_get_log_reply(args, set->imap_id_log); - if (value != NULL) - e_info(cmd->client->event, "ID sent: %s", value); + + struct event *event = event_create(cmd->client->event); + event_set_name(event, "imap_id_received"); + + string_t *log_reply = str_new(default_pool, 64); + cmd_id_log_params(args, event, log_reply); + if (str_len(log_reply) > 0) + e_debug(event, "ID sent: %s", str_c(log_reply))); + event_unref(&event); + str_free(&log_reply); } client_send_line(cmd->client, t_strdup_printf( diff --git a/src/imap/imap-settings.c b/src/imap/imap-settings.c index 953065d047..ea9c5dc6a5 100644 --- a/src/imap/imap-settings.c +++ b/src/imap/imap-settings.c @@ -94,7 +94,6 @@ static const struct setting_define imap_setting_defines[] = { DEF(STR, imap_client_workarounds), DEF(STR, imap_logout_format), DEF(STR, imap_id_send), - DEF(STR, imap_id_log), DEF(ENUM, imap_fetch_failure), DEF(BOOL, imap_metadata), DEF(BOOL, imap_literal_minus), @@ -122,7 +121,6 @@ static const struct imap_settings imap_default_settings = { "hdr_count=%{fetch_hdr_count} hdr_bytes=%{fetch_hdr_bytes} " "body_count=%{fetch_body_count} body_bytes=%{fetch_body_bytes}", .imap_id_send = "name *", - .imap_id_log = "", .imap_fetch_failure = "disconnect-immediately:disconnect-after:no-after", .imap_metadata = FALSE, .imap_literal_minus = FALSE, diff --git a/src/imap/imap-settings.h b/src/imap/imap-settings.h index f4ff7bce68..9587b7753a 100644 --- a/src/imap/imap-settings.h +++ b/src/imap/imap-settings.h @@ -30,7 +30,6 @@ struct imap_settings { const char *imap_client_workarounds; const char *imap_logout_format; const char *imap_id_send; - const char *imap_id_log; const char *imap_fetch_failure; bool imap_metadata; bool imap_literal_minus;