Gitweb:
http://git.exim.org/exim.git/commitdiff/21bc4865a31e8fba169d6da095890f842fc0643a
Commit: 21bc4865a31e8fba169d6da095890f842fc0643a
Parent: ed65a028cac9fff619338be84bef3643cc06ae06
Author: Wolfgang Breyha <wbreyha@???>
AuthorDate: Fri Dec 19 15:51:45 2014 +0000
Committer: Jeremy Harris <jgh146exb@???>
CommitDate: Fri Dec 19 15:54:37 2014 +0000
EXPERIMENTAL_DSN: use the SMTP return messsage for Diagnostic-Code lines. Bug 1559
Minor tweaking by JH.
---
src/src/deliver.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 59 insertions(+), 6 deletions(-)
diff --git a/src/src/deliver.c b/src/src/deliver.c
index 2c0524e..d33cf79 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -4793,8 +4793,56 @@ while (*s != 0)
}
+#ifdef EXPERIMENTAL_DSN
+/***********************************************************
+* 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);
+}
+#endif /* EXPERIMENTAL_DSN */
/*************************************************
@@ -6744,8 +6792,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 +7165,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);
+ }
}
#endif
@@ -7694,8 +7744,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;
}