]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
submission: Move relay part of DATA command to submission-backend-relay.c.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 15 Jul 2018 17:03:09 +0000 (19:03 +0200)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 12 Feb 2019 13:40:41 +0000 (15:40 +0200)
src/submission/cmd-data.c
src/submission/submission-backend-relay.c
src/submission/submission-backend-relay.h
src/submission/submission-commands.h

index 0ec7c780728d33603e29e43a63bf4e57c1470de7..fae5df7b12e2c26d840bf89a0d0ee985c1c2d164 100644 (file)
 
 #include "submission-commands.h"
 
-/*
- * DATA/BDAT commands
- */
-
-struct cmd_data_context {
-       struct client *client;
-       struct smtp_server_cmd_ctx *cmd;
-       struct smtp_server_transaction *trans;
-
-       struct smtp_client_command *cmd_proxied;
-};
-
-static void cmd_data_proxy_cb(const struct smtp_reply *proxy_reply,
-                             struct cmd_data_context *data_ctx)
-{
-       struct smtp_server_cmd_ctx *cmd = data_ctx->cmd;
-       struct smtp_server_transaction *trans = data_ctx->trans;
-       struct client *client = data_ctx->client;
-       struct smtp_reply reply;
-
-       /* finished proxying message to relay server */
-
-       /* check for fatal problems */
-       if (!client_command_handle_proxy_reply(client, proxy_reply, &reply))
-               return;
-
-       if (proxy_reply->status / 100 == 2) {
-               i_info("Successfully relayed message: "
-                      "from=<%s>, size=%"PRIuUOFF_T", "
-                      "id=%s, nrcpt=%u, reply=`%s'",
-                      smtp_address_encode(trans->mail_from),
-                      client->state.data_size, trans->id,
-                      array_count(&trans->rcpt_to),
-                      str_sanitize(smtp_reply_log(proxy_reply), 128));
-
-       } else {
-               i_info("Failed to relay message: "
-                      "from=<%s>, size=%"PRIuUOFF_T", nrcpt=%u, reply=`%s'",
-                      smtp_address_encode(trans->mail_from),
-                      client->state.data_size, array_count(&trans->rcpt_to),
-                      str_sanitize(smtp_reply_log(proxy_reply), 128));
-       }
-
-       smtp_server_reply_forward(cmd, &reply);
-}
-
-int cmd_data_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
-                  struct smtp_server_transaction *trans,
-                  struct istream *data_input)
-{
-       struct cmd_data_context *data_ctx;
-
-       /* start relaying to relay server */
-       data_ctx = p_new(trans->pool, struct cmd_data_context, 1);
-       data_ctx->client = client;
-       data_ctx->cmd = cmd;
-       data_ctx->trans = trans;
-       trans->context = (void*)data_ctx;
-
-       data_ctx->cmd_proxied = smtp_client_command_data_submit(
-               client->proxy_conn, 0, data_input, cmd_data_proxy_cb, data_ctx);
-       return 0;
-}
-
 /*
  * BURL command
  */
index ae785b95a5a0a9d6ed34c2160dbb9bb130af7a40..9f0c3e6d88d0205abe003de7bffd44d63e845bdc 100644 (file)
@@ -2,6 +2,7 @@
 
 #include "submission-common.h"
 #include "str.h"
+#include "str-sanitize.h"
 #include "mail-user.h"
 #include "smtp-client.h"
 #include "smtp-client-connection.h"
@@ -423,3 +424,66 @@ int cmd_rset_relay(struct client *client, struct smtp_server_cmd_ctx *cmd)
        return 0;
 }
 
+/*
+ * DATA/BDAT commands
+ */
+
+struct cmd_data_context {
+       struct client *client;
+       struct smtp_server_cmd_ctx *cmd;
+       struct smtp_server_transaction *trans;
+
+       struct smtp_client_command *cmd_proxied;
+};
+
+static void cmd_data_proxy_cb(const struct smtp_reply *proxy_reply,
+                             struct cmd_data_context *data_ctx)
+{
+       struct smtp_server_cmd_ctx *cmd = data_ctx->cmd;
+       struct smtp_server_transaction *trans = data_ctx->trans;
+       struct client *client = data_ctx->client;
+       struct smtp_reply reply;
+
+       /* finished proxying message to relay server */
+
+       /* check for fatal problems */
+       if (!client_command_handle_proxy_reply(client, proxy_reply, &reply))
+               return;
+
+       if (proxy_reply->status / 100 == 2) {
+               i_info("Successfully relayed message: "
+                      "from=<%s>, size=%"PRIuUOFF_T", "
+                      "id=%s, nrcpt=%u, reply=`%s'",
+                      smtp_address_encode(trans->mail_from),
+                      client->state.data_size, trans->id,
+                      array_count(&trans->rcpt_to),
+                      str_sanitize(smtp_reply_log(proxy_reply), 128));
+
+       } else {
+               i_info("Failed to relay message: "
+                      "from=<%s>, size=%"PRIuUOFF_T", nrcpt=%u, reply=`%s'",
+                      smtp_address_encode(trans->mail_from),
+                      client->state.data_size, array_count(&trans->rcpt_to),
+                      str_sanitize(smtp_reply_log(proxy_reply), 128));
+       }
+
+       smtp_server_reply_forward(cmd, &reply);
+}
+
+int cmd_data_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
+                  struct smtp_server_transaction *trans,
+                  struct istream *data_input)
+{
+       struct cmd_data_context *data_ctx;
+
+       /* start relaying to relay server */
+       data_ctx = p_new(trans->pool, struct cmd_data_context, 1);
+       data_ctx->client = client;
+       data_ctx->cmd = cmd;
+       data_ctx->trans = trans;
+       trans->context = (void*)data_ctx;
+
+       data_ctx->cmd_proxied = smtp_client_command_data_submit(
+               client->proxy_conn, 0, data_input, cmd_data_proxy_cb, data_ctx);
+       return 0;
+}
index 804f7f9e8524fffe474f1f0c10a9f772fb6f2c32..8d0864473b036fc2df8bdc73d16dc9fab81e1834 100644 (file)
@@ -8,5 +8,8 @@ int cmd_mail_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
 int cmd_rcpt_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
                   struct smtp_server_cmd_rcpt *data);
 int cmd_rset_relay(struct client *client, struct smtp_server_cmd_ctx *cmd);
+int cmd_data_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
+                  struct smtp_server_transaction *trans,
+                  struct istream *data_input);
 
 #endif
index 4e00fbbb306eb2737f3d183e26b08a0f3b0f9d65..285e5cd293b91cc824b5865aa337e049a1dffeee 100644 (file)
@@ -4,9 +4,6 @@
 bool client_command_handle_proxy_reply(struct client *client,
        const struct smtp_reply *reply, struct smtp_reply *reply_r);
 
-int cmd_data_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
-                  struct smtp_server_transaction *trans,
-                  struct istream *data_input);
 int cmd_vrfy_relay(struct client *client, struct smtp_server_cmd_ctx *cmd,
                   const char *param);
 int cmd_noop_relay(struct client *client, struct smtp_server_cmd_ctx *cmd);