]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lmtp: lmtp-proxy - Split off lmtp_proxy_handle_connection_error().
authorStephan Bosch <stephan.bosch@open-xchange.com>
Mon, 27 Dec 2021 10:35:05 +0000 (11:35 +0100)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Mon, 10 Jan 2022 06:31:48 +0000 (06:31 +0000)
src/lmtp/lmtp-proxy.c

index f4f9dced8fc02bce0eb72683a8488ad8faa75bb0..7c5cb960e711b66c3eb7e857d6198651632d9021 100644 (file)
@@ -293,45 +293,51 @@ lmtp_proxy_get_connection(struct lmtp_proxy *proxy,
        return conn;
 }
 
+static void
+lmtp_proxy_handle_connection_error(struct lmtp_proxy_recipient *lprcpt,
+                                  const struct smtp_reply *reply)
+{
+       struct smtp_server_recipient *rcpt = lprcpt->rcpt->rcpt;
+       const char *detail = "";
+
+       switch (reply->status) {
+       case SMTP_CLIENT_COMMAND_ERROR_ABORTED:
+               break;
+       case SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED:
+               detail = " (DNS lookup)";
+               break;
+       case SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED:
+       case SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED:
+               detail = " (connect)";
+               break;
+       case SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST:
+       case SMTP_CLIENT_COMMAND_ERROR_CONNECTION_CLOSED:
+               detail = " (connection lost)";
+               break;
+       case SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY:
+               detail = " (bad reply)";
+               break;
+       case SMTP_CLIENT_COMMAND_ERROR_TIMED_OUT:
+               detail = " (timed out)";
+               break;
+       default:
+               break;
+       }
+
+       smtp_server_command_fail(rcpt->cmd->cmd, 451, "4.4.0",
+                                "Proxy failed%s", detail);
+}
+
 static bool
 lmtp_proxy_handle_reply(struct lmtp_proxy_recipient *lprcpt,
                        const struct smtp_reply *reply,
                        struct smtp_reply *reply_r)
 {
-       struct smtp_server_recipient *rcpt = lprcpt->rcpt->rcpt;
-
        *reply_r = *reply;
 
        if (!smtp_reply_is_remote(reply) ||
            reply->status == SMTP_CLIENT_COMMAND_ERROR_CONNECTION_CLOSED) {
-               const char *detail = "";
-
-               switch (reply->status) {
-               case SMTP_CLIENT_COMMAND_ERROR_ABORTED:
-                       break;
-               case SMTP_CLIENT_COMMAND_ERROR_HOST_LOOKUP_FAILED:
-                       detail = " (DNS lookup)";
-                       break;
-               case SMTP_CLIENT_COMMAND_ERROR_CONNECT_FAILED:
-               case SMTP_CLIENT_COMMAND_ERROR_AUTH_FAILED:
-                       detail = " (connect)";
-                       break;
-               case SMTP_CLIENT_COMMAND_ERROR_CONNECTION_LOST:
-               case SMTP_CLIENT_COMMAND_ERROR_CONNECTION_CLOSED:
-                       detail = " (connection lost)";
-                       break;
-               case SMTP_CLIENT_COMMAND_ERROR_BAD_REPLY:
-                       detail = " (bad reply)";
-                       break;
-               case SMTP_CLIENT_COMMAND_ERROR_TIMED_OUT:
-                       detail = " (timed out)";
-                       break;
-               default:
-                       break;
-               }
-
-               smtp_server_command_fail(rcpt->cmd->cmd, 451, "4.4.0",
-                                        "Proxy failed", detail);
+               lmtp_proxy_handle_connection_error(lprcpt, reply);
                return FALSE;
        }