From 2bb2f53ff4aeacefe11c74171c74e4f38e929bfe Mon Sep 17 00:00:00 2001 From: Sergey Kandaurov Date: Thu, 24 Oct 2024 00:52:21 +0400 Subject: [PATCH] Mail: handling of CAPABILITY in the LOGIN IMAP command. SmarterMail IMAP server may send an optional untagged CAPABILITY response. Previously resulted in a broken connection, now it is discarded. --- src/mail/ngx_mail_proxy_module.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/mail/ngx_mail_proxy_module.c b/src/mail/ngx_mail_proxy_module.c index efed9ab3e..2599f148b 100644 --- a/src/mail/ngx_mail_proxy_module.c +++ b/src/mail/ngx_mail_proxy_module.c @@ -1019,12 +1019,39 @@ ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state) break; case ngx_imap_passwd: + + if (ngx_strncmp(p, s->tag.data, s->tag.len) != 0) { + /* as per RFC 3501, 6.2.3 LOGIN Command */ + + if (b->last - b->pos < 12) { + return NGX_AGAIN; + } + + if (ngx_strncmp(p, "* CAPABILITY", 12) == 0) { + p += 12; + + while (p < b->last - 1) { + if (p[0] == CR && p[1] == LF) { + p += (sizeof(CRLF) - 1); + break; + } + + p++; + } + + if (b->last - p < 4) { + return NGX_AGAIN; + } + } + } + if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) { p += s->tag.len; if (p[0] == 'O' && p[1] == 'K') { return NGX_OK; } } + break; }