ngx_mail_pop3_module, ngx_mail_imap_module, and ngx_mail_smtp_module
diff --git a/auto/modules b/auto/modules
index ee5462d..f479ea9 100644
--- a/auto/modules
+++ b/auto/modules
@@ -308,8 +308,6 @@
 
 
 if [ $MAIL_SSL = YES ]; then
-    MAIL_DEPS="$MAIL_DEPS $MAIL_SSL_DEPS"
-    MAIL_SRCS="$MAIL_SRCS $MAIL_SSL_SRCS"
     have=NGX_MAIL_SSL . auto/have
     USE_OPENSSL=YES
 fi
@@ -341,6 +339,26 @@
 
     if [ $MAIL_SSL = YES ]; then
         modules="$modules $MAIL_SSL_MODULE"
+        MAIL_DEPS="$MAIL_DEPS $MAIL_SSL_DEPS"
+        MAIL_SRCS="$MAIL_SRCS $MAIL_SSL_SRCS"
+    fi
+
+    if [ $MAIL_POP3 = YES ]; then
+        modules="$modules $MAIL_POP3_MODULE"
+        MAIL_DEPS="$MAIL_DEPS $MAIL_POP3_DEPS"
+        MAIL_SRCS="$MAIL_SRCS $MAIL_POP3_SRCS"
+    fi
+
+    if [ $MAIL_IMAP = YES ]; then
+        modules="$modules $MAIL_IMAP_MODULE"
+        MAIL_DEPS="$MAIL_DEPS $MAIL_IMAP_DEPS"
+        MAIL_SRCS="$MAIL_SRCS $MAIL_IMAP_SRCS"
+    fi
+
+    if [ $MAIL_SMTP = YES ]; then
+        modules="$modules $MAIL_SMTP_MODULE"
+        MAIL_DEPS="$MAIL_DEPS $MAIL_SMTP_DEPS"
+        MAIL_SRCS="$MAIL_SRCS $MAIL_SMTP_SRCS"
     fi
 
     modules="$modules $MAIL_AUTH_HTTP_MODULE"
diff --git a/auto/options b/auto/options
index a9d7a2a..1006e85 100644
--- a/auto/options
+++ b/auto/options
@@ -81,6 +81,9 @@
 
 MAIL=NO
 MAIL_SSL=NO
+MAIL_POP3=YES
+MAIL_IMAP=YES
+MAIL_SMTP=YES
 
 NGX_ADDONS=
 
@@ -190,6 +193,9 @@
         # STUB
         --with-imap)                     MAIL=YES                   ;;
         --with-imap_ssl_module)          MAIL_SSL=YES               ;;
+        --without-mail_pop3_module)      MAIL_POP3=NO               ;;
+        --without-mail_imap_module)      MAIL_IMAP=NO               ;;
+        --without-mail_smtp_module)      MAIL_SMTP=NO               ;;
 
         --add-module=*)                  NGX_ADDONS="$NGX_ADDONS $value" ;;
 
diff --git a/auto/sources b/auto/sources
index 901cdda..c5a4303 100644
--- a/auto/sources
+++ b/auto/sources
@@ -423,11 +423,23 @@
 MAIL_SRCS="src/mail/ngx_mail.c \
            src/mail/ngx_mail_core_module.c \
            src/mail/ngx_mail_handler.c \
-           src/mail/ngx_mail_pop3_handler.c \
-           src/mail/ngx_mail_imap_handler.c \
-           src/mail/ngx_mail_smtp_handler.c \
            src/mail/ngx_mail_parse.c"
 
+MAIL_POP3_MODULE="ngx_mail_pop3_module"
+MAIL_POP3_DEPS="src/mail/ngx_mail_pop3_module.h"
+MAIL_POP3_SRCS="src/mail/ngx_mail_pop3_module.c \
+                src/mail/ngx_mail_pop3_handler.c"
+
+MAIL_IMAP_MODULE="ngx_mail_imap_module"
+MAIL_IMAP_DEPS="src/mail/ngx_mail_imap_module.h"
+MAIL_IMAP_SRCS="src/mail/ngx_mail_imap_module.c \
+                src/mail/ngx_mail_imap_handler.c"
+
+MAIL_SMTP_MODULE="ngx_mail_smtp_module"
+MAIL_SMTP_DEPS="src/mail/ngx_mail_smtp_module.h"
+MAIL_SMTP_SRCS="src/mail/ngx_mail_smtp_module.c \
+                src/mail/ngx_mail_smtp_handler.c"
+
 MAIL_SSL_MODULE="ngx_mail_ssl_module"
 MAIL_SSL_DEPS="src/mail/ngx_mail_ssl_module.h"
 MAIL_SSL_SRCS="src/mail/ngx_mail_ssl_module.c"