nginx-0.3.10-RELEASE import

    *) Change: the "valid_referers" directive and the "$invalid_referer"
       variable were moved to the new ngx_http_referer_module from the
       ngx_http_rewrite_module.

    *) Change: the "$apache_bytes_sent" variable name was changed to
       "$body_bytes_sent".

    *) Feature: the "$sent_http_..." variables.

    *) Feature: the "if" directive supports the "=" and "!=" operations.

    *) Feature: the "proxy_pass" directive supports the HTTPS protocol.

    *) Feature: the "proxy_set_body" directive.

    *) Feature: the "post_action" directive.

    *) Feature: the ngx_http_empty_gif_module.

    *) Feature: the "worker_cpu_affinity" directive for Linux.

    *) Bugfix: the "rewrite" directive did not unescape URI part in
       redirect, now it is unescaped except the %00-%25 and %7F-%FF
       characters.

    *) Bugfix: nginx could not be built by the icc 9.0 compiler.

    *) Bugfix: if the SSI was enabled for zero size static file, then the
       chunked response was encoded incorrectly.
diff --git a/src/imap/ngx_imap.c b/src/imap/ngx_imap.c
index b8a75ad..2b768dd 100644
--- a/src/imap/ngx_imap.c
+++ b/src/imap/ngx_imap.c
@@ -28,12 +28,12 @@
       ngx_null_command
 };
 
