smtp-server-cmd-mail.c revision 8c2d916c7cd0c7c85fba4eb41bcc031d1424cb2d
a8c5a86d183db25a57bf193c06b41e092ec2e151Timo Sirainen/* Copyright (c) 2013-2018 Dovecot authors, see the included COPYING file */
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen/* MAIL command */
b19a1420da0618a10edf67c2cfd13c8c8633057aTimo Sirainencmd_mail_check_state(struct smtp_server_cmd_ctx *cmd)
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct smtp_server_connection *conn = cmd->conn;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct smtp_server_command *command = cmd->cmd;
539977f9257bd8985be5a8093658da266ae9cd19Timo Sirainen smtp_server_reply(cmd, 503, "5.5.0", "MAIL already given");
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainenstatic void cmd_mail_replied(struct smtp_server_cmd_ctx *cmd)
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen struct smtp_server_connection *conn = cmd->conn;
d5cebe7f98e63d4e2822863ef2faa4971e8b3a5dTimo Sirainen struct smtp_server_command *command = cmd->cmd;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen i_assert(smtp_server_command_is_replied(command));
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen if (!smtp_server_command_replied_success(command)) {
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen /* failure; substitute our own error if predictable */
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen /* success */
7631f16156aca373004953fe6b01a7f343fb47e0Timo Sirainen conn->state.trans = smtp_server_transaction_create(conn,
73b50eecfc31750a312e2f940023f522eb07178cTimo Sirainenstatic void cmd_mail_recheck(struct smtp_server_cmd_ctx *cmd)
a12399903f415a7e14c2816cffa2f7a09dcbb097Timo Sirainen struct smtp_server_connection *conn = cmd->conn;
a12399903f415a7e14c2816cffa2f7a09dcbb097Timo Sirainen /* all preceeding commands have finished and now the transaction state
a12399903f415a7e14c2816cffa2f7a09dcbb097Timo Sirainen is clear. This provides the opportunity to re-check the transaction
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen /* Advance state */
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen smtp_server_connection_set_state(conn, SMTP_SERVER_STATE_MAIL_FROM);
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainenvoid smtp_server_cmd_mail(struct smtp_server_cmd_ctx *cmd,
e15b305e90c9834734ccf35ed78f0ad29d570ee9Timo Sirainen struct smtp_server_connection *conn = cmd->conn;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen const struct smtp_server_settings *set = &conn->set;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen enum smtp_capability caps = set->capabilities;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen const struct smtp_server_callbacks *callbacks = conn->callbacks;
ecd69c4e8371853667e01b0c16d436ef7f7393e2Timo Sirainen struct smtp_server_command *command = cmd->cmd;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* mail = "MAIL FROM:" Reverse-path [SP Mail-parameters] CRLF
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen Reverse-path = Path / "<>"
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* check transaction state as far as possible */
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen /* Reverse-path */
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen if (params == NULL || strncasecmp(params, "FROM:", 5) != 0) {
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen smtp_server_reply(cmd, 501, "5.5.4", "Invalid parameters");
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen if (smtp_address_parse_path_full(pool_datastack_create(), params + 5,
f46885a5b78b15a8d2419f6e5d13b643bd85e41fTimo Sirainen smtp_server_reply(cmd, 501, "5.5.4", "Invalid FROM: %s", error);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen "Invalid FROM: Invalid character in path");
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainen if (conn->pending_helo == NULL && conn->helo.domain == NULL) {
a757f31393b9d6fc7760a9dec8363404ab3ae576Timo Sirainen /* no EHLO executed post-login, use pre-login value instead */
c0225f7f6b43d34dc58c17d3304f0fd60ab89894Timo Sirainen mail_data = p_new(cmd->pool, struct smtp_server_cmd_mail, 1);
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* [SP Mail-parameters] */
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen if (smtp_params_mail_parse(cmd->pool, params, caps,
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen smtp_server_reply(cmd, 501, "5.5.4", "%s", error);
83bb013a99f0936995f9c7a1077822662d8fefdbTimo Sirainen smtp_server_reply(cmd, 555, "5.5.4", "%s", error);
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen mail_data->path = smtp_address_clone(cmd->pool, path);
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen smtp_server_connection_set_state(conn, SMTP_SERVER_STATE_MAIL_FROM);
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen if (callbacks != NULL && callbacks->conn_cmd_mail != NULL) {
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen /* specific implementation of MAIL command */
90adcaa0a00eba29b7fbd50ca66be11c8d086d6aTimo Sirainen if ((ret=callbacks->conn_cmd_mail(conn->context,
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen /* command is waiting for external event or it failed */
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen if (!smtp_server_command_is_replied(command)) {
8dccbdbe38f0e9342caf752d9d980a64125fa4d1Timo Sirainen /* set generic MAIL success reply if none is provided */