tidying
[exim.git] / src / src / smtp_out.c
index ba6153ea9b9316a1d54a74b889ae3aace7aefb64..c4f32a0c2eea0482488d5baeb2d2040535c373a2 100644 (file)
@@ -100,7 +100,7 @@ smtp_get_port(uschar *rstring, address_item *addr, int *port, uschar *msg)
 {
 uschar *pstring = expand_string(rstring);
 
-if (pstring == NULL)
+if (!pstring)
   {
   addr->transport_return = PANIC;
   addr->message = string_sprintf("failed to expand \"%s\" (\"port\" option) "
@@ -124,7 +124,7 @@ if (isdigit(*pstring))
 else
   {
   struct servent *smtp_service = getservbyname(CS pstring, "tcp");
-  if (smtp_service == NULL)
+  if (!smtp_service)
     {
     addr->transport_return = PANIC;
     addr->message = string_sprintf("TCP port \"%s\" is not defined for %s",
@@ -319,23 +319,32 @@ pipelining.
 
 Argument:
   outblock   the SMTP output block
+  mode      more-expected, or plain
 
 Returns:     TRUE if OK, FALSE on error, with errno set
 */
 
 static BOOL
-flush_buffer(smtp_outblock *outblock)
+flush_buffer(smtp_outblock * outblock, int mode)
 {
 int rc;
 int n = outblock->ptr - outblock->buffer;
 
-HDEBUG(D_transport|D_acl) debug_printf_indent("cmd buf flush %d bytes\n", n);
+HDEBUG(D_transport|D_acl) debug_printf_indent("cmd buf flush %d bytes%s\n", n,
+  mode == SCMD_MORE ? " (more expected)" : "");
+
 #ifdef SUPPORT_TLS
 if (tls_out.active == outblock->sock)
   rc = tls_write(FALSE, outblock->buffer, n);
 else
 #endif
-  rc = send(outblock->sock, outblock->buffer, n, 0);
+  rc = send(outblock->sock, outblock->buffer, n,
+#ifdef MSG_MORE
+           mode == SCMD_MORE ? MSG_MORE : 0
+#else
+           0
+#endif
+          );
 
 if (rc <= 0)
   {
@@ -359,7 +368,7 @@ any error message.
 
 Arguments:
   outblock   contains buffer for pipelining, and socket
-  noflush    if TRUE, save the command in the output buffer, for pipelining
+  mode       buffer, write-with-more-likely, write
   format     a format, starting with one of
              of HELO, MAIL FROM, RCPT TO, DATA, ".", or QUIT.
             If NULL, flush pipeline buffer only.
@@ -371,7 +380,7 @@ Returns:     0 if command added to pipelining buffer, with nothing transmitted
 */
 
 int
-smtp_write_command(smtp_outblock *outblock, BOOL noflush, const char *format, ...)
+smtp_write_command(smtp_outblock * outblock, int mode, const char *format, ...)
 {
 int count;
 int rc = 0;
@@ -393,7 +402,7 @@ if (format)
   if (count > outblock->buffersize - (outblock->ptr - outblock->buffer))
     {
     rc = outblock->cmd_count;                 /* flush resets */
-    if (!flush_buffer(outblock)) return -1;
+    if (!flush_buffer(outblock, SCMD_FLUSH)) return -1;
     }
 
   Ustrncpy(CS outblock->ptr, big_buffer, count);
@@ -423,10 +432,10 @@ if (format)
   HDEBUG(D_transport|D_acl|D_v) debug_printf_indent("  SMTP>> %s\n", big_buffer);
   }
 
-if (!noflush)
+if (mode != SCMD_BUFFER)
   {
   rc += outblock->cmd_count;                /* flush resets */
-  if (!flush_buffer(outblock)) return -1;
+  if (!flush_buffer(outblock, mode)) return -1;
   }
 
 return rc;
@@ -500,8 +509,9 @@ for (;;)
 
   if((rc = ip_recv(sock, inblock->buffer, inblock->buffersize, timeout)) <= 0)
     {
-    if (!errno)
-      DEBUG(D_deliver|D_transport|D_acl) debug_printf_indent("  SMTP(closed)<<\n");
+    DEBUG(D_deliver|D_transport|D_acl)
+      debug_printf_indent(errno ? "  SMTP(%s)<<\n" : "  SMTP(closed)<<\n",
+       strerror(errno));
     break;
     }