EXPERIMENTAL_DSN: use the SMTP return messsage for Diagnostic-Code lines. Bug 1559
authorWolfgang Breyha <wbreyha@gmx.net>
Fri, 19 Dec 2014 15:51:45 +0000 (15:51 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Fri, 19 Dec 2014 16:59:50 +0000 (16:59 +0000)
Minor tweaking by JH.

src/src/deliver.c
test/mail/0211.CALLER
test/mail/0253.lmn
test/mail/0374.CALLER
test/mail/0375.CALLER
test/mail/0531.CALLER

index 9506bb0c1864908b711abb4b9d65a7d960364813..462aaf49dbff4a0a3a005c998435bfebd61b6505 100644 (file)
@@ -4808,8 +4808,54 @@ while (*s != 0)
 }
 
 
+/***********************************************************
+*         Print Diagnostic-Code for an address             *
+************************************************************/
 
+/* This function is called to print the error information out of an address for
+a bounce or a warning message. It tries to format the message reasonably as
+required by RFC 3461 by adding a space after each newline
+
+we assume that this function is only called if addr->host_used is set and if so
+a useable addr->message is available containing some Exim description with ": \n" 
+ending, followed by the L/SMTP error message.
+
+Arguments:
+  addr         the address
+  f            the FILE to print on
 
+Returns:       nothing
+*/
+
+static void
+print_dsn_diagnostic_code(const address_item *addr, FILE *f)
+{
+uschar * s;
+
+/* check host_used, af_pass_message flag and addr->message for safety reasons */
+if (!addr->host_used && testflag(addr, af_pass_message) && addr->message)
+  return;
+
+/* search first ": ". we assume to find the remote-MTA answer there */
+DEBUG(D_deliver)
+  debug_printf("DSN Diagnostic-Code: addr->dsn_message = %s\n", addr->message);
+if (!(s = Ustrstr(addr->message, ": ")))
+  return;                              /* not found, bail out */
+
+fprintf(f, "Diagnostic-Code: smtp; ");
+
+s += 2;  /* skip ": " */
+while (*s)
+  if (*s == '\\' && s[1] == 'n')
+    {
+    fputs("\n ", f);    /* as defined in RFC 3461 */
+    s += 2;
+    }
+  else
+    fputc(*s++, f);
+
+fputc('\n', f);
+}
 
 
 /*************************************************
@@ -6754,8 +6800,7 @@ if (addr_senddsn != NULL)
     transport_write_message(NULL, fileno(f), topt, 0, NULL, NULL, NULL, NULL, NULL, 0);
     fflush(f);
 
-    fprintf(f,"\n");       
-    fprintf(f,"--%s--\n", bound);
+    fprintf(f,"\n--%s--\n", bound);
 
     fflush(f);
     fclose(f);
@@ -7118,8 +7163,11 @@ wording. */
            "Status: 5.0.0\n",
            addr->address);
         if (addr->host_used && addr->host_used->name)
-          fprintf(f, "Remote-MTA: dns; %s\nDiagnostic-Code: smtp; %d\n",
-           addr->host_used->name, addr->basic_errno);
+          {
+          fprintf(f, "Remote-MTA: dns; %s\n",
+           addr->host_used->name);
+          print_dsn_diagnostic_code(addr, f);
+          }
         }
 
       /* Now copy the message, trying to give an intelligible comment if
@@ -7627,8 +7675,11 @@ else if (addr_defer != (address_item *)(+1))
           fprintf(f,"Final-Recipient: rfc822;%s\n", addr_dsndefer->address);
           fprintf(f,"Status: 4.0.0\n");
           if (addr_dsndefer->host_used && addr_dsndefer->host_used->name)
-            fprintf(f,"Remote-MTA: dns; %s\nDiagnostic-Code: smtp; %d\n", 
-                   addr_dsndefer->host_used->name, addr_dsndefer->basic_errno);
+            {
+            fprintf(f,"Remote-MTA: dns; %s\n", 
+                   addr_dsndefer->host_used->name);
+            print_dsn_diagnostic_code(addr_dsndefer, f);
+            }
           addr_dsndefer = addr_dsndefer->next;
           }
 
index ab4609464dcb40a1c6f2e4e7e2b97add5df53a95..89eadf58d2601acb9c8839ecbeaf3d466b21da55 100644 (file)
@@ -35,7 +35,7 @@ Action: failed
 Final-Recipient: rfc822;userx@domain1
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 Go away
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
@@ -95,12 +95,12 @@ Action: failed
 Final-Recipient: rfc822;userx@domain1
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 Go away
 Action: failed
 Final-Recipient: rfc822;usery@domain2
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 Go away
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
index 70cca86627c8853e134a2c9b8d98540993696ae2..ea91b0187173e5fc04aa81bb40874b7a5d8bb538 100644 (file)
@@ -38,7 +38,7 @@ Action: failed
 Final-Recipient: rfc822;fail@myhost.test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 Recipient not OK
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
index 6cbbe15a02431a30c50ace1565d30923ba9560e7..859d93d3bc3c1bb3f7b8ea56d0abc10684995a2f 100644 (file)
@@ -42,7 +42,7 @@ Action: failed
 Final-Recipient: rfc822;d3@myhost.test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 hard error
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
index a2929c3c7603d4c83487fee8a8784ee916a922aa..569d3f8bf7826b354597505dae847dd759e0675e 100644 (file)
@@ -36,7 +36,7 @@ Action: failed
 Final-Recipient: rfc822;e1@myhost.test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 550 hard error
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
index 1d70d8a0ad9b08166d2728549ff4de7363d2271c..4d714c7564826eb397397b81a99dc67085e3758f 100644 (file)
@@ -33,7 +33,7 @@ Action: failed
 Final-Recipient: rfc822;userx@test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 450 TEMPERROR: retry timeout exceeded
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
@@ -85,7 +85,7 @@ Action: failed
 Final-Recipient: rfc822;userx@retry.test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; 0
+Diagnostic-Code: smtp; 450 TEMPERROR: retry timeout exceeded
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822
@@ -139,7 +139,7 @@ Action: failed
 Final-Recipient: rfc822;userx@test.ex
 Status: 5.0.0
 Remote-MTA: dns; 127.0.0.1
-Diagnostic-Code: smtp; -44
+Diagnostic-Code: smtp; 450 TEMPERROR: retry timeout exceeded
 
 --NNNNNNNNNN-eximdsn-MMMMMMMMMM
 Content-type: message/rfc822