Index: trunk/src/sh_mail.c
===================================================================
--- trunk/src/sh_mail.c	(revision 252)
+++ trunk/src/sh_mail.c	(revision 272)
@@ -947,4 +947,5 @@
 
 static time_t time_wait = 300;
+static void report_smtp (char * reply);
 
 static FILE * sh_mail_start_conn (struct alias * ma_address, 
@@ -1113,12 +1114,14 @@
   if (0 != is_numeric(sh.host.name))
     {
-      TPT(( 0, FIL__, __LINE__, _("msg=<HELO [%s]>%c%c"), 
-	    sh.host.name, 13, 10));
+      sl_snprintf(error_msg, sizeof(error_msg), "HELO [%s]", 
+		  sh.host.name);
     }
   else
     {
-      TPT(( 0, FIL__, __LINE__, _("msg=<HELO %s>%c%c"), 
-	    sh.host.name, 13, 10));
-    }
+      sl_snprintf(error_msg, sizeof(error_msg), "HELO %s", 
+		  sh.host.name);
+    }
+  report_smtp(error_msg);
+
   if (0 != is_numeric(sh.host.name))
     fprintf(connFile, _("HELO [%s]%c%c"), sh.host.name, 13, 10);
@@ -1152,6 +1155,7 @@
     }
 
-  TPT(( 0, FIL__, __LINE__,  _("msg=<MAIL FROM:<%s>>%c%c"), 
-	this_address, 13, 10));
+  sl_snprintf(error_msg, sizeof(error_msg), "MAIL FROM:<%s>", 
+	      this_address);
+  report_smtp(error_msg);
 
   (void) fflush(connFile);
@@ -1175,6 +1179,7 @@
   if (aFlag == 0)
     {
-      TPT(( 0, FIL__, __LINE__,  _("msg=<RCPT TO:<%s>>%c%c"), 
-	    address, 13, 10)); 
+      sl_snprintf(error_msg, sizeof(error_msg), "RCPT TO:<%s>", 
+		  address);
+      report_smtp(error_msg);
 
       (void) fflush(connFile);
@@ -1210,6 +1215,7 @@
 	  ++address_num;
 
-	  TPT(( 0, FIL__, __LINE__,  _("msg=<RCPT TO:<%s>>%c%c"), 
-		sh_string_str(ma_address->recipient), 13, 10)); 
+	  sl_snprintf(error_msg, sizeof(error_msg), "RCPT TO:<%s>", 
+		      sh_string_str(ma_address->recipient));
+	  report_smtp(error_msg);
 	  
 	  (void) fflush(connFile);
@@ -1241,5 +1247,5 @@
   /* Send the message 
    */
-  TPT(( 0, FIL__, __LINE__,  _("msg=<DATA>%c%c"), 13, 10)); 
+  report_smtp(_("DATA"));
 
   (void) fflush(connFile);
@@ -1273,4 +1279,6 @@
   TPT(( 0, FIL__, __LINE__,  _("msg=<From: <%s>%c%cTo: <%s>%c%cDate: %s>%c%c"),
 	this_address, 13, 10, address, 13, 10, my_tbuf, 13, 10));
+
+  report_smtp(_("sending data.."));
 
   (void) fflush(connFile);
@@ -1299,9 +1307,9 @@
   time_wait = 300;
 
+  report_smtp(_("."));
+
   (void) fflush(connFile);
   fprintf(connFile, _("%c%c.%c%c"), 13, 10, 13, 10);   
   (void) fflush(connFile);
-
-  TPT(( 0, FIL__, __LINE__, _("msg=<message end written>\n")));
 
   if (0 != sh_mail_wait(250, fd))
@@ -1332,4 +1340,22 @@
  *
  */
+extern int flag_err_debug;
+
+static void report_smtp (char * reply)
+{
+  char * tmp;
+
+  if (flag_err_debug == SL_TRUE)
+    {
+      tmp = sh_util_safe_name_keepspace(reply);
+
+      sh_error_handle (SH_ERR_ALL, FIL__, __LINE__, 0, MSG_E_SUBGEN,
+		       tmp,
+		       _("report_smtp") );
+      SH_FREE(tmp);
+    }
+  return;
+}
+
 
 static int sh_mail_wait(int code, int ma_socket)
@@ -1339,5 +1365,7 @@
   char c;
 
-  char errmsg[128];
+  char errmsg[194];
+  char reply[128];
+  unsigned int  ireply = 0;
 
   enum { 
@@ -1357,8 +1385,19 @@
    */
 
-  rcode = 0;
-  state = WAIT_CODE_START;
+  rcode    = 0;
+  state    = WAIT_CODE_START;
+  reply[0] = '\0';
 
   while (sl_read_timeout_fd (ma_socket, &c, 1, time_wait, SL_FALSE) > 0) {
+
+    if (ireply < (sizeof(reply) - 1))
+      {
+	if (c != '\n' && c != '\r')
+	  {
+	    reply[ireply] = c;
+	    ++ireply;
+	    reply[ireply] = '\0';
+	  }
+      }
 
     g = (int) c;
@@ -1379,6 +1418,9 @@
       if (0 != isspace(g))
 	break;             /* Skip white space                    */
-      if (0 == isdigit(g))
-	return 0;          /* No leading number                   */
+      if (0 == isdigit(g)) 
+	{
+	  report_smtp(reply);
+	  SL_RETURN( 0, _("mail_wait")); /* No leading number     */
+	}
       rcode = g-(int)'0';  /* convert to number                   */
       state = WAIT_CODE;
@@ -1411,10 +1453,16 @@
       if (g != 1)
 	{
+	  char * tmp = sh_util_safe_name_keepspace(reply);
           sl_snprintf(errmsg, sizeof(errmsg),
-		      _("Bad response (%d), expected %d"), rcode, code);
+		      _("Bad response (%s), expected %d"), tmp, code);
+	  SH_FREE(tmp);
 
 	  sh_error_handle((-1), FIL__, __LINE__, 0, MSG_E_NET, 
 			  errmsg, _("sh_mail_wait"), 
 			  _("mail"), _("SMTP server"));
+	}
+      else
+	{
+	  report_smtp(reply);
 	}
       waited_time = time(NULL) - waited_time;
@@ -1438,4 +1486,5 @@
 
       TPT((0, FIL__, __LINE__, _("msg=<mail_wait: bad>\n"))); 
+      report_smtp(reply);
       SL_RETURN( 0, _("mail_wait")); 
       
@@ -1446,4 +1495,5 @@
 
   /* Failed, EOF or error on socket */
+  report_smtp(reply);
   SL_RETURN( 0, _("mail_wait")); 
 }
