From: Timo Sirainen Date: Sat, 31 Jan 2026 14:12:05 +0000 (+0200) Subject: imap-login: imap-proxy - Parse server responses case insensitively X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c1ac59d83ef1eabac4cd8ece8b1a113df78edaf;p=thirdparty%2Fdovecot%2Fcore.git imap-login: imap-proxy - Parse server responses case insensitively IMAP protocol is not case sensitive. Luckily this seems to have worked with current IMAP servers. --- diff --git a/src/imap-login/imap-proxy.c b/src/imap-login/imap-proxy.c index d3688c7fb3..677d7b5845 100644 --- a/src/imap-login/imap-proxy.c +++ b/src/imap-login/imap-proxy.c @@ -194,7 +194,7 @@ static int proxy_input_banner(struct imap_client *client, string_t *str; int ret; - if (!str_begins(line, "* OK ", &line)) { + if (!str_begins_icase(line, "* OK ", &line)) { const char *reason = t_strdup_printf("Invalid banner: %s", str_sanitize(line, 160)); login_proxy_failed(client->common.login_proxy, @@ -204,7 +204,7 @@ static int proxy_input_banner(struct imap_client *client, } str = t_str_new(128); - if (str_begins(line, "[CAPABILITY ", &suffix)) { + if (str_begins_icase(line, "[CAPABILITY ", &suffix)) { capabilities = t_strsplit(t_strcut(suffix, ']'), " "); if (str_array_icase_find(capabilities, "SASL-IR")) client->proxy_sasl_ir = TRUE; @@ -383,7 +383,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) imap_client->proxy_sent_state &= ENUM_NEGATE(IMAP_PROXY_SENT_STATE_STARTTLS); imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_STARTTLS; - if (!str_begins_with(suffix, "OK ")) { + if (!str_begins_icase_with(suffix, "OK ")) { /* STARTTLS failed */ const char *reason = t_strdup_printf( "STARTTLS failed: %s", @@ -403,7 +403,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) return -1; o_stream_nsend(output, str_data(str), str_len(str)); return 1; - } else if (str_begins(line, "L OK ", &suffix)) { + } else if (str_begins_icase(line, "L OK ", &suffix)) { /* Login successful. Send this line to client. */ imap_client->proxy_sent_state &= ENUM_NEGATE(IMAP_PROXY_SENT_STATE_LOGIN); imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_LOGIN; @@ -422,7 +422,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) enum login_proxy_failure_type failure_type = LOGIN_PROXY_FAILURE_TYPE_AUTH_REPLIED; #define STR_NO_IMAP_RESP_CODE_AUTHFAILED "NO ["IMAP_RESP_CODE_AUTHFAILED"]" - if (str_begins_with(line, STR_NO_IMAP_RESP_CODE_AUTHFAILED)) { + if (str_begins_icase_with(line, STR_NO_IMAP_RESP_CODE_AUTHFAILED)) { /* the remote sent a generic "authentication failed" error. replace it with our one, so that in case the remote is sending a different error message @@ -431,7 +431,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) client_send_reply_code(client, IMAP_CMD_REPLY_NO, IMAP_RESP_CODE_AUTHFAILED, AUTH_FAILED_MSG); - } else if (str_begins_with(line, "NO [")) { + } else if (str_begins_icase_with(line, "NO [")) { /* remote sent some other resp-code. forward it. */ if (auth_resp_code_is_tempfail(line + 4)) failure_type = LOGIN_PROXY_FAILURE_TYPE_AUTH_TEMPFAIL; @@ -471,7 +471,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) /* Reply to CAPABILITY command we sent */ imap_client->proxy_sent_state &= ENUM_NEGATE(IMAP_PROXY_SENT_STATE_CAPABILITY); imap_client->proxy_rcvd_state = IMAP_PROXY_RCVD_STATE_CAPABILITY; - if (str_begins_with(line, "C OK ") && + if (str_begins_icase_with(line, "C OK ") && HAS_NO_BITS(imap_client->proxy_sent_state, IMAP_PROXY_SENT_STATE_AUTHENTICATE | IMAP_PROXY_SENT_STATE_LOGIN)) { @@ -505,7 +505,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) } else if (str_begins_icase_with(line, "* ID ")) { /* Reply to ID command we sent, ignore it */ return 0; - } else if (str_begins(line, "* MULTIPLEX ", &suffix)) { + } else if (str_begins_icase(line, "* MULTIPLEX ", &suffix)) { if (strcmp(suffix, "0") != 0) { const char *reason = t_strdup_printf( "Unsupported MULTIPLEX version: %s", suffix); @@ -524,7 +524,7 @@ int imap_proxy_parse_line(struct client *client, const char *line) login_proxy_multiplex_input_start(client->login_proxy); /* force caller to refresh istream */ return 1; - } else if (str_begins_with(line, "* BYE ")) { + } else if (str_begins_icase_with(line, "* BYE ")) { /* Login unexpectedly failed (due to some internal error). Don't forward the BYE to the client, since we're not going to disconnect it. It could be a possibility to convert these