comparison src/mail/ngx_mail_proxy_module.c @ 5399:d3e09aa03a7a

Mail: handle smtp multiline replies. See here for details: http://nginx.org/pipermail/nginx/2010-August/021713.html http://nginx.org/pipermail/nginx/2010-August/021784.html http://nginx.org/pipermail/nginx/2010-August/021785.html
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 Sep 2013 22:10:03 +0400
parents 04e43d03e153
children bb3dc21c89ef
comparison
equal deleted inserted replaced
5398:04e43d03e153 5399:d3e09aa03a7a
705 705
706 706
707 static ngx_int_t 707 static ngx_int_t
708 ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state) 708 ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state)
709 { 709 {
710 u_char *p; 710 u_char *p, *m;
711 ssize_t n; 711 ssize_t n;
712 ngx_buf_t *b; 712 ngx_buf_t *b;
713 ngx_mail_proxy_conf_t *pcf; 713 ngx_mail_proxy_conf_t *pcf;
714 714
715 s->connection->log->action = "reading response from upstream"; 715 s->connection->log->action = "reading response from upstream";
782 } 782 }
783 783
784 break; 784 break;
785 785
786 default: /* NGX_MAIL_SMTP_PROTOCOL */ 786 default: /* NGX_MAIL_SMTP_PROTOCOL */
787
788 if (p[3] == '-') {
789 /* multiline reply, check if we got last line */
790
791 m = b->last - (sizeof(CRLF "200" CRLF) - 1);
792
793 while (m > p) {
794 if (m[0] == CR && m[1] == LF) {
795 break;
796 }
797
798 m--;
799 }
800
801 if (m <= p || m[5] == '-') {
802 return NGX_AGAIN;
803 }
804 }
805
787 switch (state) { 806 switch (state) {
788 807
789 case ngx_smtp_start: 808 case ngx_smtp_start:
790 if (p[0] == '2' && p[1] == '2' && p[2] == '0') { 809 if (p[0] == '2' && p[1] == '2' && p[2] == '0') {
791 return NGX_OK; 810 return NGX_OK;