24 static void ngx_mail_proxy_block_read(
ngx_event_t *rev);
25 static void ngx_mail_proxy_pop3_handler(
ngx_event_t *rev);
26 static void ngx_mail_proxy_imap_handler(
ngx_event_t *rev);
27 static void ngx_mail_proxy_smtp_handler(
ngx_event_t *rev);
28 static void ngx_mail_proxy_dummy_handler(
ngx_event_t *ev);
31 static void ngx_mail_proxy_handler(
ngx_event_t *ev);
35 static void *ngx_mail_proxy_create_conf(
ngx_conf_t *cf);
36 static char *ngx_mail_proxy_merge_conf(
ngx_conf_t *cf,
void *parent,
87 ngx_mail_proxy_create_conf,
88 ngx_mail_proxy_merge_conf
94 &ngx_mail_proxy_module_ctx,
95 ngx_mail_proxy_commands,
108 static u_char smtp_auth_ok[] =
"235 2.0.0 OK" CRLF;
127 if (setsockopt(s->
connection->
fd, SOL_SOCKET, SO_KEEPALIVE,
128 (
const void *) &keepalive,
sizeof(
int))
132 "setsockopt(SO_KEEPALIVE) failed");
154 ngx_mail_proxy_internal_server_error(s);
171 ngx_mail_proxy_internal_server_error(s);
209 ngx_mail_proxy_close_session(s);
225 "mail proxy pop3 auth handler");
232 "upstream timed out");
234 ngx_mail_proxy_internal_server_error(s);
238 rc = ngx_mail_proxy_read_response(s, 0);
245 ngx_mail_proxy_upstream_error(s);
258 if (line.
data == NULL) {
259 ngx_mail_proxy_internal_server_error(s);
277 if (line.
data == NULL) {
278 ngx_mail_proxy_internal_server_error(s);
292 rev->
handler = ngx_mail_proxy_handler;
307 #if (NGX_SUPPRESS_WARN)
318 ngx_mail_proxy_internal_server_error(s);
338 "mail proxy imap auth handler");
345 "upstream timed out");
347 ngx_mail_proxy_internal_server_error(s);
351 rc = ngx_mail_proxy_read_response(s, s->
mail_state);
358 ngx_mail_proxy_upstream_error(s);
366 "mail proxy send login");
370 line.
len = s->
tag.
len +
sizeof(
"LOGIN ") - 1
373 if (line.
data == NULL) {
374 ngx_mail_proxy_internal_server_error(s);
392 if (line.
data == NULL) {
393 ngx_mail_proxy_internal_server_error(s);
406 "mail proxy send passwd");
412 if (line.
data == NULL) {
413 ngx_mail_proxy_internal_server_error(s);
426 rev->
handler = ngx_mail_proxy_handler;
441 #if (NGX_SUPPRESS_WARN)
452 ngx_mail_proxy_internal_server_error(s);
474 "mail proxy smtp auth handler");
481 "upstream timed out");
483 ngx_mail_proxy_internal_server_error(s);
487 rc = ngx_mail_proxy_read_response(s, s->
mail_state);
494 ngx_mail_proxy_upstream_error(s);
509 if (line.
data == NULL) {
510 ngx_mail_proxy_internal_server_error(s);
518 sizeof(
"HELO ") - 1);
537 "mail proxy send xclient");
541 line.
len =
sizeof(
"XCLIENT ADDR= LOGIN= NAME="
546 if (line.
data == NULL) {
547 ngx_mail_proxy_internal_server_error(s);
552 "XCLIENT ADDR=%V%s%V NAME=%V" CRLF,
571 "mail proxy send client ehlo");
578 if (line.
data == NULL) {
579 ngx_mail_proxy_internal_server_error(s);
596 "mail proxy send mail from");
602 if (line.
data == NULL) {
603 ngx_mail_proxy_internal_server_error(s);
616 "mail proxy send rcpt to");
622 if (line.
data == NULL) {
623 ngx_mail_proxy_internal_server_error(s);
645 b->
last = b->
start +
sizeof(smtp_auth_ok) - 1;
650 rev->
handler = ngx_mail_proxy_handler;
665 #if (NGX_SUPPRESS_WARN)
676 ngx_mail_proxy_internal_server_error(s);
697 ngx_mail_proxy_close_session(s);
733 *(b->
last - 1) =
'\0';
735 "upstream sent too long response line: \"%s\"",
748 if (p[0] ==
'+' && p[1] ==
'O' && p[2] ==
'K') {
757 if (p[0] ==
'*' && p[1] ==
' ' && p[2] ==
'O' && p[3] ==
'K') {
772 if (p[0] ==
'O' && p[1] ==
'K') {
785 if (p[0] ==
'2' && p[1] ==
'2' && p[2] ==
'0') {
794 if (p[0] ==
'2' && p[1] ==
'5' && p[2] ==
'0') {
802 if (p[0] ==
'2' && (p[1] ==
'2' || p[1] ==
'5') && p[2] ==
'0') {
817 *(b->
last - 2) =
'\0';
819 "upstream sent invalid response: \"%s\"", p);
827 "upstream sent invalid response: \"%V\"", &s->
out);
839 char *action, *recv_action, *send_action;
861 "upstream timed out");
864 ngx_mail_proxy_close_session(s);
870 recv_action =
"proxying and reading from upstream";
871 send_action =
"proxying and sending to client";
877 recv_action =
"proxying and reading from client";
878 send_action =
"proxying and sending to upstream";
886 recv_action =
"proxying and reading from client";
887 send_action =
"proxying and sending to upstream";
893 recv_action =
"proxying and reading from upstream";
894 send_action =
"proxying and sending to client";
901 do_write = ev->
write ? 1 : 0;
904 "mail proxy handler: %d, #%d > #%d",
905 do_write, src->
fd, dst->
fd);
916 n = dst->
send(dst, b->
pos, size);
919 ngx_mail_proxy_close_session(s);
973 ngx_mail_proxy_close_session(s);
978 ngx_mail_proxy_close_session(s);
983 ngx_mail_proxy_close_session(s);
988 ngx_mail_proxy_close_session(s);
993 ngx_mail_proxy_close_session(s);
1009 "close mail proxy connection: %d",
1030 "close mail proxy connection: %d",
1045 "close mail proxy connection: %d",
1076 ngx_mail_proxy_merge_conf(
ngx_conf_t *cf,
void *parent,
void *child)