]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
imap: Log Post-login ID parameters as the imap_id_received event
authorKarl Fleischmann <karl.fleischmann@open-xchange.com>
Wed, 1 Mar 2023 13:38:15 +0000 (14:38 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 31 Mar 2023 05:54:46 +0000 (05:54 +0000)
Drop the manual filtering of the 'imap_id_log' fields in favor of using
a named event and respective log string.

src/imap/cmd-id.c
src/imap/imap-settings.c
src/imap/imap-settings.h

index 98355d4f119be6233f1fbae5e992c931730d549a..808d17cca5307fc2d4bcc63614724c391f34d1d7 100644 (file)
@@ -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(
index 953065d0474f72d0482d37102934ff75755dd5d7..ea9c5dc6a57faad97acc1d44a276ba279adffec6 100644 (file)
@@ -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,
index f4ff7bce683285276753c523f3d8fc14dfd65dee..9587b7753af24c92543e99ade50474ccf3e227ba 100644 (file)
@@ -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;