# HG changeset patch # User Igor Sysoev # Date 1234279185 0 # Node ID 1ab9cef4ff6c06b5389e6f8438f239db4af69cfe # Parent 9081bbdccda12b720d0f617c2cef20dab13c9562 send HELO/EHLO after XCLIENT patch by Maxim Dounin diff --git a/src/mail/ngx_mail.h b/src/mail/ngx_mail.h --- a/src/mail/ngx_mail.h +++ b/src/mail/ngx_mail.h @@ -140,6 +140,7 @@ typedef enum { ngx_smtp_helo_from, ngx_smtp_xclient, ngx_smtp_xclient_from, + ngx_smtp_xclient_helo, ngx_smtp_from, ngx_smtp_to } ngx_smtp_state_e; diff --git a/src/mail/ngx_mail_proxy_module.c b/src/mail/ngx_mail_proxy_module.c --- a/src/mail/ngx_mail_proxy_module.c +++ b/src/mail/ngx_mail_proxy_module.c @@ -539,9 +539,8 @@ ngx_mail_proxy_smtp_handler(ngx_event_t s->connection->log->action = "sending XCLIENT to upstream"; - line.len = sizeof("XCLIENT PROTO=SMTP HELO= ADDR= LOGIN= NAME=" + line.len = sizeof("XCLIENT ADDR= LOGIN= NAME=" CRLF) - 1 - + s->esmtp + s->smtp_helo.len + s->connection->addr_text.len + s->login.len + s->host.len; line.data = ngx_pnalloc(c->pool, line.len); @@ -551,15 +550,44 @@ ngx_mail_proxy_smtp_handler(ngx_event_t } line.len = ngx_sprintf(line.data, - "XCLIENT PROTO=%sSMTP%s%V ADDR=%V%s%V NAME=%V" CRLF, - (s->esmtp ? "E" : ""), - (s->smtp_helo.len ? " HELO=" : ""), &s->smtp_helo, + "XCLIENT ADDR=%V%s%V NAME=%V" CRLF, &s->connection->addr_text, (s->login.len ? " LOGIN=" : ""), &s->login, &s->host) - line.data; + if (s->smtp_helo.len) { + s->mail_state = ngx_smtp_xclient_helo; + + } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { + s->mail_state = ngx_smtp_xclient_from; + + } else { + s->mail_state = ngx_smtp_xclient; + } + + break; + + case ngx_smtp_xclient_helo: + ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, + "mail proxy send client ehlo"); + + s->connection->log->action = "sending client HELO/EHLO to upstream"; + + line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len; + + line.data = ngx_pnalloc(c->pool, line.len); + if (line.data == NULL) { + ngx_mail_proxy_internal_server_error(s); + return; + } + + line.len = ngx_sprintf(line.data, + ((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF), + &s->smtp_helo) + - line.data; + s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ? - ngx_smtp_xclient_from : ngx_smtp_xclient; + ngx_smtp_helo_from : ngx_smtp_helo; break; @@ -772,6 +800,7 @@ ngx_mail_proxy_read_response(ngx_mail_se case ngx_smtp_xclient: case ngx_smtp_xclient_from: + case ngx_smtp_xclient_helo: if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') { return NGX_OK; }