From: Stephan Bosch Date: Sun, 15 Jul 2018 17:03:09 +0000 (+0200) Subject: submission: Move relay part of DATA command to submission-backend-relay.c. X-Git-Tag: 2.3.9~1335 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=fff1a8b87e61d05f11b882712b11337dd95793f9;p=thirdparty%2Fdovecot%2Fcore.git submission: Move relay part of DATA command to submission-backend-relay.c. --- diff --git a/src/submission/cmd-data.c b/src/submission/cmd-data.c index 0ec7c78072..fae5df7b12 100644 --- a/src/submission/cmd-data.c +++ b/src/submission/cmd-data.c @@ -15,70 +15,6 @@ #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 */ diff --git a/src/submission/submission-backend-relay.c b/src/submission/submission-backend-relay.c index ae785b95a5..9f0c3e6d88 100644 --- a/src/submission/submission-backend-relay.c +++ b/src/submission/submission-backend-relay.c @@ -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; +} diff --git a/src/submission/submission-backend-relay.h b/src/submission/submission-backend-relay.h index 804f7f9e85..8d0864473b 100644 --- a/src/submission/submission-backend-relay.h +++ b/src/submission/submission-backend-relay.h @@ -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 diff --git a/src/submission/submission-commands.h b/src/submission/submission-commands.h index 4e00fbbb30..285e5cd293 100644 --- a/src/submission/submission-commands.h +++ b/src/submission/submission-commands.h @@ -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);