[exim-cvs] Pipeline QUIT after data

Page principale
Supprimer ce message
Répondre à ce message
Auteur: Exim Git Commits Mailing List
Date:  
À: exim-cvs
Sujet: [exim-cvs] Pipeline QUIT after data
Gitweb: https://git.exim.org/exim.git/commitdiff/001bf8f58763581d117edaa391aa13ac139eb39b
Commit:     001bf8f58763581d117edaa391aa13ac139eb39b
Parent:     843edb3830b89e01fd2b956d2a0d23d13e29b55e
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Sun Mar 14 20:39:03 2021 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Tue Mar 16 16:43:49 2021 +0000


    Pipeline QUIT after data
---
 src/src/daemon.c                 |  12 +-
 src/src/deliver.c                |  46 ------
 src/src/functions.h              |   3 +-
 src/src/macros.h                 |  25 +--
 src/src/receive.c                |  13 +-
 src/src/smtp_in.c                |  21 ++-
 src/src/smtp_out.c               |   5 +-
 src/src/spool_in.c               |  41 +++++
 src/src/tls-gnu.c                |  40 +++--
 src/src/tls-openssl.c            |  49 ++++--
 src/src/transport.c              |  13 +-
 src/src/transports/smtp.c        | 198 +++++++++++++++++++----
 src/src/transports/smtp.h        |   1 +
 test/confs/0623                  |  43 +++++
 test/confs/0900                  |   5 +-
 test/confs/0911                  |  43 +++++
 test/log/0623                    |  20 +++
 test/log/0900                    |  20 +--
 test/log/0904                    |  91 +++++------
 test/log/0905                    |  74 ++++-----
 test/log/0911                    |  30 ++++
 test/log/1114                    |   6 +-
 test/log/1157                    |  18 +--
 test/log/1165                    |  10 +-
 test/log/4521                    |  22 +--
 test/log/4522                    |  10 +-
 test/log/5590                    |  10 +-
 test/log/5591                    |   8 +-
 test/rejectlog/0900              |   4 +-
 test/runtest                     |   2 +
 test/scripts/0000-Basic/0623     | 114 +++++++++++++
 test/scripts/0000-Basic/0904     |  51 +++---
 test/scripts/0000-Basic/0911     | 142 +++++++++++++++++
 test/scripts/1100-Basic-TLS/1157 |   6 +-
 test/stderr/0143                 |   2 +
 test/stderr/0217                 |   4 +
 test/stderr/0218                 |  10 +-
 test/stderr/0276                 |   4 +
 test/stderr/0388                 |   4 +-
 test/stderr/0450                 |   2 +-
 test/stderr/0467                 |   2 +
 test/stderr/0476                 |   4 +-
 test/stderr/0623                 | 190 ++++++++++++++++++++++
 test/stderr/0911                 | 335 +++++++++++++++++++++++++++++++++++++++
 test/stderr/1150                 |   9 +-
 test/stderr/1157                 |  31 ++--
 test/stderr/1160                 |   9 +-
 test/stderr/2035                 |   5 +-
 test/stderr/2135                 |   5 +-
 test/stderr/3404                 |   6 +
 test/stderr/4052                 |  11 +-
 test/stderr/4520                 |   4 +-
 test/stdout/0623                 | 133 ++++++++++++++++
 test/stdout/0904                 |  11 --
 test/stdout/0911                 | 123 ++++++++++++++
 55 files changed, 1754 insertions(+), 346 deletions(-)


diff --git a/src/src/daemon.c b/src/src/daemon.c
index 50c202c..52e6dca 100644
--- a/src/src/daemon.c
+++ b/src/src/daemon.c
@@ -554,7 +554,7 @@ if (pid == 0)
         }
       if (message_id[0] == 0) continue;   /* No message was accepted */
       }
