]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: Move session_id field to generic recipient struct.
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 4 Oct 2021 00:57:25 +0000 (02:57 +0200)
committertimo.sirainen <timo.sirainen@open-xchange.com>
Wed, 6 Oct 2021 21:58:03 +0000 (21:58 +0000)
src/lmtp/lmtp-commands.c
src/lmtp/lmtp-local.c
src/lmtp/lmtp-recipient.c
src/lmtp/lmtp-recipient.h

index 34be6586c5152b1e4f2889e15548d3c7079ebaf6..dd8b791e0cbe88487c47e2513a472a04bb3a7837 100644 (file)
@@ -90,9 +90,13 @@ int cmd_rcpt(void *conn_ctx, struct smtp_server_cmd_ctx *cmd,
             struct smtp_server_recipient *rcpt)
 {
        struct client *client = (struct client *)conn_ctx;
+       struct smtp_server_transaction *trans;
        struct lmtp_recipient *lrcpt;
 
-       lrcpt = lmtp_recipient_create(client, rcpt);
+       trans = smtp_server_connection_get_transaction(rcpt->conn);
+       i_assert(trans != NULL); /* MAIL command is synchronous */
+
+       lrcpt = lmtp_recipient_create(client, trans, rcpt);
 
        if (cmd_rcpt_handle_forward_fields(cmd, lrcpt) < 0)
                return -1;
index f64d368da4bae5d3bb9bc09e940a10f7efc68d2a..c20b619439042840ca8a5dd7afa43b2dc654c00b 100644 (file)
@@ -27,7 +27,6 @@
 
 struct lmtp_local_recipient {
        struct lmtp_recipient *rcpt;
-       char *session_id;
 
        char *detail;
 
@@ -284,28 +283,18 @@ lmtp_local_rcpt_anvil_cb(const char *reply, void *context)
        }
 }
 
-int lmtp_local_rcpt(struct client *client, struct smtp_server_cmd_ctx *cmd,
+int lmtp_local_rcpt(struct client *client,
+                   struct smtp_server_cmd_ctx *cmd ATTR_UNUSED,
                    struct lmtp_recipient *lrcpt, const char *username,
                    const char *detail)
 {
-       struct smtp_server_connection *conn = cmd->conn;
        struct smtp_server_recipient *rcpt = lrcpt->rcpt;
-       struct smtp_server_transaction *trans;
        struct lmtp_local_recipient *llrcpt;
        struct mail_storage_service_input input;
        struct mail_storage_service_user *service_user;
-       const char *session_id, *error = NULL;
+       const char *error = NULL;
        int ret = 0;
 
-       trans = smtp_server_connection_get_transaction(conn);
-       i_assert(trans != NULL); /* MAIL command is synchronous */
-
-       /* Use a unique session_id for each mail delivery. This is especially
-          important for stats process to not see duplicate sessions. */
-       client->state.session_id_seq++;
-       session_id = t_strdup_printf("%s:%u",
-                                    trans->id, client->state.session_id_seq);
-
        i_zero(&input);
        input.module = input.service = "lmtp";
        input.username = username;
@@ -313,14 +302,12 @@ int lmtp_local_rcpt(struct client *client, struct smtp_server_cmd_ctx *cmd,
        input.remote_ip = client->remote_ip;
        input.local_port = client->local_port;
        input.remote_port = client->remote_port;
-       input.session_id = session_id;
+       input.session_id = lrcpt->session_id;
        input.conn_ssl_secured =
                smtp_server_connection_is_ssl_secured(client->conn);
        input.conn_secured = input.conn_ssl_secured ||
                smtp_server_connection_is_trusted(client->conn);
        input.forward_fields = lrcpt->forward_fields;
-
-       event_add_str(rcpt->event, "session", session_id);
        input.event_parent = rcpt->event;
 
        ret = mail_storage_service_lookup(storage_service, &input,
@@ -346,7 +333,6 @@ int lmtp_local_rcpt(struct client *client, struct smtp_server_cmd_ctx *cmd,
        llrcpt->rcpt = lrcpt;
        llrcpt->detail = p_strdup(rcpt->pool, detail);
        llrcpt->service_user = service_user;
-       llrcpt->session_id = p_strdup(rcpt->pool, session_id);
 
        lrcpt->type = LMTP_RECIPIENT_TYPE_LOCAL;
        lrcpt->backend_context = llrcpt;
@@ -463,7 +449,7 @@ lmtp_local_deliver(struct lmtp_local *local,
        }
 
        i_zero(&lldctx);
-       lldctx.session_id = llrcpt->session_id;
+       lldctx.session_id = lrcpt->session_id;
        lldctx.src_mail = src_mail;
        lldctx.session = session;
 
index cb4999a60a43350dd0a2ee3ee18c3b16e0c9c9eb..d92fe735405136148e3a887abbd64acca34ac801 100644 (file)
@@ -1,6 +1,6 @@
 /* Copyright (c) 2018 Dovecot authors, see the included COPYING file */
 
-#include "lib.h"
+#include "lmtp-common.h"
 #include "array.h"
 #include "smtp-server.h"
 #include "lmtp-recipient.h"
@@ -10,6 +10,7 @@ lmtp_recipient_module_register = { 0 };
 
 struct lmtp_recipient *
 lmtp_recipient_create(struct client *client,
+                     struct smtp_server_transaction *trans,
                      struct smtp_server_recipient *rcpt)
 {
        struct lmtp_recipient *lrcpt;
@@ -22,6 +23,14 @@ lmtp_recipient_create(struct client *client,
 
        p_array_init(&lrcpt->module_contexts, rcpt->pool, 5);
 
+       /* Use a unique session_id for each mail delivery. This is especially
+          important for stats process to not see duplicate sessions. */
+       client->state.session_id_seq++;
+       lrcpt->session_id = p_strdup_printf(rcpt->pool, "%s:%u", trans->id,
+                                           client->state.session_id_seq);
+
+       event_add_str(rcpt->event, "session", lrcpt->session_id);
+
        return lrcpt;
 }
 
index 8d11124057b744f3b8118ba47b4de0c07e28374b..2b4367860f3cf4ee2026e5e9eb1d33368d875494 100644 (file)
@@ -20,6 +20,7 @@ struct lmtp_recipient {
        enum lmtp_recipient_type type;
        void *backend_context;
 
+       char *session_id;
        const char *forward_fields;
 
        /* Module-specific contexts. */
@@ -37,6 +38,7 @@ extern struct lmtp_recipient_module_register lmtp_recipient_module_register;
 
 struct lmtp_recipient *
 lmtp_recipient_create(struct client *client,
+                     struct smtp_server_transaction *trans,
                      struct smtp_server_recipient *rcpt);
 
 struct lmtp_recipient *