520
520
p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
521
521
*p++ = CR; *p = LF;
523
s->mail_state = pcf->xclient ? ngx_smtp_helo: ngx_smtp_noxclient;
524
s->mail_state = ngx_smtp_helo_xclient;
526
} else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
527
s->mail_state = ngx_smtp_helo_from;
530
s->mail_state = ngx_smtp_helo;
535
case ngx_smtp_helo_xclient:
528
536
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
529
537
"mail proxy send xclient");
531
539
s->connection->log->action = "sending XCLIENT to upstream";
533
line.len = sizeof("XCLIENT PROTO=SMTP HELO= ADDR= LOGIN= NAME="
541
line.len = sizeof("XCLIENT ADDR= LOGIN= NAME="
535
+ s->esmtp + s->smtp_helo.len
536
543
+ s->connection->addr_text.len + s->login.len + s->host.len;
538
line.data = ngx_palloc(c->pool, line.len);
545
line.data = ngx_pnalloc(c->pool, line.len);
539
546
if (line.data == NULL) {
540
547
ngx_mail_proxy_internal_server_error(s);
551
line.len = ngx_sprintf(line.data,
552
"XCLIENT ADDR=%V%s%V NAME=%V" CRLF,
553
&s->connection->addr_text,
554
(s->login.len ? " LOGIN=" : ""), &s->login, &s->host)
544
557
if (s->smtp_helo.len) {
545
line.len = ngx_sprintf(line.data,
546
"XCLIENT PROTO=%sSMTP HELO=%V ADDR=%V LOGIN=%V "
548
(s->esmtp ? "E" : ""), &s->smtp_helo,
549
&s->connection->addr_text, &s->login, &s->host)
558
s->mail_state = ngx_smtp_xclient_helo;
560
} else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
561
s->mail_state = ngx_smtp_xclient_from;
552
line.len = ngx_sprintf(line.data,
553
"XCLIENT PROTO=SMTP ADDR=%V LOGIN=%V NAME=%V" CRLF,
554
&s->connection->addr_text, &s->login, &s->host)
558
s->mail_state = ngx_smtp_xclient;
561
case ngx_smtp_noxclient:
564
s->mail_state = ngx_smtp_xclient;
569
case ngx_smtp_xclient_helo:
570
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
571
"mail proxy send client ehlo");
573
s->connection->log->action = "sending client HELO/EHLO to upstream";
575
line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len;
577
line.data = ngx_pnalloc(c->pool, line.len);
578
if (line.data == NULL) {
579
ngx_mail_proxy_internal_server_error(s);
583
line.len = ngx_sprintf(line.data,
584
((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF),
588
s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ?
589
ngx_smtp_helo_from : ngx_smtp_helo;
593
case ngx_smtp_helo_from:
594
case ngx_smtp_xclient_from:
595
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
596
"mail proxy send mail from");
598
s->connection->log->action = "sending MAIL FROM to upstream";
600
line.len = s->smtp_from.len + sizeof(CRLF) - 1;
601
line.data = ngx_pnalloc(c->pool, line.len);
602
if (line.data == NULL) {
603
ngx_mail_proxy_internal_server_error(s);
607
p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len);
610
s->mail_state = ngx_smtp_from;
615
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
616
"mail proxy send rcpt to");
618
s->connection->log->action = "sending RCPT TO to upstream";
620
line.len = s->smtp_to.len + sizeof(CRLF) - 1;
621
line.data = ngx_pnalloc(c->pool, line.len);
622
if (line.data == NULL) {
623
ngx_mail_proxy_internal_server_error(s);
627
p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len);
630
s->mail_state = ngx_smtp_to;
562
635
case ngx_smtp_xclient:
564
ngx_memcpy(s->proxy->buffer->start, smtp_ok, sizeof(smtp_ok) - 1);
566
s->proxy->buffer->pos = s->proxy->buffer->start;
567
s->proxy->buffer->last = s->proxy->buffer->start + sizeof(smtp_ok) - 1;
638
b = s->proxy->buffer;
640
if (s->auth_method == NGX_MAIL_AUTH_NONE) {
644
ngx_memcpy(b->start, smtp_auth_ok, sizeof(smtp_auth_ok) - 1);
645
b->last = b->start + sizeof(smtp_auth_ok) - 1;
569
648
s->connection->read->handler = ngx_mail_proxy_handler;
570
649
s->connection->write->handler = ngx_mail_proxy_handler;
887
if (ngx_handle_write_event(dst->write, 0) == NGX_ERROR) {
888
ngx_mail_proxy_close_session(s);
892
if (ngx_handle_read_event(dst->read, 0) == NGX_ERROR) {
893
ngx_mail_proxy_close_session(s);
897
if (ngx_handle_write_event(src->write, 0) == NGX_ERROR) {
898
ngx_mail_proxy_close_session(s);
902
if (ngx_handle_read_event(src->read, 0) == NGX_ERROR) {
977
if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
978
ngx_mail_proxy_close_session(s);
982
if (ngx_handle_read_event(dst->read, 0) != NGX_OK) {
983
ngx_mail_proxy_close_session(s);
987
if (ngx_handle_write_event(src->write, 0) != NGX_OK) {
988
ngx_mail_proxy_close_session(s);
992
if (ngx_handle_read_event(src->read, 0) != NGX_OK) {
903
993
ngx_mail_proxy_close_session(s);