520
521
p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
521
522
*p++ = CR; *p = LF;
523
s->mail_state = pcf->xclient ? ngx_smtp_helo: ngx_smtp_noxclient;
525
s->mail_state = ngx_smtp_helo_xclient;
527
} else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
528
s->mail_state = ngx_smtp_helo_from;
531
s->mail_state = ngx_smtp_helo;
536
case ngx_smtp_helo_xclient:
528
537
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
529
538
"mail proxy send xclient");
531
540
s->connection->log->action = "sending XCLIENT to upstream";
533
line.len = sizeof("XCLIENT PROTO=SMTP HELO= ADDR= LOGIN= NAME="
542
line.len = sizeof("XCLIENT ADDR= LOGIN= NAME="
535
+ s->esmtp + s->smtp_helo.len
536
544
+ s->connection->addr_text.len + s->login.len + s->host.len;
538
line.data = ngx_palloc(c->pool, line.len);
546
line.data = ngx_pnalloc(c->pool, line.len);
539
547
if (line.data == NULL) {
540
548
ngx_mail_proxy_internal_server_error(s);
552
line.len = ngx_sprintf(line.data,
553
"XCLIENT ADDR=%V%s%V NAME=%V" CRLF,
554
&s->connection->addr_text,
555
(s->login.len ? " LOGIN=" : ""), &s->login, &s->host)
544
558
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)
559
s->mail_state = ngx_smtp_xclient_helo;
561
} else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
562
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:
565
s->mail_state = ngx_smtp_xclient;
570
case ngx_smtp_xclient_helo:
571
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
572
"mail proxy send client ehlo");
574
s->connection->log->action = "sending client HELO/EHLO to upstream";
576
line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len;
578
line.data = ngx_pnalloc(c->pool, line.len);
579
if (line.data == NULL) {
580
ngx_mail_proxy_internal_server_error(s);
584
line.len = ngx_sprintf(line.data,
585
((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF),
589
s->mail_state = (s->auth_method == NGX_MAIL_AUTH_NONE) ?
590
ngx_smtp_helo_from : ngx_smtp_helo;
594
case ngx_smtp_helo_from:
595
case ngx_smtp_xclient_from:
596
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
597
"mail proxy send mail from");
599
s->connection->log->action = "sending MAIL FROM to upstream";
601
line.len = s->smtp_from.len + sizeof(CRLF) - 1;
602
line.data = ngx_pnalloc(c->pool, line.len);
603
if (line.data == NULL) {
604
ngx_mail_proxy_internal_server_error(s);
608
p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len);
611
s->mail_state = ngx_smtp_from;
616
ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
617
"mail proxy send rcpt to");
619
s->connection->log->action = "sending RCPT TO to upstream";
621
line.len = s->smtp_to.len + sizeof(CRLF) - 1;
622
line.data = ngx_pnalloc(c->pool, line.len);
623
if (line.data == NULL) {
624
ngx_mail_proxy_internal_server_error(s);
628
p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len);
631
s->mail_state = ngx_smtp_to;
562
636
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;
639
b = s->proxy->buffer;
641
if (s->auth_method == NGX_MAIL_AUTH_NONE) {
645
ngx_memcpy(b->start, smtp_auth_ok, sizeof(smtp_auth_ok) - 1);
646
b->last = b->start + sizeof(smtp_auth_ok) - 1;
569
649
s->connection->read->handler = ngx_mail_proxy_handler;
570
650
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) {
979
if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
980
ngx_mail_proxy_close_session(s);
984
if (ngx_handle_read_event(dst->read, 0) != NGX_OK) {
985
ngx_mail_proxy_close_session(s);
989
if (ngx_handle_write_event(src->write, 0) != NGX_OK) {
990
ngx_mail_proxy_close_session(s);
994
if (ngx_handle_read_event(src->read, 0) != NGX_OK) {
903
995
ngx_mail_proxy_close_session(s);