-    
+
 static ngx_core_module_t  ngx_imap_module_ctx = {
     ngx_string("imap"),
     NULL,
     NULL
-};  
+};
 
 
 ngx_module_t  ngx_imap_module = {
@@ -164,7 +164,7 @@
         /* init imap{} main_conf's */
 
         if (module->init_main_conf) {
-            rv = module->init_main_conf(cf, ctx->main_conf[mi]); 
+            rv = module->init_main_conf(cf, ctx->main_conf[mi]);
             if (rv != NGX_CONF_OK) {
                 *cf = pcf;
                 return rv;
@@ -172,9 +172,9 @@
         }
 
         for (s = 0; s < cmcf->servers.nelts; s++) {
-    
+
             /* merge the server{}s' srv_conf's */
-    
+
             if (module->merge_srv_conf) {
                 rv = module->merge_srv_conf(cf,
                                             ctx->srv_conf[mi],
@@ -187,9 +187,9 @@
         }
     }
 
-    /* imap{}'s cf->ctx was needed while the configuration merging */ 
-    
-    *cf = pcf; 
+    /* imap{}'s cf->ctx was needed while the configuration merging */
+
+    *cf = pcf;
 
     return NGX_CONF_OK;
 }
diff --git a/src/imap/ngx_imap_auth_http_module.c b/src/imap/ngx_imap_auth_http_module.c
index dfe0c20..75350d5 100644
--- a/src/imap/ngx_imap_auth_http_module.c
+++ b/src/imap/ngx_imap_auth_http_module.c
@@ -217,7 +217,7 @@
     ngx_log_debug0(NGX_LOG_DEBUG_IMAP, wev->log, 0,
                    "imap auth http write handler");
 
-    if (wev->timedout) {  
+    if (wev->timedout) {
         ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT,
                       "auth http server %V timed out",
                       &ctx->peer.peers->peer[0].name);
@@ -275,7 +275,7 @@
 
     ctx = ngx_imap_get_module_ctx(s, ngx_imap_auth_http_module);
 
-    if (rev->timedout) {  
+    if (rev->timedout) {
         ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
                       "auth http server %V timed out",
                       &ctx->peer.peers->peer[0].name);
@@ -384,7 +384,7 @@
                 state = sw_almost_done;
 
                 break;
-            case LF: 
+            case LF:
                 goto done;
             }
             break;
@@ -767,11 +767,11 @@
         sw_space_before_value,
         sw_value,
         sw_space_after_value,
-        sw_almost_done, 
+        sw_almost_done,
         sw_header_almost_done
     } state;
 
-    state = ctx->state; 
+    state = ctx->state;
     hash = ctx->hash;
 
     for (p = ctx->response->pos; p < ctx->response->last; p++) {
@@ -784,10 +784,10 @@
 
             switch (ch) {
             case CR:
-                ctx->header_end = p; 
+                ctx->header_end = p;
                 state = sw_header_almost_done;
                 break;
-            case LF: 
+            case LF:
                 ctx->header_end = p;
                 goto header_done;
             default:
@@ -1061,9 +1061,9 @@
 
 static void *
 ngx_imap_auth_http_create_conf(ngx_conf_t *cf)
-{           
+{
     ngx_imap_auth_http_conf_t  *ahcf;
-            
+
     ahcf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_auth_http_conf_t));
     if (ahcf == NULL) {
         return NGX_CONF_ERROR;
@@ -1128,7 +1128,7 @@
 
 static char *
 ngx_imap_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{   
+{
     ngx_imap_auth_http_conf_t *ahcf = conf;
 
     ngx_str_t                   *value, *url;
@@ -1159,13 +1159,13 @@
         ahcf->host_header.len = sizeof("localhost") - 1;
         ahcf->host_header.data = (u_char *) "localhost";
         ahcf->uri = unix_upstream.uri;
-    
+
 #else
         ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                            "the unix domain sockets are not supported "
                            "on this platform");
         return NGX_CONF_ERROR;
-    
+
 #endif
 
     } else {
@@ -1196,7 +1196,7 @@
 
 static char *
 ngx_imap_auth_http_header(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{   
+{
     ngx_imap_auth_http_conf_t *ahcf = conf;
 
     ngx_str_t        *value;
diff --git a/src/imap/ngx_imap_core_module.c b/src/imap/ngx_imap_core_module.c
index d037ad8..6408e54 100644
--- a/src/imap/ngx_imap_core_module.c
+++ b/src/imap/ngx_imap_core_module.c
@@ -127,7 +127,7 @@
 
 static void *
 ngx_imap_core_create_main_conf(ngx_conf_t *cf)
-{           
+{
     ngx_imap_core_main_conf_t  *cmcf;
 
     cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_core_main_conf_t));
@@ -147,9 +147,9 @@
 
 static void *
 ngx_imap_core_create_srv_conf(ngx_conf_t *cf)
-{           
+{
     ngx_imap_core_srv_conf_t  *cscf;
-            
+
     cscf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_core_srv_conf_t));
     if (cscf == NULL) {
         return NULL;
@@ -299,7 +299,7 @@
 
     imap_ctx = cf->ctx;
     ctx->main_conf = imap_ctx->main_conf;
-    
+
     /* the server{}'s srv_conf */
 
     ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_imap_max_module);
@@ -388,7 +388,7 @@
 
         if (in_addr == INADDR_NONE) {
             h = gethostbyname((const char *) inet_upstream.host.data);
-    
+
             if (h == NULL || h->h_addr_list[0] == NULL) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "can not resolve host \"%s\" "
@@ -407,7 +407,7 @@
 
     ls = ngx_listening_inet_stream_socket(cf, in_addr, inet_upstream.port);
     if (ls == NULL) {
-        return NGX_CONF_ERROR; 
+        return NGX_CONF_ERROR;
     }
 
     ls->backlog = -1;
diff --git a/src/imap/ngx_imap_handler.c b/src/imap/ngx_imap_handler.c
index ac5db73..ddff96a 100644
--- a/src/imap/ngx_imap_handler.c
+++ b/src/imap/ngx_imap_handler.c
@@ -17,7 +17,6 @@
 
 #if (NGX_IMAP_SSL)
 static void ngx_imap_ssl_handshake_handler(ngx_connection_t *c);
-static void ngx_imap_ssl_close_handler(ngx_event_t *ev);
 #endif
 
 
@@ -58,7 +57,7 @@
     if (lctx == NULL) {
         ngx_imap_close_connection(c);
         return;
-    } 
+    }
 
     lctx->client = &c->addr_text;
     lctx->session = NULL;
@@ -106,7 +105,7 @@
 
 static void
 ngx_imap_ssl_handshake_handler(ngx_connection_t *c)
-{   
+{
     if (c->ssl->handshaked) {
         ngx_imap_init_session(c);
         return;
@@ -181,6 +180,7 @@
 
     if (wev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
+        c->timedout = 1;
         ngx_imap_close_connection(c);
         return;
     }
@@ -246,6 +246,7 @@
 
     if (rev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
+        c->timedout = 1;
         ngx_imap_close_connection(c);
         return;
     }
@@ -298,6 +299,7 @@
 
     if (rev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
+        c->timedout = 1;
         ngx_imap_close_connection(c);
         return;
     }
@@ -498,6 +500,7 @@
 
     if (rev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
+        c->timedout = 1;
         ngx_imap_close_connection(c);
         return;
     }
@@ -725,8 +728,7 @@
 
     if (c->ssl) {
         if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
-            c->read->handler = ngx_imap_ssl_close_handler;
-            c->write->handler = ngx_imap_ssl_close_handler;
+            c->ssl->handler = ngx_imap_close_connection;
             return;
         }
     }
@@ -743,27 +745,6 @@
 }
 
 
-#if (NGX_IMAP_SSL)
- 
-static void
-ngx_imap_ssl_close_handler(ngx_event_t *ev)
-{
-    ngx_connection_t  *c;
-
-    c = ev->data;
-
-    ngx_log_debug0(NGX_LOG_DEBUG_IMAP, ev->log, 0, "http ssl close handler");
-
-    if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
-        return;
-    }
-
-    ngx_imap_close_connection(c);
-}
-
-#endif
-
-
 static u_char *
 ngx_imap_log_error(ngx_log_t *log, u_char *buf, size_t len)
 {
@@ -776,7 +757,7 @@
         len -= p - buf;
         buf = p;
     }
-    
+
     ctx = log->data;
 
     p = ngx_snprintf(buf, len, ", client: %V", ctx->client);
diff --git a/src/imap/ngx_imap_parse.c b/src/imap/ngx_imap_parse.c
index 473825c..d8c436b 100644
--- a/src/imap/ngx_imap_parse.c
+++ b/src/imap/ngx_imap_parse.c
@@ -473,7 +473,7 @@
         case sw_argument:
             switch (ch) {
 
-         /* 
+         /*
           * the space should be considered part of the at username
           * or password, but not of argument in other commands
           *
diff --git a/src/imap/ngx_imap_proxy_module.c b/src/imap/ngx_imap_proxy_module.c
index e1cccf1..6232960 100644
--- a/src/imap/ngx_imap_proxy_module.c
+++ b/src/imap/ngx_imap_proxy_module.c
@@ -172,6 +172,7 @@
     if (rev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                       "upstream timed out");
+        c->timedout = 1;
         ngx_imap_proxy_internal_server_error(s);
         return;
     }
@@ -310,6 +311,7 @@
     if (rev->timedout) {
         ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                       "upstream timed out");
+        c->timedout = 1;
         ngx_imap_proxy_internal_server_error(s);
         return;
     }
@@ -501,6 +503,8 @@
         if (c == s->connection) {
             ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                           "client timed out");
+            c->timedout = 1;
+
         } else {
             ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                           "upstream timed out");
@@ -652,9 +656,9 @@
 
 static void *
 ngx_imap_proxy_create_conf(ngx_conf_t *cf)
-{           
+{
     ngx_imap_proxy_conf_t  *pcf;
-            
+
     pcf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_proxy_conf_t));
     if (pcf == NULL) {
         return NGX_CONF_ERROR;
diff --git a/src/imap/ngx_imap_ssl_module.c b/src/imap/ngx_imap_ssl_module.c
index f92dba6..cbbbb68 100644
--- a/src/imap/ngx_imap_ssl_module.c
+++ b/src/imap/ngx_imap_ssl_module.c
@@ -27,7 +27,7 @@
 #endif
 
 
-static ngx_conf_bitmask_t  ngx_imap_ssl_protocols[] = { 
+static ngx_conf_bitmask_t  ngx_imap_ssl_protocols[] = {
     { ngx_string("SSLv2"), NGX_SSL_SSLv2 },
     { ngx_string("SSLv3"), NGX_SSL_SSLv3 },
     { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
@@ -124,16 +124,16 @@
 
 static void *
 ngx_imap_ssl_create_conf(ngx_conf_t *cf)
-{           
+{
     ngx_imap_ssl_conf_t  *scf;
-            
+
     scf = ngx_pcalloc(cf->pool, sizeof(ngx_imap_ssl_conf_t));
     if (scf == NULL) {
         return NGX_CONF_ERROR;
     }
 
     /*
-     * set by ngx_pcalloc():  
+     * set by ngx_pcalloc():
      *
      *     scf->protocols = 0;
      *
@@ -240,12 +240,12 @@
     return NGX_CONF_OK;
 }
 
-    
+
 #if !defined (SSL_OP_CIPHER_SERVER_PREFERENCE)
-    
+
 static char *
 ngx_imap_ssl_nosupported(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{   
+{
     ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                        "\"%V\" directive is available only in %s,",
                        &cmd->name, cmd->post);