-    else
+    else                /* bad smtp_setup_msg() */
       {
       if (smtp_out)
     {
@@ -674,15 +674,15 @@ if (pid == 0)
       {
       pid_t dpid;


-      /* Before forking, ensure that the C output buffer is flushed. Otherwise
-      anything that it in it will get duplicated, leading to duplicate copies
-      of the pending output. */
-
-      mac_smtp_fflush();
+      /* We used to flush smtp_out before forking so that buffered data was not
+      duplicated, but now we want to pipeline the responses for data and quit.
+      Instead, hard-close the fd underlying smtp_out right after fork to discard
+      the data buffer. */


       if ((dpid = exim_fork(US"daemon-accept-delivery")) == 0)
         {
         (void)fclose(smtp_in);
+    (void)close(fileno(smtp_out));
         (void)fclose(smtp_out);


         /* Don't ever molest the parent's SSL connection, but do clean up
diff --git a/src/src/deliver.c b/src/src/deliver.c
index 833970c..29e2b71 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -8549,52 +8549,6 @@ f.tcp_fastopen_ok = TRUE;
 }



-uschar *
-deliver_get_sender_address (uschar * id)
-{
-int rc;
-uschar * new_sender_address,
-       * save_sender_address;
-BOOL save_qr = f.queue_running;
-uschar * spoolname;
-
-/* make spool_open_datafile non-noisy on fail */
-
-f.queue_running = TRUE;
-
-/* Side effect: message_subdir is set for the (possibly split) spool directory */
-
-deliver_datafile = spool_open_datafile(id);
-f.queue_running = save_qr;
-if (deliver_datafile < 0)
-  return NULL;
-
-/* Save and restore the global sender_address.  I'm not sure if we should
-not save/restore all the other global variables too, because
-spool_read_header() may change all of them. But OTOH, when this
-deliver_get_sender_address() gets called, the current message is done
-already and nobody needs the globals anymore. (HS12, 2015-08-21) */
-
-spoolname = string_sprintf("%s-H", id);
-save_sender_address = sender_address;
-
-rc = spool_read_header(spoolname, TRUE, TRUE);
-
-new_sender_address = sender_address;
-sender_address = save_sender_address;
-
-if (rc != spool_read_OK)
-  return NULL;
-
-assert(new_sender_address);
-
-(void)close(deliver_datafile);
-deliver_datafile = -1;
-
-return new_sender_address;
-}
-
-


 void
 delivery_re_exec(int exec_type)
diff --git a/src/src/functions.h b/src/src/functions.h
index 38309e7..5ffb23d 100644
--- a/src/src/functions.h
+++ b/src/src/functions.h
@@ -75,6 +75,7 @@ extern BOOL    tls_openssl_options_parse(uschar *, long *);
 # endif
 extern int     tls_read(void *, uschar *, size_t);
 extern int     tls_server_start(uschar **);
+extern void    tls_shutdown_wr(void *);
 extern BOOL    tls_smtp_buffered(void);
 extern int     tls_ungetc(int);
 #if defined(EXIM_HAVE_INOTIFY) || defined(EXIM_HAVE_KEVENT)
@@ -204,7 +205,6 @@ extern void    deliver_set_expansions(address_item *);
 extern int     deliver_split_address(address_item *);
 extern void    deliver_succeeded(address_item *);


-extern uschar *deliver_get_sender_address (uschar *id);
 extern void    delivery_re_exec(int);


 extern void    die_tainted(const uschar *, const uschar *, int);
@@ -514,6 +514,7 @@ extern BOOL    spool_move_message(uschar *, uschar *, uschar *, uschar *);
 extern int     spool_open_datafile(uschar *);
 extern int     spool_open_temp(uschar *);
 extern int     spool_read_header(uschar *, BOOL, BOOL);
+extern uschar *spool_sender_from_msgid(const uschar *);
 extern int     spool_write_header(uschar *, int, uschar **);
 extern int     stdin_getc(unsigned);
 extern int     stdin_feof(void);
diff --git a/src/src/macros.h b/src/src/macros.h
index 68470a9..0b64756 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -866,18 +866,19 @@ enum {


/* Options for transport_write_message */

-#define topt_add_return_path    0x001
-#define topt_add_delivery_date  0x002
-#define topt_add_envelope_to    0x004
-#define topt_use_crlf           0x008  /* Terminate lines with CRLF */
-#define topt_end_dot            0x010  /* Send terminating dot line */
-#define topt_no_headers         0x020  /* Omit headers */
-#define topt_no_body            0x040  /* Omit body */
-#define topt_escape_headers     0x080  /* Apply escape check to headers */
-#define topt_use_bdat        0x100  /* prepend chunks with RFC3030 BDAT header */
-#define topt_output_string    0x200  /* create string rather than write to fd */
-#define topt_continuation    0x400  /* do not reset buffer */
-#define topt_not_socket        0x800  /* cannot do socket-only syscalls */
+#define topt_add_return_path    0x0001
+#define topt_add_delivery_date  0x0002
+#define topt_add_envelope_to    0x0004
+#define topt_escape_headers     0x0008    /* Apply escape check to headers */
+#define topt_use_crlf           0x0010    /* Terminate lines with CRLF */
+#define topt_no_headers         0x0020    /* Omit headers */
+#define topt_no_body            0x0040    /* Omit body */
+#define topt_end_dot            0x0080    /* Send terminating dot line */
+#define topt_no_flush        0x0100    /* more data expected after message (eg QUIT) */
+#define topt_use_bdat        0x0200    /* prepend chunks with RFC3030 BDAT header */
+#define topt_output_string    0x0400    /* create string rather than write to fd */
+#define topt_continuation    0x0800    /* do not reset buffer */
+#define topt_not_socket        0x1000    /* cannot do socket-only syscalls */


/* Options for smtp_write_command */

diff --git a/src/src/receive.c b/src/src/receive.c
index 00c431f..3e950ff 100644
--- a/src/src/receive.c
+++ b/src/src/receive.c
@@ -4177,12 +4177,10 @@ response, but the chance of this happening should be small. */
 if (smtp_input && sender_host_address && !f.sender_host_notsocket &&
     !receive_smtp_buffered())
   {
-  struct timeval tv;
+  struct timeval tv = {.tv_sec = 0, .tv_usec = 0};
   fd_set select_check;
   FD_ZERO(&select_check);
   FD_SET(fileno(smtp_in), &select_check);
-  tv.tv_sec = 0;
-  tv.tv_usec = 0;


   if (select(fileno(smtp_in) + 1, &select_check, NULL, NULL, &tv) != 0)
     {
@@ -4375,12 +4373,17 @@ if (smtp_input)


       else if (chunking_state > CHUNKING_OFFERED)
     {
-        smtp_printf("250- %u byte chunk, total %d\r\n250 OK id=%s\r\n", FALSE,
+    /* If there is more input waiting, no need to flush (probably the client
+    pipelined QUIT after data).  We check only the in-process buffer, not
+    the socket. */
+
+        smtp_printf("250- %u byte chunk, total %d\r\n250 OK id=%s\r\n",
+        receive_smtp_buffered(),
         chunking_datasize, message_size+message_linecount, message_id);
     chunking_state = CHUNKING_OFFERED;
     }
       else
-        smtp_printf("250 OK id=%s\r\n", FALSE, message_id);
+        smtp_printf("250 OK id=%s\r\n", receive_smtp_buffered(), message_id);


       if (host_checking)
         fprintf(stdout,
diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c
index 14dd114..03085c9 100644
--- a/src/src/smtp_in.c
+++ b/src/src/smtp_in.c
@@ -347,7 +347,7 @@ wouldblock_reading(void)
 {
 int fd, rc;
 fd_set fds;
-struct timeval tzero;
+struct timeval tzero = {.tv_sec = 0, .tv_usec = 0};


#ifndef DISABLE_TLS
if (tls_in.active.sock >= 0)
@@ -360,8 +360,6 @@ if (smtp_inptr < smtp_inend)
fd = fileno(smtp_in);
FD_ZERO(&fds);
FD_SET(fd, &fds);
-tzero.tv_sec = 0;
-tzero.tv_usec = 0;
rc = select(fd + 1, (SELECT_ARG2_TYPE *)&fds, NULL, NULL, &tzero);

 if (rc <= 0) return TRUE;     /* Not ready to read */
@@ -587,6 +585,8 @@ smtp_get_cache(void)
 {
 #ifndef DISABLE_DKIM
 int n = smtp_inend - smtp_inptr;
+if (chunking_state == CHUNKING_LAST && chunking_data_left < n)
+  n = chunking_data_left;
 if (n > 0)
   dkim_exim_verify_feed(smtp_inptr, n);
 #endif
@@ -3844,11 +3844,24 @@ else
   smtp_printf("221 %s closing connection\r\n", FALSE, smtp_active_hostname);


#ifndef DISABLE_TLS
-tls_close(NULL, TLS_SHUTDOWN_NOWAIT);
+tls_close(NULL, TLS_SHUTDOWN_WAIT);
#endif

log_write(L_smtp_connection, LOG_MAIN, "%s closed by QUIT",
smtp_get_connection_info());
+
+/* Pause, hoping client will FIN first so that they get the TIME_WAIT.
+The socket should become readble (though with no data) */
+
+ {
+ int fd = fileno(smtp_in);
+ fd_set fds;
+ struct timeval t_limit = {.tv_sec = 0, .tv_usec = 200*1000};
+
+ FD_ZERO(&fds);
+ FD_SET(fd, &fds);
+ (void) select(fd + 1, (SELECT_ARG2_TYPE *)&fds, NULL, NULL, &t_limit);
+ }
}


diff --git a/src/src/smtp_out.c b/src/src/smtp_out.c
index 2b03c03..2a44974 100644
--- a/src/src/smtp_out.c
+++ b/src/src/smtp_out.c
@@ -659,8 +659,9 @@ if (format)
     while (*p) *p++ = '*';
     }


-  HDEBUG(D_transport|D_acl|D_v)
-    debug_printf_indent("  SMTP%c> %s\n", ">+|"[mode], big_buffer);
+  HDEBUG(D_transport|D_acl|D_v) debug_printf_indent("  SMTP%c> %s\n",
+    mode == SCMD_BUFFER ? '|' : mode == SCMD_MORE ? '+' : '>',
+    big_buffer);
   }


if (mode != SCMD_BUFFER)
diff --git a/src/src/spool_in.c b/src/src/spool_in.c
index 022ac02..9794e93 100644
--- a/src/src/spool_in.c
+++ b/src/src/spool_in.c
@@ -993,6 +993,47 @@ errno = ERRNO_SPOOLFORMAT;
return inheader? spool_read_hdrerror : spool_read_enverror;
}

+
+#ifndef COMPILE_UTILITY
+/* Read out just the (envelope) sender string from the spool -H file.
+Remove the <> wrap and return it in allocated store.  Return NULL on error.
+
+We assume that message_subdir is already set.
+*/
+
+uschar *
+spool_sender_from_msgid(const uschar * id)
+{
+uschar * name = string_sprintf("%s-H", id);
+FILE * fp;
+int n;
+uschar * yield = NULL;
+
+if (!(fp = Ufopen(spool_fname(US"input", message_subdir, name, US""), "rb")))
+  return NULL;
+
+DEBUG(D_deliver) debug_printf_indent("reading spool file %s\n", name);
+
+/* Skip the line with the copy of the filename, then the line with login/uid/gid.
+Read the next line, which should be the envelope sender.
+Do basic validation on that. */
+
+if (  Ufgets(big_buffer, big_buffer_size, fp) != NULL
+   && Ufgets(big_buffer, big_buffer_size, fp) != NULL
+   && Ufgets(big_buffer, big_buffer_size, fp) != NULL
+   && (n = Ustrlen(big_buffer)) >= 3
+   && big_buffer[0] == '<' && big_buffer[n-2] == '>'
+   )
+  {
+  yield = store_get(n-2, TRUE);    /* tainted */
+  Ustrncpy(yield, big_buffer+1, n-3);
+  yield[n-3] = 0;
+  }
+fclose(fp);
+return yield;
+}
+#endif  /* COMPILE_UTILITY */
+
 /* vi: aw ai sw=2
 */
 /* End of spool_in.c */
diff --git a/src/src/tls-gnu.c b/src/src/tls-gnu.c
index 46547d7..89e3ef2 100644
--- a/src/src/tls-gnu.c
+++ b/src/src/tls-gnu.c
@@ -3489,6 +3489,25 @@ return TRUE;




+/*
+Arguments:
+  ct_ctx    client TLS context pointer, or NULL for the one global server context
+*/
+
+void
+tls_shutdown_wr(void * ct_ctx)
+{
+exim_gnutls_state_st * state = ct_ctx ? ct_ctx : &state_server;
+tls_support * tlsp = state->tlsp;
+
+if (!tlsp || tlsp->active.sock < 0) return;  /* TLS was not active */
+
+tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */
+
+HDEBUG(D_transport|D_tls|D_acl|D_v) debug_printf_indent("  SMTP(TLS shutdown)>>\n");
+gnutls_bye(state->session, GNUTLS_SHUT_WR);
+}
+
 /*************************************************
 *         Close down a TLS session               *
 *************************************************/
@@ -3499,29 +3518,30 @@ would tamper with the TLS session in the parent process).


 Arguments:
   ct_ctx    client context pointer, or NULL for the one global server context
-  shutdown    1 if TLS close-alert is to be sent,
-        2 if also response to be waited for
+  do_shutdown    0 no data-flush or TLS close-alert
+        1 if TLS close-alert is to be sent,
+        2 if also response to be waited for (2s timeout)


 Returns:     nothing
 */


void
-tls_close(void * ct_ctx, int shutdown)
+tls_close(void * ct_ctx, int do_shutdown)
{
exim_gnutls_state_st * state = ct_ctx ? ct_ctx : &state_server;
tls_support * tlsp = state->tlsp;

if (!tlsp || tlsp->active.sock < 0) return; /* TLS was not active */

-tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */
-
-if (shutdown)
+if (do_shutdown)
   {
   DEBUG(D_tls) debug_printf("tls_close(): shutting down TLS%s\n",
-    shutdown > 1 ? " (with response-wait)" : "");
+    do_shutdown > 1 ? " (with response-wait)" : "");
+
+  tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */


ALARM(2);
- gnutls_bye(state->session, shutdown > 1 ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
+ gnutls_bye(state->session, do_shutdown > 1 ? GNUTLS_SHUT_RDWR : GNUTLS_SHUT_WR);
ALARM_CLR(0);
}

@@ -3669,7 +3689,7 @@ return buf;


void
-tls_get_cache()
+tls_get_cache(void)
{
#ifndef DISABLE_DKIM
exim_gnutls_state_st * state = &state_server;
@@ -3688,8 +3708,6 @@ return state_server.xfer_buffer_lwm < state_server.xfer_buffer_hwm
}


-
-
 /*************************************************
 *          Read bytes from TLS channel           *
 *************************************************/
diff --git a/src/src/tls-openssl.c b/src/src/tls-openssl.c
index 0d653a4..13b0c23 100644
--- a/src/src/tls-openssl.c
+++ b/src/src/tls-openssl.c
@@ -3941,7 +3941,7 @@ return buf;



 void
-tls_get_cache()
+tls_get_cache(void)
 {
 #ifndef DISABLE_DKIM
 int n = ssl_xfer_buffer_hwm - ssl_xfer_buffer_lwm;
@@ -3955,7 +3955,7 @@ BOOL
 tls_could_read(void)
 {
 return ssl_xfer_buffer_lwm < ssl_xfer_buffer_hwm
-      || SSL_pending(state_server.lib_state.lib_ssl) > 0;
+    || SSL_pending(state_server.lib_state.lib_ssl) > 0;
 }



@@ -4120,6 +4120,32 @@ return olen;



+/*
+Arguments:
+  ct_ctx    client TLS context pointer, or NULL for the one global server context
+*/
+
+void
+tls_shutdown_wr(void * ct_ctx)
+{
+exim_openssl_client_tls_ctx * o_ctx = ct_ctx;
+SSL ** sslp = o_ctx ? &o_ctx->ssl : (SSL **) &state_server.lib_state.lib_ssl;
+int * fdp = o_ctx ? &tls_out.active.sock : &tls_in.active.sock;
+int rc;
+
+if (*fdp < 0) return;  /* TLS was not active */
+
+tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */
+
+HDEBUG(D_transport|D_tls|D_acl|D_v) debug_printf_indent("  SMTP(TLS shutdown)>>\n");
+rc = SSL_shutdown(*sslp);
+if (rc < 0) DEBUG(D_tls)
+  {
+  ERR_error_string_n(ERR_get_error(), ssl_errstring, sizeof(ssl_errstring));
+  debug_printf("SSL_shutdown: %s\n", ssl_errstring);
+  }
+}
+
 /*************************************************
 *         Close down a TLS session               *
 *************************************************/
@@ -4130,7 +4156,8 @@ would tamper with the SSL session in the parent process).


 Arguments:
   ct_ctx    client TLS context pointer, or NULL for the one global server context
-  shutdown    1 if TLS close-alert is to be sent,
+  do_shutdown    0 no data-flush or TLS close-alert
+        1 if TLS close-alert is to be sent,
          2 if also response to be waited for


 Returns:     nothing
@@ -4139,24 +4166,24 @@ Used by both server-side and client-side TLS.
 */


void
-tls_close(void * ct_ctx, int shutdown)
+tls_close(void * ct_ctx, int do_shutdown)
{
exim_openssl_client_tls_ctx * o_ctx = ct_ctx;
-SSL **sslp = o_ctx ? &o_ctx->ssl : (SSL **) &state_server.lib_state.lib_ssl;
-int *fdp = o_ctx ? &tls_out.active.sock : &tls_in.active.sock;
+SSL ** sslp = o_ctx ? &o_ctx->ssl : (SSL **) &state_server.lib_state.lib_ssl;
+int * fdp = o_ctx ? &tls_out.active.sock : &tls_in.active.sock;

if (*fdp < 0) return; /* TLS was not active */

-tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */
-
-if (shutdown)
+if (do_shutdown)
   {
   int rc;
   DEBUG(D_tls) debug_printf("tls_close(): shutting down TLS%s\n",
-    shutdown > 1 ? " (with response-wait)" : "");
+    do_shutdown > 1 ? " (with response-wait)" : "");
+
+  tls_write(ct_ctx, NULL, 0, FALSE);    /* flush write buffer */


   if (  (rc = SSL_shutdown(*sslp)) == 0    /* send "close notify" alert */
-     && shutdown > 1)
+     && do_shutdown > 1)
     {
     ALARM(2);
     rc = SSL_shutdown(*sslp);        /* wait for response */
diff --git a/src/src/transport.c b/src/src/transport.c
index c2062e6..31edb96 100644
--- a/src/src/transport.c
+++ b/src/src/transport.c
@@ -886,7 +886,7 @@ transport_write_timeout non-zero.


 Arguments:
   tctx
-    (fd, msg)        Either and fd, to write the message to,
+    (fd, msg)        Either an fd, to write the message to,
             or a string: if null write message to allocated space
             otherwire take content as headers.
     addr                (chain of) addresses (for extra headers), or NULL;
@@ -905,6 +905,7 @@ Arguments:
       add_delivery_date     if TRUE, add a "delivery-date" header
       use_crlf              if TRUE, turn NL into CR LF
       end_dot               if TRUE, send a terminating "." line at the end
+      no_flush            if TRUE, do not flush at end
       no_headers            if TRUE, omit the headers
       no_body               if TRUE, omit the body
     check_string          a string to check for at the start of lines, or NULL
@@ -1161,8 +1162,9 @@ if (tctx->options & topt_end_dot && !write_chunk(tctx, US".\n", 2))


/* Write out any remaining data in the buffer before returning. */

-return (len = chunk_ptr - deliver_out_buffer) <= 0 ||
-  transport_write_block(tctx, deliver_out_buffer, len, FALSE);
+return (len = chunk_ptr - deliver_out_buffer) <= 0
+  || transport_write_block(tctx, deliver_out_buffer, len,
+                !!(tctx->options & topt_no_flush));
 }



@@ -1260,7 +1262,7 @@ if ((write_pid = exim_fork(US"tpt-filter-writer")) == 0)

tctx->u.fd = fd_write;
tctx->check_string = tctx->escape_string = NULL;
- tctx->options &= ~(topt_use_crlf | topt_end_dot | topt_use_bdat);
+ tctx->options &= ~(topt_use_crlf | topt_end_dot | topt_use_bdat | topt_no_flush);

rc = internal_transport_write_message(tctx, size_limit);

@@ -1599,7 +1601,8 @@ for (host_item * host = hostlist; host; host = host->next)
/* Update the database */

   dbfn_write(dbm_file, host->name, host_record, sizeof(dbdata_wait) + host_length);
-  DEBUG(D_transport) debug_printf("added to list for %s\n", host->name);
+  DEBUG(D_transport) debug_printf("added %.*s to queue for %s\n",
+                  MESSAGE_ID_LENGTH, message_id, host->name);
   }


/* All now done */
diff --git a/src/src/transports/smtp.c b/src/src/transports/smtp.c
index 95fa6da..13f617c 100644
--- a/src/src/transports/smtp.c
+++ b/src/src/transports/smtp.c
@@ -1637,8 +1637,9 @@ uschar * message_local_identity,
current_local_identity =
smtp_local_identity(s_compare->current_sender_address, s_compare->tblock);

-if (!(new_sender_address = deliver_get_sender_address(message_id)))
-    return FALSE;
+if (!(new_sender_address = spool_sender_from_msgid(message_id)))
+  return FALSE;
+


 message_local_identity =
   smtp_local_identity(new_sender_address, s_compare->tblock);
@@ -2516,6 +2517,7 @@ if (  smtp_peer_options & OPTION_TLS
       sx->send_quit = FALSE;
       goto TLS_FAILED;
       }
+    sx->send_tlsclose = TRUE;


     /* TLS session is set up.  Check the inblock fill level.  If there is
     content then as we have not yet done a tls read it must have arrived before
@@ -2949,7 +2951,11 @@ if (sx->send_quit)
 #ifndef DISABLE_TLS
 if (sx->cctx.tls_ctx)
   {
-  tls_close(sx->cctx.tls_ctx, TLS_SHUTDOWN_NOWAIT);
+  if (sx->send_tlsclose)
+    {
+    tls_close(sx->cctx.tls_ctx, TLS_SHUTDOWN_NOWAIT);
+    sx->send_tlsclose = FALSE;
+    }
   sx->cctx.tls_ctx = NULL;
   }
 #endif
@@ -3328,6 +3334,7 @@ smtp_proxy_tls(void * ct_ctx, uschar * buf, size_t bsize, int * pfd,
 fd_set rfds, efds;
 int max_fd = MAX(pfd[0], tls_out.active.sock) + 1;
 int rc, i;
+BOOL send_tls_shutdown = TRUE;


close(pfd[1]);
if ((rc = exim_fork(US"tls-proxy")))
@@ -3372,8 +3379,8 @@ for (int fd_bits = 3; fd_bits; )

   /* handle inbound data */
   if (FD_ISSET(tls_out.active.sock, &rfds))
-    if ((rc = tls_read(ct_ctx, buf, bsize)) <= 0)
-      {
+    if ((rc = tls_read(ct_ctx, buf, bsize)) <= 0)    /* Expect -1 for EOF; */
+    {                    /* that reaps the TLS Close Notify record */
       fd_bits &= ~1;
       FD_CLR(tls_out.active.sock, &rfds);
       shutdown(pfd[0], SHUT_WR);
@@ -3384,16 +3391,21 @@ for (int fd_bits = 3; fd_bits; )
       for (int nbytes = 0; rc - nbytes > 0; nbytes += i)
     if ((i = write(pfd[0], buf + nbytes, rc - nbytes)) < 0) goto done;
       }
-  else if (fd_bits & 1)
-    FD_SET(tls_out.active.sock, &rfds);


-  /* handle outbound data */
+  /* Handle outbound data.  We cannot combine payload and the TLS-close
+  due to the limitations of the (pipe) channel feeding us. */
   if (FD_ISSET(pfd[0], &rfds))
     if ((rc = read(pfd[0], buf, bsize)) <= 0)
       {
-      fd_bits = 0;
-      tls_close(ct_ctx, TLS_SHUTDOWN_NOWAIT);
-      ct_ctx = NULL;
+      fd_bits &= ~2;
+      FD_CLR(pfd[0], &rfds);
+
+# ifdef EXIM_TCP_CORK  /* Use _CORK to get TLS Close Notify in FIN segment */
+      (void) setsockopt(tls_out.active.sock, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
+# endif
+      tls_shutdown_wr(ct_ctx);
+      send_tls_shutdown = FALSE;
+      shutdown(tls_out.active.sock, SHUT_WR);
       }
     else
       {
@@ -3401,11 +3413,14 @@ for (int fd_bits = 3; fd_bits; )
     if ((i = tls_write(ct_ctx, buf + nbytes, rc - nbytes, FALSE)) < 0)
       goto done;
       }
-  else if (fd_bits & 2)
-    FD_SET(pfd[0], &rfds);
+
+  if (fd_bits & 1) FD_SET(tls_out.active.sock, &rfds);
+  if (fd_bits & 2) FD_SET(pfd[0], &rfds);
   }


 done:
+  if (send_tls_shutdown) tls_close(ct_ctx, TLS_SHUTDOWN_NOWAIT);
+  ct_ctx = NULL;
   testharness_pause_ms(100);    /* let logging complete */
   exim_exit(EXIT_SUCCESS);
 }
@@ -3478,6 +3493,7 @@ smtp_context * sx = store_get(sizeof(*sx), TRUE);    /* tainted, for the data buffe
 #ifdef SUPPORT_DANE
 BOOL dane_held;
 #endif
+BOOL tcw_done = FALSE, tcw = FALSE;


*message_defer = FALSE;

@@ -3767,6 +3783,44 @@ else
   report_time_since(&t0, US"dkim_exim_sign_init (delta)");
 # endif
   }
+#endif
+
+  /* See if we can pipeline QUIT.  Reasons not to are
+  - pipelining not active
+  - not ok to send quit
+  - errors in amtp transation responses
+  - more addrs to send for this message or this host
+  - more messages for this host
+  If we can, we want the message-write to not flush (the tail end of) its data out.  */
+
+  if (  sx->pipelining_used
+     && (sx->ok && sx->completed_addr || sx->peer_offered & OPTION_CHUNKING)
+     && sx->send_quit
+     && !(sx->first_addr || f.continue_more)
+     )
+    {
+    smtp_compare_t t_compare =
+      {.tblock = tblock, .current_sender_address = sender_address};
+
+    tcw_done = TRUE;
+    tcw =
+#ifndef DISABLE_TLS
+       (  tls_out.active.sock < 0  &&  !continue_proxy_cipher
+           || verify_check_given_host(CUSS &ob->hosts_nopass_tls, host) != OK
+       )
+        &&
+#endif
+           transport_check_waiting(tblock->name, host->name,
+             tblock->connection_max_messages, new_message_id,
+         (oicf)smtp_are_same_identities, (void*)&t_compare);
+    if (!tcw)
+      {
+      HDEBUG(D_transport) debug_printf("will pipeline QUIT\n");
+      tctx.options |= topt_no_flush;
+      }
+    }
+
+#ifndef DISABLE_DKIM
   sx->ok = dkim_transport_write_message(&tctx, &ob->dkim, CUSS &message);
 #else
   sx->ok = transport_write_message(&tctx, 0);
@@ -3795,6 +3849,47 @@ else


smtp_command = US"end of data";

+  /* If we can pipeline a QUIT with the data them send it now.  If a new message
+  for this host appeared in the queue while data was being sent, we will not see
+  it and it will have to wait for a queue run.  If there was one but another
+  thread took it, we might attempt to send it - but locking of spoolfiles will
+  detect that. Use _MORE to get QUIT in FIN segment. */
+
+  if (tcw_done && !tcw)
+    {
+    /*XXX jgh 2021/03/10 google et. al screwup.  G, at least, sends TCP FIN in response to TLS
+    close-notify.  Under TLS 1.3, violating RFC.
+    However, TLS 1.2 does not have half-close semantics. */
+
+    if (  sx->cctx.tls_ctx
+#if 0 && !defined(DISABLE_TLS)
+       && Ustrcmp(tls_out.ver, "TLS1.3") != 0
+#endif
+       )
+      {                /* Send QUIT now and not later */
+      (void)smtp_write_command(sx, SCMD_FLUSH, "QUIT\r\n");
+      sx->send_quit = FALSE;
+      }
+    else
+      {                /* add QUIT to the output buffer */
+      (void)smtp_write_command(sx, SCMD_MORE, "QUIT\r\n");
+      sx->send_quit = FALSE;    /* avoid sending it later */
+
+#ifndef DISABLE_TLS
+      if (sx->cctx.tls_ctx)    /* need to send TLS Cloe Notify */
+    {
+# ifdef EXIM_TCP_CORK        /* Use _CORK to get Close Notify in FIN segment */
+    (void) setsockopt(sx->cctx.sock, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
+# endif
+    tls_shutdown_wr(sx->cctx.tls_ctx);
+    sx->send_tlsclose = FALSE;    /* avoid later repeat */
+    }
+#endif
+      HDEBUG(D_transport|D_acl|D_v) debug_printf_indent("  SMTP(shutdown)>>\n");
+      shutdown(sx->cctx.sock, SHUT_WR);    /* flush output buffer, with TCP FIN */
+      }
+    }
+
   if (sx->peer_offered & OPTION_CHUNKING && sx->cmd_count > 1)
     {
     /* Reap any outstanding MAIL & RCPT commands, but not a DATA-go-ahead */
@@ -4069,7 +4164,8 @@ if (!sx->ok)
     {
     save_errno = errno;
     message = NULL;
-    sx->send_quit = check_response(host, &save_errno, addrlist->more_errno,
+    /* Clear send_quit flag if needed.  Do not set. */
+    sx->send_quit &= check_response(host, &save_errno, addrlist->more_errno,
       sx->buffer, &code, &message, &pass_message);
     goto FAILED;
     }
@@ -4230,13 +4326,12 @@ DEBUG(D_transport)


 if (sx->completed_addr && sx->ok && sx->send_quit)
   {
-  smtp_compare_t t_compare;
-
-  t_compare.tblock = tblock;
-  t_compare.current_sender_address = sender_address;
+  smtp_compare_t t_compare =
+    {.tblock = tblock, .current_sender_address = sender_address};


   if (  sx->first_addr            /* more addrs for this message */
-     || f.continue_more            /* more addrs for coninued-host */
+     || f.continue_more            /* more addrs for continued-host */
+     || tcw_done && tcw            /* more messages for host */
      || (
 #ifndef DISABLE_TLS
        (  tls_out.active.sock < 0  &&  !continue_proxy_cipher
@@ -4281,7 +4376,6 @@ if (sx->completed_addr && sx->ok && sx->send_quit)
 #endif
       int socket_fd = sx->cctx.sock;


-
       if (sx->first_addr)        /* More addresses still to be sent */
         {                /*   for this message              */
         continue_sequence++;        /* Causes * in logging */
@@ -4306,6 +4400,7 @@ if (sx->completed_addr && sx->ok && sx->send_quit)
       the socket on. */


       tls_close(sx->cctx.tls_ctx, TLS_SHUTDOWN_WAIT);
+      sx->send_tlsclose = FALSE;
       sx->cctx.tls_ctx = NULL;
       tls_out.active.sock = -1;
       smtp_peer_options = smtp_peer_options_wrap;
@@ -4399,20 +4494,21 @@ been passed to another process. */


 SEND_QUIT:
 if (sx->send_quit)
-            /* Use _MORE to get QUIT in FIN segment */
+  {            /* Use _MORE to get QUIT in FIN segment */
   (void)smtp_write_command(sx, SCMD_MORE, "QUIT\r\n");
-
-END_OFF:
-
 #ifndef DISABLE_TLS
-# ifdef EXIM_TCP_CORK
-if (sx->cctx.tls_ctx)    /* Use _CORK to get TLS Close Notify in FIN segment */
-  (void) setsockopt(sx->cctx.sock, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
+  if (sx->cctx.tls_ctx)
+    {
+# ifdef EXIM_TCP_CORK    /* Use _CORK to get TLS Close Notify in FIN segment */
+    (void) setsockopt(sx->cctx.sock, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
 # endif
-
-tls_close(sx->cctx.tls_ctx, TLS_SHUTDOWN_NOWAIT);
-sx->cctx.tls_ctx = NULL;
+    tls_shutdown_wr(sx->cctx.tls_ctx);
+    sx->send_tlsclose = FALSE;
+    }
 #endif
+  }
+
+END_OFF:


/* Close the socket, and return the appropriate value, first setting
works because the NULL setting is passed back to the calling process, and
@@ -4424,26 +4520,58 @@ writing RSET might have failed, or there may be other addresses whose hosts are
specified in the transports, and therefore not visible at top level, in which
case continue_more won't get set. */

-HDEBUG(D_transport|D_acl|D_v) debug_printf_indent(" SMTP(close)>>\n");
if (sx->send_quit)
{
/* This flushes data queued in the socket, being the QUIT and any TLS Close,
sending them along with the client FIN flag. Us (we hope) sending FIN first
means we (client) take the TIME_WAIT state, so the server (which likely has a
- higher connection rate) does no have to. */
+ higher connection rate) does not have to. */

+ HDEBUG(D_transport|D_acl|D_v) debug_printf_indent(" SMTP(shutdown)>>\n");
shutdown(sx->cctx.sock, SHUT_WR);
+ }

+if (sx->send_quit || tcw_done && !tcw)
+ {
/* Wait for (we hope) ack of our QUIT, and a server FIN. Discard any data
received, then discard the socket. Any packet received after then, or receive
data still in the socket, will get a RST - hence the pause/drain. */

+  /* Reap the response to QUIT, timing out after one second */
+  (void) smtp_read_response(sx, sx->buffer, sizeof(sx->buffer), '2', 1);
+#ifndef DISABLE_TLS
+  if (sx->cctx.tls_ctx)
+    {
+    int n;
+
+    /* Reap the TLS Close Notify from the server, timing out after one second */
+    sigalrm_seen = FALSE;
+    ALARM(1);
+    do
+      n = tls_read(sx->cctx.tls_ctx, sx->inbuffer, sizeof(sx->inbuffer));
+    while (!sigalrm_seen && n > 0);
+    ALARM_CLR(0);
+
+# ifdef EXIM_TCP_CORK
+    (void) setsockopt(sx->cctx.sock, IPPROTO_TCP, EXIM_TCP_CORK, US &on, sizeof(on));
+# endif
+    tls_close(sx->cctx.tls_ctx, TLS_SHUTDOWN_WAIT);
+    sx->cctx.tls_ctx = NULL;
+    }
+#endif
   millisleep(20);
-  testharness_pause_ms(200);
   if (fcntl(sx->cctx.sock, F_SETFL, O_NONBLOCK) == 0)
-    for (int i = 16; read(sx->cctx.sock, sx->inbuffer, sizeof(sx->inbuffer)) > 0 && i > 0;)
-      i--;                /* drain socket */
+    for (int i = 16, n;                        /* drain socket */
+     (n = read(sx->cctx.sock, sx->inbuffer, sizeof(sx->inbuffer))) > 0 && i > 0;
+     i--) HDEBUG(D_transport|D_acl|D_v)
+      {
+      int m = MIN(n, 64);
+      debug_printf_indent("  SMTP(drain %d bytes)<< %.*s\n", n, m, sx->inbuffer);
+      for (m = 0; m < n; m++)
+    debug_printf("0x%02x\n", sx->inbuffer[m]);
+      }
   }
+HDEBUG(D_transport|D_acl|D_v) debug_printf_indent("  SMTP(close)>>\n");
 (void)close(sx->cctx.sock);


#ifndef DISABLE_EVENT
diff --git a/src/src/transports/smtp.h b/src/src/transports/smtp.h
index d55dc59..1ea2a4d 100644
--- a/src/src/transports/smtp.h
+++ b/src/src/transports/smtp.h
@@ -174,6 +174,7 @@ typedef struct {
BOOL completed_addr:1;
BOOL send_rset:1;
BOOL send_quit:1;
+ BOOL send_tlsclose:1;

   int        max_rcpt;
   int        cmd_count;
diff --git a/test/confs/0623 b/test/confs/0623
new file mode 100644
index 0000000..3805c51
--- /dev/null
+++ b/test/confs/0623
@@ -0,0 +1,43 @@
+# Exim test configuration 0623
+
+SERVER=
+
+.include DIR/aux-var/std_conf_prefix
+
+primary_hostname = myhost.test.ex
+log_selector = +pipelining +received_recipients +smtp_connection
+
+
+# ----- Main settings -----
+
+acl_smtp_rcpt = accept
+
+# ----- Routers -----
+
+begin routers
+
+client:
+  driver =    accept
+  transport =    send_to_server
+  errors_to =    ""
+
+
+# ----- Transports -----
+
+begin transports
+
+send_to_server:
+  driver = smtp
+  allow_localhost
+  hosts = 127.0.0.1
+  port = PORT_D
+
+# ----- Retry -----
+
+
+begin retry
+
+* * F,5d,10s
+
+
+# End
diff --git a/test/confs/0900 b/test/confs/0900
index ffce9e8..2409f39 100644
--- a/test/confs/0900
+++ b/test/confs/0900
@@ -6,6 +6,7 @@ ALLOW=


exim_path = EXIM_PATH
keep_environment =
+add_environment = SSLKEYLOGFILE=DIR/spool/sslkeys
host_lookup_order = bydns
spool_directory = DIR/spool
log_file_path = DIR/spool/log/SERVER%slog
@@ -37,9 +38,9 @@ queue_only
smtp_receive_timeout = 2s

.ifdef _HAVE_DKIM
-log_selector = +received_recipients +dkim_verbose
+log_selector = +received_recipients +millisec +dkim_verbose
.else
-log_selector = +received_recipients
+log_selector = +received_recipients +millisec
.endif

 .ifdef _OPT_MAIN_TLS_CERTIFICATE
diff --git a/test/confs/0911 b/test/confs/0911
new file mode 100644
index 0000000..4c9444c
--- /dev/null
+++ b/test/confs/0911
@@ -0,0 +1,43 @@
+# Exim test configuration 0623
+
+SERVER=
+
+.include DIR/aux-var/std_conf_prefix
+
+primary_hostname = myhost.test.ex
+log_selector = +pipelining +received_recipients +smtp_connection +millisec
+
+
+# ----- Main settings -----
+
+acl_smtp_rcpt = accept
+
+# ----- Routers -----
+
+begin routers
+
+client:
+  driver =    accept
+  transport =    send_to_server
+  errors_to =    ""
+
+
+# ----- Transports -----
+
+begin transports
+
+send_to_server:
+  driver = smtp
+  allow_localhost
+  hosts = 127.0.0.1
+  port = PORT_D
+
+# ----- Retry -----
+
+
+begin retry
+
+* * F,5d,10s
+
+
+# End
diff --git a/test/log/0623 b/test/log/0623
new file mode 100644
index 0000000..8c54aee
--- /dev/null
+++ b/test/log/0623
@@ -0,0 +1,20 @@
+1999-03-02 09:44:33 10HmaX-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for good@???
+1999-03-02 09:44:33 10HmaX-0005vi-00 => good@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] L C="250 OK message data"
+1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
+1999-03-02 09:44:33 10HmaY-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for nopipe@???
+1999-03-02 09:44:33 10HmaY-0005vi-00 => nopipe@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] C="250 OK message data"
+1999-03-02 09:44:33 10HmaY-0005vi-00 Completed
+1999-03-02 09:44:33 10HmaZ-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for tempreject@???
+1999-03-02 09:44:33 10HmaZ-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 451 Service not available
+1999-03-02 09:44:33 10HmaZ-0005vi-00 == tempreject@??? R=client T=send_to_server defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 451 Service not available
+1999-03-02 09:44:33 10HmaZ-0005vi-00 removed by CALLER
+1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
+1999-03-02 09:44:33 10HmbA-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for permreject@???
+1999-03-02 09:44:33 10HmbA-0005vi-00 ** permreject@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 550 content rejected
+1999-03-02 09:44:33 10HmbA-0005vi-00 permreject@???: error ignored
+1999-03-02 09:44:33 10HmbA-0005vi-00 Completed
+1999-03-02 09:44:33 10HmbB-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for permreject@???
+1999-03-02 09:44:33 10HmbB-0005vi-00 H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to end of data
+1999-03-02 09:44:33 10HmbB-0005vi-00 == permreject@??? R=client T=send_to_server defer (-18) H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to end of data
+1999-03-02 09:44:33 10HmbB-0005vi-00 removed by CALLER
+1999-03-02 09:44:33 10HmbB-0005vi-00 Completed
diff --git a/test/log/0900 b/test/log/0900
index 305aa94..a6e1063 100644
--- a/test/log/0900
+++ b/test/log/0900
@@ -1,12 +1,12 @@


******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
-1999-03-02 09:44:33 10HmaZ-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
-1999-03-02 09:44:33 10HmbA-0005vi-00 SMTP data timeout (message abandoned) on connection from (tester) [127.0.0.1] F=<someone@???>
-1999-03-02 09:44:33 SMTP connection from (tester) [127.0.0.1] lost while reading message data
-1999-03-02 09:44:33 SMTP connection from (tester) [127.0.0.1] lost while reading message data
-1999-03-02 09:44:33 10HmbB-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
-1999-03-02 09:44:33 H=(tester) [127.0.0.1] F=<someone@???> rejected RCPT <dummy@???>: relay not permitted
-1999-03-02 09:44:33 rejected from <someone@???> H=(tester) [127.0.0.1]: Non-CRLF-terminated header, under CHUNKING: message abandoned
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 SMTP data timeout (message abandoned) on connection from (tester) [127.0.0.1] F=<someone@???>
+2017-07-30 18:51:05.712 SMTP connection from (tester) [127.0.0.1] lost while reading message data
+2017-07-30 18:51:05.712 SMTP connection from (tester) [127.0.0.1] lost while reading message data
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp K S=sss for CALLER@???
+2017-07-30 18:51:05.712 H=(tester) [127.0.0.1] F=<someone@???> rejected RCPT <dummy@???>: relay not permitted
+2017-07-30 18:51:05.712 rejected from <someone@???> H=(tester) [127.0.0.1]: Non-CRLF-terminated header, under CHUNKING: message abandoned
diff --git a/test/log/0904 b/test/log/0904
index 0ca8720..55f85d3 100644
--- a/test/log/0904
+++ b/test/log/0904
@@ -1,47 +1,44 @@
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for a@???
-1999-03-02 09:44:33 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK"
-1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for b@???
-1999-03-02 09:44:33 10HmaY-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP timeout after end of data (ddd bytes written): Connection timed out
-1999-03-02 09:44:33 10HmaY-0005vi-00 == b@??? R=to_server T=remote_smtp defer (dd): Connection timed out H=127.0.0.1 [127.0.0.1]: SMTP timeout after end of data (ddd bytes written)
-1999-03-02 09:44:33 10HmaZ-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for c@???
-1999-03-02 09:44:33 10HmaZ-0005vi-00 => c@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK"
-1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbA-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for d@???
-1999-03-02 09:44:33 10HmbA-0005vi-00 ** d@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 500 oops
-1999-03-02 09:44:33 10HmbA-0005vi-00 d@???: error ignored
-1999-03-02 09:44:33 10HmbA-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbB-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for e@???
-1999-03-02 09:44:33 10HmbB-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 400 not right now
-1999-03-02 09:44:33 10HmbB-0005vi-00 == e@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 400 not right now
-1999-03-02 09:44:33 10HmbC-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for ebad@???
-1999-03-02 09:44:33 10HmbC-0005vi-00 ** ebad@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<ebad@???>: 550 sorry, no
-1999-03-02 09:44:33 10HmbC-0005vi-00 ebad@???: error ignored
-1999-03-02 09:44:33 10HmbC-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbD-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for p@???
-1999-03-02 09:44:33 10HmbD-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmbD-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbE-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for q@???
-1999-03-02 09:44:33 10HmbE-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP timeout after pipelined end of data (ddd bytes written): Connection timed out
-1999-03-02 09:44:33 10HmbE-0005vi-00 == q@??? R=to_server T=remote_smtp defer (dd): Connection timed out H=127.0.0.1 [127.0.0.1]: SMTP timeout after pipelined end of data (ddd bytes written)
-1999-03-02 09:44:33 10HmbF-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for r@???
-1999-03-02 09:44:33 10HmbF-0005vi-00 => r@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmbF-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbG-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for s@???
-1999-03-02 09:44:33 10HmbG-0005vi-00 ** s@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 550 unacceptable mail-from
-1999-03-02 09:44:33 10HmbG-0005vi-00 s@???: error ignored
-1999-03-02 09:44:33 10HmbG-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbH-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for s1@???
-1999-03-02 09:44:33 10HmbH-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 450 greylisted mail-from
-1999-03-02 09:44:33 10HmbH-0005vi-00 == s1@??? R=to_server T=remote_smtp defer (-45) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 450 greylisted mail-from
-1999-03-02 09:44:33 10HmbI-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for t@???
-1999-03-02 09:44:33 10HmbI-0005vi-00 ** t@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t@???>: 550 no such recipient
-1999-03-02 09:44:33 10HmbI-0005vi-00 t@???: error ignored
-1999-03-02 09:44:33 10HmbI-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbJ-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for u@???
-1999-03-02 09:44:33 10HmbJ-0005vi-00 ** u@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 500 oops bdat
-1999-03-02 09:44:33 10HmbJ-0005vi-00 u@???: error ignored
-1999-03-02 09:44:33 10HmbJ-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbK-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for v@???
-1999-03-02 09:44:33 10HmbK-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 400 not right now bdat
-1999-03-02 09:44:33 10HmbK-0005vi-00 == v@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 400 not right now bdat
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for a@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for b@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP timeout after end of data (ddd bytes written): Connection timed out
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 == b@??? R=to_server T=remote_smtp defer (dd): Connection timed out H=127.0.0.1 [127.0.0.1]: SMTP timeout after end of data (ddd bytes written)
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for c@???
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 => c@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK"
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for d@???
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 ** d@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 500 oops
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 d@???: error ignored
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for e@???
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 400 not right now
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 == e@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 400 not right now
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for ebad@???
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 ** ebad@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<ebad@???>: 550 sorry, no
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 ebad@???: error ignored
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for p@???
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for r@???
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 => r@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for s@???
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 ** s@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 550 unacceptable mail-from
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 s@???: error ignored
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for s1@???
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 450 greylisted mail-from
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 == s1@??? R=to_server T=remote_smtp defer (-45) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 450 greylisted mail-from
+2017-07-30 18:51:05.712 10HmbH-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for t@???
+2017-07-30 18:51:05.712 10HmbH-0005vi-00 ** t@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t@???>: 550 no such recipient
+2017-07-30 18:51:05.712 10HmbH-0005vi-00 t@???: error ignored
+2017-07-30 18:51:05.712 10HmbH-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbI-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for u@???
+2017-07-30 18:51:05.712 10HmbI-0005vi-00 ** u@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 500 oops bdat
+2017-07-30 18:51:05.712 10HmbI-0005vi-00 u@???: error ignored
+2017-07-30 18:51:05.712 10HmbI-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbJ-0005vi-00 <= sender@??? U=root P=local-bsmtp S=sss for v@???
+2017-07-30 18:51:05.712 10HmbJ-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 400 not right now bdat
+2017-07-30 18:51:05.712 10HmbJ-0005vi-00 == v@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 400 not right now bdat
diff --git a/test/log/0905 b/test/log/0905
index 626b00b..245c71a 100644
--- a/test/log/0905
+++ b/test/log/0905
@@ -1,37 +1,37 @@
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for a@???
-1999-03-02 09:44:33 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for d@???
-1999-03-02 09:44:33 10HmaY-0005vi-00 ** d@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after sending data block: 500 oops bdat-nonlast
-1999-03-02 09:44:33 10HmaY-0005vi-00 d@???: error ignored
-1999-03-02 09:44:33 10HmaY-0005vi-00 Completed
-1999-03-02 09:44:33 10HmaZ-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for p@???
-1999-03-02 09:44:33 10HmaZ-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbA-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for s@???
-1999-03-02 09:44:33 10HmbA-0005vi-00 ** s@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 550 unacceptable mail-from
-1999-03-02 09:44:33 10HmbA-0005vi-00 s@???: error ignored
-1999-03-02 09:44:33 10HmbA-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbB-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for t@???
-1999-03-02 09:44:33 10HmbB-0005vi-00 ** t@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t@???>: 550 no such recipient
-1999-03-02 09:44:33 10HmbB-0005vi-00 t@???: error ignored
-1999-03-02 09:44:33 10HmbB-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbC-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for t1@??? t2@???
-1999-03-02 09:44:33 10HmbC-0005vi-00 ** t1@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t1@???>: 550 no such recipient
-1999-03-02 09:44:33 10HmbC-0005vi-00 => t2@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmbC-0005vi-00 t1@???: error ignored
-1999-03-02 09:44:33 10HmbC-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbD-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for u@???
-1999-03-02 09:44:33 10HmbD-0005vi-00 ** u@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 500 oops nonlast bdat
-1999-03-02 09:44:33 10HmbD-0005vi-00 u@???: error ignored
-1999-03-02 09:44:33 10HmbD-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbE-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for v@???
-1999-03-02 09:44:33 10HmbE-0005vi-00 ** v@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 500 oops bdat
-1999-03-02 09:44:33 10HmbE-0005vi-00 v@???: error ignored
-1999-03-02 09:44:33 10HmbE-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbF-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for u@???
-1999-03-02 09:44:33 10HmbF-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 400 oops nonlast bdat
-1999-03-02 09:44:33 10HmbF-0005vi-00 == u@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 400 oops nonlast bdat
-1999-03-02 09:44:33 10HmbG-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for p@???
-1999-03-02 09:44:33 10HmbG-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
-1999-03-02 09:44:33 10HmbG-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for a@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for d@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 ** d@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after sending data block: 500 oops bdat-nonlast
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 d@???: error ignored
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for p@???
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for s@???
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 ** s@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 550 unacceptable mail-from
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 s@???: error ignored
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for t@???
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 ** t@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t@???>: 550 no such recipient
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 t@???: error ignored
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for t1@??? t2@???
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 ** t1@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after RCPT TO:<t1@???>: 550 no such recipient
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 => t2@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 t1@???: error ignored
+2017-07-30 18:51:05.712 10HmbC-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for u@???
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 ** u@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 500 oops nonlast bdat
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 u@???: error ignored
+2017-07-30 18:51:05.712 10HmbD-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for v@???
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 ** v@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 500 oops bdat
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 v@???: error ignored
+2017-07-30 18:51:05.712 10HmbE-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for u@???
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 400 oops nonlast bdat
+2017-07-30 18:51:05.712 10HmbF-0005vi-00 == u@??? R=to_server T=remote_smtp defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined sending data block: 400 oops nonlast bdat
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for p@???
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 => p@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] K C="250 OK bdat"
+2017-07-30 18:51:05.712 10HmbG-0005vi-00 Completed
diff --git a/test/log/0911 b/test/log/0911
new file mode 100644
index 0000000..e4bb5a0
--- /dev/null
+++ b/test/log/0911
@@ -0,0 +1,30 @@
+2017-07-30 18:51:05.712 SMTP connection from root
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= fred@??? U=root P=local-smtp S=sss for good@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => good@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] L K C="250 OK chunked message data"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 SMTP connection from root closed by QUIT
+2017-07-30 18:51:05.712 SMTP connection from root
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= fred@??? U=root P=local-smtp S=sss for nopipe@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 => nopipe@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] K C="250 OK chunked message data"
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 Completed
+2017-07-30 18:51:05.712 SMTP connection from root closed by QUIT
+2017-07-30 18:51:05.712 SMTP connection from root
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 <= fred@??? U=root P=local-smtp S=sss for tempreject@???
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 451 Service not available
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 == tempreject@??? R=client T=send_to_server defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 451 Service not available
+2017-07-30 18:51:05.712 SMTP connection from root closed by QUIT
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 removed by CALLER
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 Completed
+2017-07-30 18:51:05.712 SMTP connection from root
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 <= fred@??? U=root P=local-smtp S=sss for permreject@???
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 ** permreject@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 550 content rejected
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 permreject@???: error ignored
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 Completed
+2017-07-30 18:51:05.712 SMTP connection from root closed by QUIT
+2017-07-30 18:51:05.712 SMTP connection from root
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 <= fred@??? U=root P=local-smtp S=sss for dataloss@???
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to pipelined end of data
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 == dataloss@??? R=client T=send_to_server defer (-18) H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to pipelined end of data
+2017-07-30 18:51:05.712 SMTP connection from root closed by QUIT
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 removed by CALLER
+2017-07-30 18:51:05.712 10HmbB-0005vi-00 Completed
diff --git a/test/log/1114 b/test/log/1114
index f3e5e78..649e2e9 100644
--- a/test/log/1114
+++ b/test/log/1114
@@ -1,5 +1,5 @@

******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= someone@??? H=(rhu.barb) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss for CALLER@???
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= someone@??? H=(rhu.barb) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss for CALLER@???
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= someone@??? H=(rhu.barb) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss for CALLER@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= someone@??? H=(rhu.barb) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss for CALLER@???
diff --git a/test/log/1157 b/test/log/1157
index 7c8e6e8..065ea89 100644
--- a/test/log/1157
+++ b/test/log/1157
@@ -20,15 +20,15 @@
1999-03-02 09:44:33 10HmbE-0005vi-00 => userb@??? R=cl_override T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no C="250 OK id=10HmbI-0005vi-00"
1999-03-02 09:44:33 10HmbE-0005vi-00 Completed
1999-03-02 09:44:33 End queue run: pid=pppp -qqf
-1999-03-02 09:44:33 10HmbJ-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for userx@???
-1999-03-02 09:44:33 10HmbK-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for usery@???
-1999-03-02 09:44:33 10HmbL-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for userz@???
+1999-03-02 09:44:33 10HmbJ-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for user_p@???
+1999-03-02 09:44:33 10HmbK-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for user_q@???
+1999-03-02 09:44:33 10HmbL-0005vi-00 <= CALLER@??? U=CALLER P=local S=sss for user_r@???
1999-03-02 09:44:33 Start queue run: pid=pppp -qqf
-1999-03-02 09:44:33 10HmbJ-0005vi-00 => userx@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbM-0005vi-00"
+1999-03-02 09:44:33 10HmbJ-0005vi-00 => user_p@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbM-0005vi-00"
1999-03-02 09:44:33 10HmbJ-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbL-0005vi-00 => userz@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbN-0005vi-00"
+1999-03-02 09:44:33 10HmbL-0005vi-00 => user_r@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbN-0005vi-00"
1999-03-02 09:44:33 10HmbL-0005vi-00 Completed
-1999-03-02 09:44:33 10HmbK-0005vi-00 => usery@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbO-0005vi-00"
+1999-03-02 09:44:33 10HmbK-0005vi-00 => user_q@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbO-0005vi-00"
1999-03-02 09:44:33 10HmbK-0005vi-00 Completed
1999-03-02 09:44:33 End queue run: pid=pppp -qqf

@@ -63,7 +63,7 @@
1999-03-02 09:44:33 End queue run: pid=pppp -qf
1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
1999-03-02 09:44:33 SMTP connection from [127.0.0.1]:1113 (TCP/IP connection count = 1)
-1999-03-02 09:44:33 10HmbM-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbJ-0005vi-00@??? for userx@???
-1999-03-02 09:44:33 10HmbN-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbL-0005vi-00@??? for userz@???
-1999-03-02 09:44:33 10HmbO-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbK-0005vi-00@??? for usery@???
+1999-03-02 09:44:33 10HmbM-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbJ-0005vi-00@??? for user_p@???
+1999-03-02 09:44:33 10HmbN-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbL-0005vi-00@??? for user_r@???
+1999-03-02 09:44:33 10HmbO-0005vi-00 <= CALLER@??? H=localhost (myhost.test.ex) [127.0.0.1]:1113 P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no S=sss id=E10HmbK-0005vi-00@??? for user_q@???
1999-03-02 09:44:33 SMTP connection from localhost (myhost.test.ex) [127.0.0.1]:1113 closed by QUIT
diff --git a/test/log/1165 b/test/log/1165
index e35fd54..54193cd 100644
--- a/test/log/1165
+++ b/test/log/1165
@@ -1,7 +1,7 @@
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= this-user@??? U=this-user P=local S=sss for other-user@???
-1999-03-02 09:44:33 10HmaX-0005vi-00 => other-user@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes K C="250- 3nn byte chunk, total 3nn\\n250 OK id=10HmaY-0005vi-00"
-1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= this-user@??? U=this-user P=local S=sss for other-user@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => other-user@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes K C="250- 3nn byte chunk, total 3nn\\n250 OK id=10HmaY-0005vi-00"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed

******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss id=E10HmaX-0005vi-00@??? for other-user@???
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtps X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no K S=sss id=E10HmaX-0005vi-00@??? for other-user@???
diff --git a/test/log/4521 b/test/log/4521
index 61c5bdb..8849068 100644
--- a/test/log/4521
+++ b/test/log/4521
@@ -1,13 +1,13 @@
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= sender@??? U=sender P=local S=sss for a@???
-1999-03-02 09:44:33 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp_dkim H=127.0.0.1 [127.0.0.1] K C="250- 6nn byte chunk, total 6nn\\n250 OK id=10HmaY-0005vi-00"
-1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
-1999-03-02 09:44:33 10HmaZ-0005vi-00 <= sender@??? U=sender P=local S=sss for b@???
-1999-03-02 09:44:33 10HmaZ-0005vi-00 => b@??? R=to_server T=remote_smtp_dkim H=127.0.0.1 [127.0.0.1] K C="250- 8nn byte chunk, total 8nn\\n250 OK id=10HmbA-0005vi-00"
-1999-03-02 09:44:33 10HmaZ-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= sender@??? U=sender P=local S=sss for a@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => a@??? R=to_server T=remote_smtp_dkim H=127.0.0.1 [127.0.0.1] K C="250- 6nn byte chunk, total 6nn\\n250 OK id=10HmaY-0005vi-00"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 <= sender@??? U=sender P=local S=sss for b@???
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 => b@??? R=to_server T=remote_smtp_dkim H=127.0.0.1 [127.0.0.1] K C="250- 8nn byte chunk, total 8nn\\n250 OK id=10HmbA-0005vi-00"
+2017-07-30 18:51:05.712 10HmaZ-0005vi-00 Completed

******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
-1999-03-02 09:44:33 10HmaY-0005vi-00 DKIM: d=test.ex s=sel c=relaxed/relaxed a=rsa-sha256 b=1024 [verification succeeded]
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=E10HmaX-0005vi-00@??? for a@???
-1999-03-02 09:44:33 10HmbA-0005vi-00 DKIM: d=test.ex s=sel c=relaxed/relaxed a=rsa-sha256 b=1024 [verification succeeded]
-1999-03-02 09:44:33 10HmbA-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=E10HmaZ-0005vi-00@??? for b@???
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 DKIM: d=test.ex s=sel c=relaxed/relaxed a=rsa-sha256 b=1024 [verification succeeded]
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=E10HmaX-0005vi-00@??? for a@???
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 DKIM: d=test.ex s=sel c=relaxed/relaxed a=rsa-sha256 b=1024 [verification succeeded]
+2017-07-30 18:51:05.712 10HmbA-0005vi-00 <= <> H=localhost (testhost.test.ex) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=E10HmaZ-0005vi-00@??? for b@???
diff --git a/test/log/4522 b/test/log/4522
index 25a8749..7abd59e 100644
--- a/test/log/4522
+++ b/test/log/4522
@@ -1,7 +1,7 @@

******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
-1999-03-02 09:44:33 10HmaX-0005vi-00 DKIM: d=test.ex s=sel c=simple/simple a=rsa-sha256 b=1024 [verification succeeded]
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= CALLER@??? H=(xxx) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=qwerty1234@??? for a@???
-1999-03-02 09:44:33 10HmaY-0005vi-00 DKIM: d=test.ex s=sel c=simple/simple a=rsa-sha256 b=1024 [verification succeeded]
-1999-03-02 09:44:33 10HmaY-0005vi-00 <= CALLER@??? H=(xxx) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=qwerty1234@??? for a@???
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_S
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 DKIM: d=test.ex s=sel c=simple/simple a=rsa-sha256 b=1024 [verification succeeded]
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= CALLER@??? H=(xxx) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=qwerty1234@??? for a@???
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 DKIM: d=test.ex s=sel c=simple/simple a=rsa-sha256 b=1024 [verification succeeded]
+2017-07-30 18:51:05.712 10HmaY-0005vi-00 <= CALLER@??? H=(xxx) [127.0.0.1] P=esmtp K S=sss DKIM=test.ex id=qwerty1234@??? for a@???
diff --git a/test/log/5590 b/test/log/5590
index f872b82..def35fb 100644
--- a/test/log/5590
+++ b/test/log/5590
@@ -1,7 +1,7 @@

******** SERVER ********
-1999-03-02 09:44:33 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
-1999-03-02 09:44:33 10HmaX-0005vi-00 PRDR R=<bad1@???> refusal
-1999-03-02 09:44:33 10HmaX-0005vi-00 PRDR R=<good@???> acceptance
-1999-03-02 09:44:33 10HmaX-0005vi-00 PRDR R=<bad2@???> refusal
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp PRDR K S=sss for bad1@??? good@??? bad2@???
+2017-07-30 18:51:05.712 exim x.yz daemon started: pid=pppp, no queue runs, listening for SMTP on port PORT_D
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 PRDR R=<bad1@???> refusal
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 PRDR R=<good@???> acceptance
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 PRDR R=<bad2@???> refusal
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= someone@??? H=(tester) [127.0.0.1] P=esmtp PRDR K S=sss for bad1@??? good@??? bad2@???
diff --git a/test/log/5591 b/test/log/5591
index f5dd653..6585a5e 100644
--- a/test/log/5591
+++ b/test/log/5591
@@ -1,4 +1,4 @@
-1999-03-02 09:44:33 10HmaX-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for usery@??? userz@???
-1999-03-02 09:44:33 10HmaX-0005vi-00 => usery@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] PRDR K C="250 first rcpt was good\\n250 OK, overall"
-1999-03-02 09:44:33 10HmaX-0005vi-00 -> userz@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] PRDR K C="250 second rcpt was good\\n250 OK, overall"
-1999-03-02 09:44:33 10HmaX-0005vi-00 Completed
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 <= sender@dom U=root P=local-bsmtp S=sss for usery@??? userz@???
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 => usery@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] PRDR K C="250 first rcpt was good\\n250 OK, overall"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 -> userz@??? R=to_server T=remote_smtp H=127.0.0.1 [127.0.0.1] PRDR K C="250 second rcpt was good\\n250 OK, overall"
+2017-07-30 18:51:05.712 10HmaX-0005vi-00 Completed
diff --git a/test/rejectlog/0900 b/test/rejectlog/0900
index e5eb296..5e1c037 100644
--- a/test/rejectlog/0900
+++ b/test/rejectlog/0900
@@ -1,7 +1,7 @@

 ******** SERVER ********
-1999-03-02 09:44:33 H=(tester) [127.0.0.1] F=<someone@???> rejected RCPT <dummy@???>: relay not permitted
-1999-03-02 09:44:33 rejected from <someone@???> H=(tester) [127.0.0.1]: Non-CRLF-terminated header, under CHUNKING: message abandoned
+2017-07-30 18:51:05.712 H=(tester) [127.0.0.1] F=<someone@???> rejected RCPT <dummy@???>: relay not permitted
+2017-07-30 18:51:05.712 rejected from <someone@???> H=(tester) [127.0.0.1]: Non-CRLF-terminated header, under CHUNKING: message abandoned
 Envelope-from: <someone@???>
 Envelope-to: <CALLER@???>
   To: Susan@???
diff --git a/test/runtest b/test/runtest
index ed01ba7..2295810 100755
--- a/test/runtest
+++ b/test/runtest
@@ -1152,6 +1152,8 @@ RESET_AFTER_EXTRA_LINE_READ:
     # drop pdkim debugging header
     next if /^DKIM( <<<<<<<<<<<<<<<<<<<<<<<<<<<<<+|: no signatures)$/;


+    # Some platforms have TIOCOUTome do not
+    next if /\d+ bytes remain in socket output buffer$/;
     # Various other IPv6 lines must be omitted too


     next if /using host_fake_gethostbyname for \S+ \(IPv6\)/;
diff --git a/test/scripts/0000-Basic/0623 b/test/scripts/0000-Basic/0623
new file mode 100644
index 0000000..315bc49
--- /dev/null
+++ b/test/scripts/0000-Basic/0623
@@ -0,0 +1,114 @@
+# PIPELINING of QUIT
+need_ipv4
+#
+# Baseline: no error.  Check the QUIT arrived befre we ack message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+DATA
+300 go ahead
+.
+QUIT
+250 OK message data
+221 Closing connection
+****
+exim -odi good@???
+****
+#
+# QUIT-pipeliining should not be done when PIPELINING not advertised
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+DATA
+300 go ahead
+.
+250 OK message data
+*sleep 1
+<<
+QUIT
+221 Closing connection
+****
+exim -odi nopipe@???
+****
+#
+# Temp-error response to message-data
+# Check specifically for a close, and no repeated command
+# Also check Exim's list of commands sent
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+DATA
+300 go ahead
+.
+QUIT
+451 Service not available
+221 Closing connection
+*eof
+****
+exim -d-all+transport -odi tempreject@???
+****
+exim -Mrm $msg1
+****
+#
+# Perm-error response to message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+DATA
+300 go ahead
+.
+QUIT
+550 content rejected
+221 Closing connection
+*eof
+****
+exim -d-all+transport -odi permreject@???
+****
+#
+# Channel-close response to message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+DATA
+300 go ahead
+.
+>*eof
+****
+exim -d-all+transport -odi permreject@???
+****
+exim -Mrm $msg1
+****
diff --git a/test/scripts/0000-Basic/0904 b/test/scripts/0000-Basic/0904
index fa72256..9f09a84 100644
--- a/test/scripts/0000-Basic/0904
+++ b/test/scripts/0000-Basic/0904
@@ -206,29 +206,34 @@ QUIT
 ****
 #
 # Error case: server wrongly expected more data, client gets timeout for data-ack
-server PORT_S
-220 Greetings
-EHLO
-250-Hello there
-250-PIPELINING
-250 CHUNKING
-MAIL FROM
-RCPT TO
-BDAT 329 LAST
-*data 330
-250 good mail cmd
-****
-sudo exim -odf -bS
-EHLO test
-MAIL FROM:<sender@???>
-RCPT TO:<q@???>
-DATA
-Subject: foo
-
-data
-.
-QUIT
-****
+# XXX This is a problem with data/quit pipelining.  The succeeding SMTP command cannot
+# be distinguished from the data, by the errroneous server.
+# Of course, we could avoid such pipelining on the client side, when BDAT is used.
+# But - is this any worse than a server failing to spot the data-dot under DATA?
+# I think not; both are culpable, and there is only so much the client can do.
+#server PORT_S
+#220 Greetings
+#EHLO
+#250-Hello there
+#250-PIPELINING
+#250 CHUNKING
+#MAIL FROM
+#RCPT TO
+#BDAT 329 LAST
+#*data 330
+#250 good mail cmd
+#****
+#sudo exim -odf -bS
+#EHLO test
+#MAIL FROM:<sender@???>
+#RCPT TO:<q@???>
+#DATA
+#Subject: foo
+#
+#data
+#.
+#QUIT
+#****
 #
 # Error case: server wrongly expected less data
 # client get the data-ack, sends quit - but server
diff --git a/test/scripts/0000-Basic/0911 b/test/scripts/0000-Basic/0911
new file mode 100644
index 0000000..c697989
--- /dev/null
+++ b/test/scripts/0000-Basic/0911
@@ -0,0 +1,142 @@
+# CHUNKING and PIPELINING of QUIT
+need_ipv4
+#
+# Chunking Baseline: no error.  Check the QUIT arrived befre we ack message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM
+RCPT TO
+BDAT 313 LAST
+250 OK mail
+250 OK rcpt
+*data 313
+QUIT
+250 OK chunked message data
+221 Closing connection
+****
+sudo exim -d-all+transport -odi -bs
+helo tester
+mail from:<fred@???>
+rcpt to:<good@???>
+data
+.
+quit
+****
+#
+# QUIT-pipeliining should not be done when PIPELINING not advertised
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-CHUNKING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+BDAT 315 LAST
+*data 315
+250 OK chunked message data
+QUIT
+221 Closing connection
+****
+sudo exim -d-all+transport -odi -bs
+helo tester
+mail from:<fred@???>
+rcpt to:<nopipe@???>
+data
+.
+quit
+****
+#
+# Temp-error response to message-data
+# Check specifically for a close, and no repeated command
+# Also check Exim's list of commands sent
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+BDAT 319 LAST
+*data 319
+QUIT
+451 Service not available
+221 Closing connection
+*eof
+****
+sudo exim -d-all+transport -odi -bs
+helo tester
+mail from:<fred@???>
+rcpt to:<tempreject@???>
+data
+.
+quit
+****
+exim -Mrm $msg1
+****
+#
+# Perm-error response to message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+BDAT 319 LAST
+*data 319
+QUIT
+550 content rejected
+221 Closing connection
+*eof
+****
+sudo exim -d-all+transport -odi -bs
+helo tester
+mail from:<fred@???>
+rcpt to:<permreject@???>
+data
+.
+quit
+****
+#
+# Channel-close response to message-data
+server PORT_D
+220 Server ready
+EHLO
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM
+250 OK mail
+RCPT TO
+250 OK rcpt
+BDAT 317 LAST
+*data 317
+>*eof
+****
+sudo exim -d-all+transport -odi -bs
+helo tester
+mail from:<fred@???>
+rcpt to:<dataloss@???>
+data
+.
+quit
+****
+exim -Mrm $msg1
+****
diff --git a/test/scripts/1100-Basic-TLS/1157 b/test/scripts/1100-Basic-TLS/1157
index afbc9a6..1a271e2 100644
--- a/test/scripts/1100-Basic-TLS/1157
+++ b/test/scripts/1100-Basic-TLS/1157
@@ -38,13 +38,13 @@ exim -DSERVER=server -DNOTDAEMON -qf
 # no tls proxy (default for test was permitting proxy)
 exim -DSERVER=server -bd -oX PORT_D
 ****
-exim userx@???
+exim user_p@???
 Test message 1
 ****
-exim usery@???
+exim user_q@???
 Test message 2
 ****
-exim userz@???
+exim user_r@???
 Test message 3
 ****
 exim -d-all+acl '-DPEX=*' -qqf
diff --git a/test/stderr/0143 b/test/stderr/0143
index 943af04..02e23a8 100644
--- a/test/stderr/0143
+++ b/test/stderr/0143
@@ -51,6 +51,8 @@ transport_check_waiting entered
 transport_check_waiting: FALSE
   SMTP+> QUIT
 cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 Leaving my_smtp transport
 LOG: MAIN
diff --git a/test/stderr/0217 b/test/stderr/0217
index 827baa5..a1efa5c 100644
--- a/test/stderr/0217
+++ b/test/stderr/0217
@@ -415,6 +415,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
 LOG: MAIN
   H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined DATA: 403 Sorry temp data error
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   == yes@??? R=client T=send_to_server defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined DATA: 403 Sorry temp data error
@@ -850,6 +852,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP>> writing message and terminating "."
   SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP(closed)<<
   SMTP(close)>>
 LOG: MAIN
   => w@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] C="250 OK"
diff --git a/test/stderr/0218 b/test/stderr/0218
index 2ff9c98..c07bd2a 100644
--- a/test/stderr/0218
+++ b/test/stderr/0218
@@ -54,8 +54,10 @@ T: send_to_server  (ACL)
   SMTP<< 250 OK
   SMTP<< 351 Send more
   SMTP>> writing message and terminating "."
-  SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => b@??? F=<CALLER@???> R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* L C="250 OK"
@@ -99,6 +101,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP<< 503 Unexpected RCPT
   SMTP<< 503 Unexpected DATA
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   ** a@??? F=<CALLER@???> R=client T=send_to_server H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined MAIL FROM:<CALLER@???>: 550 NO
@@ -191,8 +195,10 @@ T: send_to_server  (ACL)
   SMTP<< 250 OK
   SMTP<< 351 OK
   SMTP>> writing message and terminating "."
-  SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => c@??? F=<CALLER@???> R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* L C="250 OK"
diff --git a/test/stderr/0276 b/test/stderr/0276
index 5894d75..3519ecf 100644
--- a/test/stderr/0276
+++ b/test/stderr/0276
@@ -14,6 +14,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP<< 250 OK
   SMTP<< 500 NO
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 200 OK
   SMTP(close)>>
 LOG: MAIN
   ** userx@??? R=r1 T=t1 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined DATA: 500 NO
@@ -48,6 +50,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP>> DATA
   SMTP<< 500 NO
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 200 OK
   SMTP(close)>>
 LOG: MAIN
   ** usery@??? R=r1 T=t1 H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after DATA: 500 NO
diff --git a/test/stderr/0388 b/test/stderr/0388
index 4536358..939aba1 100644
--- a/test/stderr/0388
+++ b/test/stderr/0388
@@ -100,12 +100,13 @@ LOG: MAIN
 added retry item for R:x@y: errno=-44 more_errno=dd,A flags=0
   SMTP+> QUIT
 cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 set_process_info: pppp delivering 10HmaX-0005vi-00: just tried 127.0.0.1 [127.0.0.1]:PORT_S for x@y: result OK
 address match test: subject=*@127.0.0.1 pattern=*
 127.0.0.1 in "*"? yes (matched "*")
 *@127.0.0.1 in "*"? yes (matched "*")
-set_process_info: pppp delivering 10HmaX-0005vi-00: waiting for a remote delivery subprocess to finish
 checking status of V4NET.0.0.0
  locking TESTSUITE/spool/db/retry.lockfile
  locked  TESTSUITE/spool/db/retry.lockfile
@@ -120,6 +121,7 @@ LOG: MAIN
   H=V4NET.0.0.0 [V4NET.0.0.0] Network Error
 set_process_info: pppp delivering 10HmaX-0005vi-00: just tried V4NET.0.0.0 [V4NET.0.0.0]:PORT_S for x@y: result DEFER
 added retry item for T:V4NET.0.0.0:V4NET.0.0.0:1224: errno=dd more_errno=dd,A flags=2
+set_process_info: pppp delivering 10HmaX-0005vi-00: waiting for a remote delivery subprocess to finish
 set_process_info: pppp delivering 10HmaX-0005vi-00 (just run smtp for x@y in subprocess)
 search_tidyup called
 reading retry information for T:V4NET.0.0.0:V4NET.0.0.0:1224 from subprocess
diff --git a/test/stderr/0450 b/test/stderr/0450
index 9552e38..b665681 100644
--- a/test/stderr/0450
+++ b/test/stderr/0450
@@ -24,7 +24,7 @@ LOG: MAIN
 added retry item for T:127.0.0.1:127.0.0.1:1225: errno=dd more_errno=dd,A flags=2
 all IP addresses skipped or deferred at least one address
 updating wait-t1 database
-added to list for 127.0.0.1
+added 10HmaX-0005vi-00 to queue for 127.0.0.1
 Leaving t1 transport
 LOG: MAIN
   == userx@??? R=r1 T=t1 defer (dd): Connection refused
diff --git a/test/stderr/0467 b/test/stderr/0467
index 5cc2f0a..54d1e8b 100644
--- a/test/stderr/0467
+++ b/test/stderr/0467
@@ -30,6 +30,8 @@ Connecting to localhost.test.ex [127.0.0.1]:1224 ...  connected
   SMTP>> writing message and terminating "."
   SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => x@??? R=r1 T=t1 H=localhost.test.ex [127.0.0.1]:1224 C="250 OK"
diff --git a/test/stderr/0476 b/test/stderr/0476
index 152bfd8..98baf51 100644
--- a/test/stderr/0476
+++ b/test/stderr/0476
@@ -91,7 +91,7 @@ set_process_info: pppp delivering 10HmaZ-0005vi-00: just tried 127.0.0.1 [127.0.
 added retry item for T:127.0.0.1:127.0.0.1:1224: errno=dd more_errno=dd,A flags=2
 all IP addresses skipped or deferred at least one address
 updating wait-t1 database
-added to list for 127.0.0.1
+added 10HmaZ-0005vi-00 to queue for 127.0.0.1
 Leaving t1 transport
 set_process_info: pppp delivering 10HmaZ-0005vi-00 (just run t1 for CALLER@??? in subprocess)
 set_process_info: pppp delivering 10HmaZ-0005vi-00: waiting for a remote delivery subprocess to finish
@@ -120,7 +120,7 @@ no message retry record
 127.0.0.1 [127.0.0.1]:1111 retry-status = unusable
 all IP addresses skipped or deferred at least one address
 updating wait-t1 database
-added to list for 127.0.0.1
+added 10HmaY-0005vi-00 to queue for 127.0.0.1
 Leaving t1 transport
 set_process_info: pppp delivering 10HmaY-0005vi-00 (just run t1 for usery@??? in subprocess)
 set_process_info: pppp running queue: waiting for 10HmaY-0005vi-00 (pppp)
diff --git a/test/stderr/0623 b/test/stderr/0623
new file mode 100644
index 0000000..8abd7b0
--- /dev/null
+++ b/test/stderr/0623
@@ -0,0 +1,190 @@
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+LOG: MAIN
+  <= CALLER@??? U=CALLER P=local S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> tempreject@??? <--------
+send_to_server transport entered
+  tempreject@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmaZ-0005vi-00 to 127.0.0.1 [127.0.0.1] (tempreject@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250 OK
+using PIPELINING
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<tempreject@???>
+  SMTP>> DATA
+cmd buf flush ddd bytes
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for tempreject@???
+  SMTP<< 250 OK rcpt
+sync_responses expect data
+  SMTP<< 300 go ahead
+  SMTP>> writing message and terminating "."
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 451 Service not available
+LOG: MAIN
+  H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 451 Service not available
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+added retry item for T:127.0.0.1:127.0.0.1:1225:10HmaZ-0005vi-00: errno=-46 more_errno=dd,A flags=6
+all IP addresses skipped or deferred at least one address
+Leaving send_to_server transport
+LOG: MAIN
+  == tempreject@??? R=client T=send_to_server defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 451 Service not available
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+LOG: MAIN
+  <= CALLER@??? U=CALLER P=local S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> permreject@??? <--------
+send_to_server transport entered
+  permreject@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+no host retry record
+no message retry record
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmbA-0005vi-00 to 127.0.0.1 [127.0.0.1] (permreject@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250 OK
+using PIPELINING
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<permreject@???>
+  SMTP>> DATA
+cmd buf flush ddd bytes
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for permreject@???
+  SMTP<< 250 OK rcpt
+sync_responses expect data
+  SMTP<< 300 go ahead
+  SMTP>> writing message and terminating "."
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 550 content rejected
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+Leaving send_to_server transport
+LOG: MAIN
+  ** permreject@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after end of data: 550 content rejected
+LOG: MAIN
+  permreject@???: error ignored
+LOG: MAIN
+  Completed
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+admin user
+LOG: MAIN
+  <= CALLER@??? U=CALLER P=local S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> permreject@??? <--------
+send_to_server transport entered
+  permreject@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+no host retry record
+no message retry record
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmbB-0005vi-00 to 127.0.0.1 [127.0.0.1] (permreject@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250 OK
+using PIPELINING
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<permreject@???>
+  SMTP>> DATA
+cmd buf flush ddd bytes
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for permreject@???
+  SMTP<< 250 OK rcpt
+sync_responses expect data
+  SMTP<< 300 go ahead
+  SMTP>> writing message and terminating "."
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP(closed)<<
+LOG: MAIN
+  H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to end of data
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP(closed)<<
+  SMTP(close)>>
+added retry item for T:127.0.0.1:127.0.0.1:1225:10HmbB-0005vi-00: errno=-18 more_errno=dd,A flags=6
+all IP addresses skipped or deferred at least one address
+Leaving send_to_server transport
+LOG: MAIN
+  == permreject@??? R=client T=send_to_server defer (-18) H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to end of data
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
diff --git a/test/stderr/0911 b/test/stderr/0911
new file mode 100644
index 0000000..6a6645d
--- /dev/null
+++ b/test/stderr/0911
@@ -0,0 +1,335 @@
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from root
+created log directory TESTSUITE/spool/log
+LOG: MAIN
+  <= fred@??? U=root P=local-smtp S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> good@??? <--------
+send_to_server transport entered
+  good@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmaX-0005vi-00 to 127.0.0.1 [127.0.0.1] (good@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250-CHUNKING
+         250 OK
+using PIPELINING
+CHUNKING usable
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<good@???>
+         will write message using CHUNKING
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+  SMTP+> BDAT 313 LAST
+cmd buf flush ddd bytes (more expected)
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for good@???
+  SMTP<< 250 OK rcpt
+  SMTP<< 250 OK chunked message data
+ok=1 send_quit=0 send_rset=0 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+Leaving send_to_server transport
+LOG: MAIN
+  => good@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] L K C="250 OK chunked message data"
+LOG: MAIN
+  Completed
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from root
+LOG: MAIN
+  <= fred@??? U=root P=local-smtp S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> nopipe@??? <--------
+send_to_server transport entered
+  nopipe@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmaY-0005vi-00 to 127.0.0.1 [127.0.0.1] (nopipe@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-CHUNKING
+         250 OK
+not using PIPELINING
+CHUNKING usable
+not using DSN
+  SMTP>> MAIL FROM:<>
+cmd buf flush ddd bytes
+  SMTP<< 250 OK mail
+  SMTP>> RCPT TO:<nopipe@???>
+cmd buf flush ddd bytes
+sync_responses expect rcpt for nopipe@???
+  SMTP<< 250 OK rcpt
+         will write message using CHUNKING
+  SMTP+> BDAT 315 LAST
+cmd buf flush ddd bytes (more expected)
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300
+  SMTP<< 250 OK chunked message data
+ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address is NULL
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+Leaving send_to_server transport
+LOG: MAIN
+  => nopipe@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] K C="250 OK chunked message data"
+LOG: MAIN
+  Completed
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from root
+LOG: MAIN
+  <= fred@??? U=root P=local-smtp S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> tempreject@??? <--------
+send_to_server transport entered
+  tempreject@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmaZ-0005vi-00 to 127.0.0.1 [127.0.0.1] (tempreject@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250-CHUNKING
+         250 OK
+using PIPELINING
+CHUNKING usable
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<tempreject@???>
+         will write message using CHUNKING
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+  SMTP+> BDAT 319 LAST
+cmd buf flush ddd bytes (more expected)
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for tempreject@???
+  SMTP<< 250 OK rcpt
+  SMTP<< 451 Service not available
+LOG: MAIN
+  H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 451 Service not available
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+added retry item for T:127.0.0.1:127.0.0.1:1225:10HmaZ-0005vi-00: errno=-46 more_errno=dd,A flags=6
+all IP addresses skipped or deferred at least one address
+Leaving send_to_server transport
+LOG: MAIN
+  == tempreject@??? R=client T=send_to_server defer (-46) H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 451 Service not available
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from root
+LOG: MAIN
+  <= fred@??? U=root P=local-smtp S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> permreject@??? <--------
+send_to_server transport entered
+  permreject@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+no host retry record
+no message retry record
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmbA-0005vi-00 to 127.0.0.1 [127.0.0.1] (permreject@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250-CHUNKING
+         250 OK
+using PIPELINING
+CHUNKING usable
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<permreject@???>
+         will write message using CHUNKING
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+  SMTP+> BDAT 319 LAST
+cmd buf flush ddd bytes (more expected)
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for permreject@???
+  SMTP<< 250 OK rcpt
+  SMTP<< 550 content rejected
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 221 Closing connection
+  SMTP(close)>>
+Leaving send_to_server transport
+LOG: MAIN
+  ** permreject@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]: SMTP error from remote mail server after pipelined end of data: 550 content rejected
+LOG: MAIN
+  permreject@???: error ignored
+LOG: MAIN
+  Completed
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+LOG: smtp_connection MAIN
+  SMTP connection from root
+LOG: MAIN
+  <= fred@??? U=root P=local-smtp S=sss
+Exim version x.yz ....
+configuration file is TESTSUITE/test-config
+trusted user
+admin user
+dropping to exim gid; retaining priv uid
+>>>>>>>>>>>>>>>> Remote deliveries >>>>>>>>>>>>>>>>
+--------> dataloss@??? <--------
+send_to_server transport entered
+  dataloss@???
+using the transport's hosts: 127.0.0.1
+getting address for 127.0.0.1
+checking status of 127.0.0.1
+no host retry record
+no message retry record
+127.0.0.1 [127.0.0.1]:1111 retry-status = usable
+delivering 10HmbB-0005vi-00 to 127.0.0.1 [127.0.0.1] (dataloss@???)
+Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
+  SMTP<< 220 Server ready
+  SMTP>> EHLO myhost.test.ex
+cmd buf flush ddd bytes
+  SMTP<< 250-hi there
+         250-PIPELINING
+         250-CHUNKING
+         250 OK
+using PIPELINING
+CHUNKING usable
+not using DSN
+  SMTP|> MAIL FROM:<>
+  SMTP|> RCPT TO:<dataloss@???>
+         will write message using CHUNKING
+transport_check_waiting entered
+  sequence=1 local_max=500 global_max=-1
+ no messages waiting for 127.0.0.1
+transport_check_waiting: FALSE
+will pipeline QUIT
+  SMTP+> BDAT 317 LAST
+cmd buf flush ddd bytes (more expected)
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
+  SMTP+> QUIT
+cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+sync_responses expect mail
+  SMTP<< 250 OK mail
+sync_responses expect rcpt for dataloss@???
+  SMTP<< 250 OK rcpt
+  SMTP(closed)<<
+LOG: MAIN
+  H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to pipelined end of data
+ok=0 send_quit=0 send_rset=1 continue_more=0 yield=0 first_address is NULL
+  SMTP(closed)<<
+  SMTP(close)>>
+added retry item for T:127.0.0.1:127.0.0.1:1225:10HmbB-0005vi-00: errno=-18 more_errno=dd,A flags=6
+all IP addresses skipped or deferred at least one address
+Leaving send_to_server transport
+LOG: MAIN
+  == dataloss@??? R=client T=send_to_server defer (-18) H=127.0.0.1 [127.0.0.1]: Remote host closed connection in response to pipelined end of data
+>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>
+LOG: smtp_connection MAIN
+  SMTP connection from root closed by QUIT
+>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>
diff --git a/test/stderr/1150 b/test/stderr/1150
index 03ee03d..9ba4234 100644
--- a/test/stderr/1150
+++ b/test/stderr/1150
@@ -25,8 +25,9 @@ Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
   SMTP<< 250 Accepted
   SMTP<< 354 Enter message, ending with "." on a line by itself
   SMTP>> writing message and terminating "."
+  SMTP>> QUIT
   SMTP<< 250 OK id=10HmaZ-0005vi-00
-  SMTP+> QUIT
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
 LOG: MAIN
   => CALLER@??? R=client T=send_to_server1 H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmaZ-0005vi-00"
@@ -59,8 +60,9 @@ Connecting to 127.0.0.1 [127.0.0.1]:1225 ...  connected
   SMTP<< 250 Accepted
   SMTP<< 354 Enter message, ending with "." on a line by itself
   SMTP>> writing message and terminating "."
+  SMTP>> QUIT
   SMTP<< 250 OK id=10HmbA-0005vi-00
-  SMTP+> QUIT
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
 LOG: MAIN
   => CALLER@??? R=client T=send_to_server1 H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbA-0005vi-00"
@@ -90,8 +92,9 @@ Connecting to ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4]:1225 ...  connected
   SMTP<< 250 Accepted
   SMTP<< 354 Enter message, ending with "." on a line by itself
   SMTP>> writing message and terminating "."
+  SMTP>> QUIT
   SMTP<< 250 OK id=10HmbB-0005vi-00
-  SMTP+> QUIT
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
 LOG: MAIN
   => abcd@??? R=client T=send_to_server2 H=ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbB-0005vi-00"
diff --git a/test/stderr/1157 b/test/stderr/1157
index 321544e..d5274fb 100644
--- a/test/stderr/1157
+++ b/test/stderr/1157
@@ -71,16 +71,19 @@ cmd buf flush ddd bytes
   SMTP<< 250 OK
   SMTP<< 250 Accepted
   SMTP<< 354 Enter message, ending with "." on a line by itself
-  SMTP<< 250 OK id=10HmbC-0005vi-00
   SMTP+> QUIT
 cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP(TLS shutdown)>>
+  SMTP<< 250 OK id=10HmbC-0005vi-00
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
->>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
 LOG: MAIN
   => usery@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no C="250 OK id=10HmbC-0005vi-00"
 LOG: MAIN
   Completed

>>>>>>>>>>>>>>>> Exim pid=pppp (continued-transport) terminating with rc=0 >>>>>>>>>>>>>>>>

+>>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
LOG: queue_run MAIN
End queue run: pid=pppp -qqf
>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>

@@ -157,16 +160,19 @@ cmd buf flush ddd bytes
SMTP<< 250 OK
SMTP<< 250 Accepted
SMTP<< 354 Enter message, ending with "." on a line by itself
- SMTP<< 250 OK id=10HmbI-0005vi-00
SMTP+> QUIT
cmd buf flush ddd bytes (more expected)
+ SMTP(shutdown)>>
+ SMTP(TLS shutdown)>>
+ SMTP<< 250 OK id=10HmbI-0005vi-00
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
->>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
LOG: MAIN
=> userb@??? R=cl_override T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no C="250 OK id=10HmbI-0005vi-00"
LOG: MAIN
Completed
>>>>>>>>>>>>>>>> Exim pid=pppp (continued-transport) terminating with rc=0 >>>>>>>>>>>>>>>>

+>>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
LOG: queue_run MAIN
End queue run: pid=pppp -qqf
>>>>>>>>>>>>>>>> Exim pid=pppp (fresh-exec) terminating with rc=0 >>>>>>>>>>>>>>>>

@@ -200,7 +206,7 @@ cmd buf flush ddd bytes
          250-PIPELINING
          250 HELP
   SMTP|> MAIL FROM:<CALLER@???> SIZE=ssss
-  SMTP|> RCPT TO:<userx@???>
+  SMTP|> RCPT TO:<user_p@???>
   SMTP>> DATA
 cmd buf flush ddd bytes
   SMTP<< 250 OK
@@ -217,7 +223,7 @@ cmd buf flush ddd bytes
          250 HELP
   SMTP(close)>>
 LOG: MAIN
-  => userx@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbM-0005vi-00"
+  => user_p@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbM-0005vi-00"
 LOG: MAIN
   Completed

>>>>>>>>>>>>>>>> Exim pid=pppp (qrun-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>

@@ -237,7 +243,7 @@ cmd buf flush ddd bytes
          250-PIPELINING
          250 HELP
   SMTP|> MAIL FROM:<CALLER@???> SIZE=ssss
-  SMTP|> RCPT TO:<userz@???>
+  SMTP|> RCPT TO:<user_r@???>
   SMTP>> DATA
 cmd buf flush ddd bytes
   SMTP<< 250 OK
@@ -254,7 +260,7 @@ cmd buf flush ddd bytes
          250 HELP
   SMTP(close)>>
 LOG: MAIN
-  => userz@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbN-0005vi-00"
+  => user_r@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbN-0005vi-00"
 LOG: MAIN
   Completed

>>>>>>>>>>>>>>>> Exim pid=pppp (continued-transport) terminating with rc=0 >>>>>>>>>>>>>>>>

@@ -274,18 +280,19 @@ cmd buf flush ddd bytes
          250-PIPELINING
          250 HELP
   SMTP|> MAIL FROM:<CALLER@???> SIZE=ssss
-  SMTP|> RCPT TO:<usery@???>
+  SMTP|> RCPT TO:<user_q@???>
   SMTP>> DATA
 cmd buf flush ddd bytes
   SMTP<< 250 OK
   SMTP<< 250 Accepted
   SMTP<< 354 Enter message, ending with "." on a line by itself
+  SMTP>> QUIT
+cmd buf flush ddd bytes
   SMTP<< 250 OK id=10HmbO-0005vi-00
-  SMTP+> QUIT
-cmd buf flush ddd bytes (more expected)
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
 LOG: MAIN
-  => usery@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbO-0005vi-00"
+  => user_q@??? R=client T=send_to_server H=127.0.0.1 [127.0.0.1]* X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbO-0005vi-00"
 LOG: MAIN
   Completed

>>>>>>>>>>>>>>>> Exim pid=pppp (continued-transport) terminating with rc=0 >>>>>>>>>>>>>>>>

diff --git a/test/stderr/1160 b/test/stderr/1160
index a302240..cdbad36 100644
--- a/test/stderr/1160
+++ b/test/stderr/1160
@@ -16,8 +16,9 @@ Connecting to 127.0.0.1 [127.0.0.1]:1225 ... connected
SMTP<< 250 Accepted
SMTP<< 354 Enter message, ending with "." on a line by itself
SMTP>> writing message and terminating "."
+ SMTP>> QUIT
SMTP<< 250 OK id=10HmaZ-0005vi-00
- SMTP+> QUIT
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
LOG: MAIN
=> CALLER@??? R=client T=send_to_server1 H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmaZ-0005vi-00"
@@ -41,8 +42,9 @@ Connecting to 127.0.0.1 [127.0.0.1]:1225 ... connected
SMTP<< 250 Accepted
SMTP<< 354 Enter message, ending with "." on a line by itself
SMTP>> writing message and terminating "."
+ SMTP>> QUIT
SMTP<< 250 OK id=10HmbA-0005vi-00
- SMTP+> QUIT
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
LOG: MAIN
=> CALLER@??? R=client T=send_to_server1 H=127.0.0.1 [127.0.0.1] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbA-0005vi-00"
@@ -63,8 +65,9 @@ Connecting to ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4]:1225 ... connected
SMTP<< 250 Accepted
SMTP<< 354 Enter message, ending with "." on a line by itself
SMTP>> writing message and terminating "."
+ SMTP>> QUIT
SMTP<< 250 OK id=10HmbB-0005vi-00
- SMTP+> QUIT
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
LOG: MAIN
=> abcd@??? R=client T=send_to_server2 H=ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4] X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=yes C="250 OK id=10HmbB-0005vi-00"
diff --git a/test/stderr/2035 b/test/stderr/2035
index 95c3b78..c15645c 100644
--- a/test/stderr/2035
+++ b/test/stderr/2035
@@ -64,13 +64,16 @@ writing data block fd=dddd size=sss timeout=300
ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address is NULL
SMTP+> QUIT
cmd buf flush ddd bytes (more expected)
+ SMTP(shutdown)>>
+ SMTP(TLS shutdown)>>
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
->>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
Leaving t1 transport
LOG: MAIN
=> userb@??? R=client T=t1 H=127.0.0.1 [127.0.0.1]:1225 X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no C="250 OK id=10HmaY-0005vi-00"
LOG: MAIN
Completed
>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>

+>>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>

******** SERVER ********
diff --git a/test/stderr/2135 b/test/stderr/2135
index 95c3b78..c15645c 100644
--- a/test/stderr/2135
+++ b/test/stderr/2135
@@ -64,13 +64,16 @@ writing data block fd=dddd size=sss timeout=300
ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address is NULL
SMTP+> QUIT
cmd buf flush ddd bytes (more expected)
+ SMTP(shutdown)>>
+ SMTP(TLS shutdown)>>
+ SMTP<< 221 myhost.test.ex closing connection
SMTP(close)>>
->>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>
Leaving t1 transport
LOG: MAIN
=> userb@??? R=client T=t1 H=127.0.0.1 [127.0.0.1]:1225 X=TLS1.x:ke-RSA-AES256-SHAnnn:xxx CV=no C="250 OK id=10HmaY-0005vi-00"
LOG: MAIN
Completed
>>>>>>>>>>>>>>>> Exim pid=pppp (local-accept-delivery) terminating with rc=0 >>>>>>>>>>>>>>>>

+>>>>>>>>>>>>>>>> Exim pid=pppp (tls-proxy) terminating with rc=0 >>>>>>>>>>>>>>>>

 ******** SERVER ********
diff --git a/test/stderr/3404 b/test/stderr/3404
index c117158..ea3f7e0 100644
--- a/test/stderr/3404
+++ b/test/stderr/3404
@@ -18,6 +18,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP>> writing message and terminating "."
   SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => userx@??? R=all T=smtp H=127.0.0.1 [127.0.0.1] A=plain C="250 OK"
@@ -43,6 +45,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP>> writing message and terminating "."
   SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => userx@??? R=all T=smtp H=127.0.0.1 [127.0.0.1] A=plain C="250 OK"
@@ -72,6 +76,8 @@ Connecting to 127.0.0.1 [127.0.0.1]:1224 ...  connected
   SMTP>> writing message and terminating "."
   SMTP<< 250 OK
   SMTP+> QUIT
+  SMTP(shutdown)>>
+  SMTP<< 250 OK
   SMTP(close)>>
 LOG: MAIN
   => userx@??? R=all T=smtp H=127.0.0.1 [127.0.0.1] A=login C="250 OK"
diff --git a/test/stderr/4052 b/test/stderr/4052
index c824cb4..4c0c1b1 100644
--- a/test/stderr/4052
+++ b/test/stderr/4052
@@ -48,16 +48,19 @@ sync_responses expect rcpt for extchange@???
 sync_responses expect data
   SMTP<< 354 data go-ahead
   SMTP>> writing message and terminating "."
-cannot use sendfile for body: spoolfile not wireformat
-writing data block fd=dddd size=sss timeout=300
-  SMTP<< 250 message accepted
-ok=1 send_quit=1 send_rset=0 continue_more=0 yield=0 first_address is NULL
 transport_check_waiting entered
   sequence=1 local_max=500 global_max=-1
  no messages waiting for 127.0.0.1
 transport_check_waiting: FALSE
+will pipeline QUIT
+cannot use sendfile for body: spoolfile not wireformat
+writing data block fd=dddd size=sss timeout=300 (more expected)
   SMTP+> QUIT
 cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 250 message accepted
+ok=1 send_quit=0 send_rset=0 continue_more=0 yield=0 first_address is NULL
+  SMTP<< 220 bye
   SMTP(close)>>
 Leaving smtp transport
 LOG: MAIN
diff --git a/test/stderr/4520 b/test/stderr/4520
index ad927fc..cfdbe6e 100644
--- a/test/stderr/4520
+++ b/test/stderr/4520
@@ -47,9 +47,11 @@ DKIM-Signature:{SP}v=1;{SP}a=rsa-sha256;{SP}q=dns/txt;{SP}c=relaxed/relaxed;{SP}
 DKIM >> Signed DKIM-Signature header, canonicalized (relaxed) >>>>>>>
 dkim-signature:v=1;{SP}a=rsa-sha256;{SP}q=dns/txt;{SP}c=relaxed/relaxed;{SP}d=test.ex;{SP}s=sel_bad;{SP}h=From;{SP}bh=/Ab0giHZitYQbDhFszoqQRUkgqueaX9zatJttIU/plc=;{SP}b=;
 DKIM [test.ex] Header sha256 computed: 241e16230df5723d899cfae9474c6b376a2ab1f81d1094e358f50ffd0e0067b3
-  SMTP<< 250 OK id=10HmbL-0005vi-00
   SMTP+> QUIT
 cmd buf flush ddd bytes (more expected)
+  SMTP(shutdown)>>
+  SMTP<< 250 OK id=10HmbL-0005vi-00
+  SMTP<< 221 myhost.test.ex closing connection
   SMTP(close)>>
 LOG: MAIN
   => d@??? R=client T=send_to_server H=ip4.ip4.ip4.ip4 [ip4.ip4.ip4.ip4] C="250 OK id=10HmbL-0005vi-00"
diff --git a/test/stdout/0623 b/test/stdout/0623
new file mode 100644
index 0000000..1c571c9
--- /dev/null
+++ b/test/stdout/0623
@@ -0,0 +1,133 @@
+Message 10HmaZ-0005vi-00 has been removed
+Message 10HmbB-0005vi-00 has been removed
+
+******** SERVER ********
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<good@???>
+250 OK rcpt
+DATA
+300 go ahead
+Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+    (envelope-from <CALLER@???>)
+    id 10HmaX-0005vi-00
+    for good@???; Tue, 2 Mar 1999 09:44:33 +0000
+Message-Id: <E10HmaX-0005vi-00@???>
+From: CALLER_NAME <CALLER@???>
+Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+.
+QUIT
+250 OK message data
+221 Closing connection
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<nopipe@???>
+250 OK rcpt
+DATA
+300 go ahead
+Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+    (envelope-from <CALLER@???>)
+    id 10HmaY-0005vi-00
+    for nopipe@???; Tue, 2 Mar 1999 09:44:33 +0000
+Message-Id: <E10HmaY-0005vi-00@???>
+From: CALLER_NAME <CALLER@???>
+Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+.
+250 OK message data
+*sleep 1
+<<QUIT
+Unexpected EOF read from client
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<tempreject@???>
+250 OK rcpt
+DATA
+300 go ahead
+Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+    (envelope-from <CALLER@???>)
+    id 10HmaZ-0005vi-00
+    for tempreject@???; Tue, 2 Mar 1999 09:44:33 +0000
+Message-Id: <E10HmaZ-0005vi-00@???>
+From: CALLER_NAME <CALLER@???>
+Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+.
+QUIT
+451 Service not available
+221 Closing connection
+Expected EOF read from client
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<permreject@???>
+250 OK rcpt
+DATA
+300 go ahead
+Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+    (envelope-from <CALLER@???>)
+    id 10HmbA-0005vi-00
+    for permreject@???; Tue, 2 Mar 1999 09:44:33 +0000
+Message-Id: <E10HmbA-0005vi-00@???>
+From: CALLER_NAME <CALLER@???>
+Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+.
+QUIT
+550 content rejected
+221 Closing connection
+Expected EOF read from client
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<permreject@???>
+250 OK rcpt
+DATA
+300 go ahead
+Received: from CALLER by myhost.test.ex with local (Exim x.yz)
+    (envelope-from <CALLER@???>)
+    id 10HmbB-0005vi-00
+    for permreject@???; Tue, 2 Mar 1999 09:44:33 +0000
+Message-Id: <E10HmbB-0005vi-00@???>
+From: CALLER_NAME <CALLER@???>
+Date: Tue, 2 Mar 1999 09:44:33 +0000
+
+.
+>*eof
+End of script
diff --git a/test/stdout/0904 b/test/stdout/0904
index 8875566..6df7891 100644
--- a/test/stdout/0904
+++ b/test/stdout/0904
@@ -110,17 +110,6 @@ EHLO testhost.test.ex
 250-PIPELINING
 250 CHUNKING
 MAIL FROM:<>
-RCPT TO:<q@???>
-BDAT 329 LAST
-Unexpected EOF read from client
-Listening on port 1224 ... 
-Connection request from [127.0.0.1]
-220 Greetings
-EHLO testhost.test.ex
-250-Hello there
-250-PIPELINING
-250 CHUNKING
-MAIL FROM:<>
 RCPT TO:<r@???>
 BDAT 329 LAST
 250 OK mail
diff --git a/test/stdout/0911 b/test/stdout/0911
new file mode 100644
index 0000000..92db28b
--- /dev/null
+++ b/test/stdout/0911
@@ -0,0 +1,123 @@
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 myhost.test.ex Hello root at tester
+250 OK
+250 Accepted
+354 Enter message, ending with "." on a line by itself
+250 OK id=10HmaX-0005vi-00
+221 myhost.test.ex closing connection
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 myhost.test.ex Hello root at tester
+250 OK
+250 Accepted
+354 Enter message, ending with "." on a line by itself
+250 OK id=10HmaY-0005vi-00
+221 myhost.test.ex closing connection
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 myhost.test.ex Hello root at tester
+250 OK
+250 Accepted
+354 Enter message, ending with "." on a line by itself
+250 OK id=10HmaZ-0005vi-00
+221 myhost.test.ex closing connection
+Message 10HmaZ-0005vi-00 has been removed
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 myhost.test.ex Hello root at tester
+250 OK
+250 Accepted
+354 Enter message, ending with "." on a line by itself
+250 OK id=10HmbA-0005vi-00
+221 myhost.test.ex closing connection
+220 myhost.test.ex ESMTP Exim x.yz Tue, 2 Mar 1999 09:44:33 +0000
+250 myhost.test.ex Hello root at tester
+250 OK
+250 Accepted
+354 Enter message, ending with "." on a line by itself
+250 OK id=10HmbB-0005vi-00
+221 myhost.test.ex closing connection
+Message 10HmbB-0005vi-00 has been removed
+
+******** SERVER ********
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM:<>
+RCPT TO:<good@???>
+BDAT 313 LAST
+250 OK mail
+250 OK rcpt
+QUIT
+250 OK chunked message data
+221 Closing connection
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-CHUNKING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<nopipe@???>
+250 OK rcpt
+BDAT 315 LAST
+250 OK chunked message data
+QUIT
+221 Closing connection
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<tempreject@???>
+250 OK rcpt
+BDAT 319 LAST
+QUIT
+451 Service not available
+221 Closing connection
+Expected EOF read from client
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<permreject@???>
+250 OK rcpt
+BDAT 319 LAST
+QUIT
+550 content rejected
+221 Closing connection
+Expected EOF read from client
+End of script
+Listening on port 1225 ... 
+Connection request from [127.0.0.1]
+220 Server ready
+EHLO myhost.test.ex
+250-hi there
+250-PIPELINING
+250-CHUNKING
+250 OK
+MAIL FROM:<>
+250 OK mail
+RCPT TO:<dataloss@???>
+250 OK rcpt
+BDAT 317 LAST
+>*eof
+End of script