Mercurial > hg > nginx-mail
diff src/mail/ngx_mail_proxy_module.c @ 467:d67e93e97b4a
Merge with nginx 0.7.30.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sun, 11 Jan 2009 17:17:57 +0300 |
parents | 9b19e26b2660 dac47e9ef0d5 |
children | 2c989ee54dbd |
line wrap: on
line diff
--- a/src/mail/ngx_mail_proxy_module.c +++ b/src/mail/ngx_mail_proxy_module.c @@ -104,7 +104,7 @@ ngx_module_t ngx_mail_proxy_module = { }; -static u_char smtp_ok[] = "235 2.0.0 OK" CRLF; +static u_char smtp_ok[] = "250 2.0.0 OK" CRLF; void @@ -201,7 +201,7 @@ ngx_mail_proxy_block_read(ngx_event_t *r ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read"); - if (ngx_handle_read_event(rev, 0) == NGX_ERROR) { + if (ngx_handle_read_event(rev, 0) != NGX_OK) { c = rev->data; s = c->data; @@ -465,6 +465,7 @@ ngx_mail_proxy_smtp_handler(ngx_event_t u_char *p; ngx_int_t rc; ngx_str_t line; + ngx_buf_t *b; ngx_connection_t *c; ngx_mail_session_t *s; ngx_mail_proxy_conf_t *pcf; @@ -520,9 +521,15 @@ ngx_mail_proxy_smtp_handler(ngx_event_t p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len); *p++ = CR; *p = LF; - s->mail_state = pcf->xclient ? ngx_smtp_helo_xclient : - s->auth_method == NGX_MAIL_AUTH_NONE ? - ngx_smtp_helo_from : ngx_smtp_helo; + if (pcf->xclient) { + s->mail_state = ngx_smtp_helo_xclient; + + } else if (s->auth_method == NGX_MAIL_AUTH_NONE) { + s->mail_state = ngx_smtp_helo_from; + + } else { + s->mail_state = ngx_smtp_helo; + } break; @@ -544,16 +551,15 @@ 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" : ""), + "XCLIENT PROTO=%sSMTP%s%V ADDR=%V%s%V NAME=%V" CRLF, + (s->esmtp ? "E" : ""), (s->smtp_helo.len ? " HELO=" : ""), &s->smtp_helo, &s->connection->addr_text, (s->login.len ? " LOGIN=" : ""), &s->login, &s->host) - line.data; - s->mail_state = s->auth_method == NGX_MAIL_AUTH_NONE ? - ngx_smtp_xclient_from : ngx_smtp_xclient; + s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ? + ngx_smtp_xclient_from : ngx_smtp_xclient; break; @@ -602,15 +608,16 @@ ngx_mail_proxy_smtp_handler(ngx_event_t case ngx_smtp_xclient: case ngx_smtp_to: - if (s->auth_method != NGX_MAIL_AUTH_NONE) { - ngx_memcpy(s->proxy->buffer->start, smtp_ok, - sizeof(smtp_ok) - 1); - s->proxy->buffer->last = s->proxy->buffer->start - + sizeof(smtp_ok) - 1; - s->proxy->buffer->pos = s->proxy->buffer->start; + b = s->proxy->buffer; + + if (s->auth_method == NGX_MAIL_AUTH_NONE) { + b->pos = b->start; + + } else { + ngx_memcpy(b->start, smtp_ok, sizeof(smtp_ok) - 1); + b->last = b->start + sizeof(smtp_ok) - 1; } - s->connection->read->handler = ngx_mail_proxy_handler; s->connection->write->handler = ngx_mail_proxy_handler; rev->handler = ngx_mail_proxy_handler; @@ -662,7 +669,7 @@ ngx_mail_proxy_dummy_handler(ngx_event_t ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy dummy handler"); - if (ngx_handle_write_event(wev, 0) == NGX_ERROR) { + if (ngx_handle_write_event(wev, 0) != NGX_OK) { c = wev->data; s = c->data; @@ -753,20 +760,17 @@ ngx_mail_proxy_read_response(ngx_mail_se default: /* NGX_MAIL_SMTP_PROTOCOL */ switch (state) { - case ngx_smtp_to: - return NGX_OK; - - case ngx_smtp_helo: - case ngx_smtp_helo_from: - case ngx_smtp_helo_xclient: - case ngx_smtp_from: - if (p[0] == '2' && p[1] == '5' && p[2] == '0') { + case ngx_smtp_start: + if (p[0] == '2' && p[1] == '2' && p[2] == '0') { return NGX_OK; } break; - case ngx_smtp_start: - if (p[0] == '2' && p[1] == '2' && p[2] == '0') { + case ngx_smtp_helo: + case ngx_smtp_helo_xclient: + case ngx_smtp_helo_from: + case ngx_smtp_from: + if (p[0] == '2' && p[1] == '5' && p[2] == '0') { return NGX_OK; } break; @@ -777,6 +781,9 @@ ngx_mail_proxy_read_response(ngx_mail_se return NGX_OK; } break; + + case ngx_smtp_to: + return NGX_OK; } break; @@ -945,22 +952,22 @@ ngx_mail_proxy_handler(ngx_event_t *ev) return; } - if (ngx_handle_write_event(dst->write, 0) == NGX_ERROR) { + if (ngx_handle_write_event(dst->write, 0) != NGX_OK) { ngx_mail_proxy_close_session(s); return; } - if (ngx_handle_read_event(dst->read, 0) == NGX_ERROR) { + if (ngx_handle_read_event(dst->read, 0) != NGX_OK) { ngx_mail_proxy_close_session(s); return; } - if (ngx_handle_write_event(src->write, 0) == NGX_ERROR) { + if (ngx_handle_write_event(src->write, 0) != NGX_OK) { ngx_mail_proxy_close_session(s); return; } - if (ngx_handle_read_event(src->read, 0) == NGX_ERROR) { + if (ngx_handle_read_event(src->read, 0) != NGX_OK) { ngx_mail_proxy_close_session(s); return; }