From 1c5b14999af72b5e2471f708b91631738f07dfb7 Mon Sep 17 00:00:00 2001 From: Jeremy Harris Date: Sat, 7 Mar 2015 16:05:19 +0000 Subject: [PATCH] DSN: fix multiple-recipient notifications A newline is needed between each Action group --- src/src/deliver.c | 88 +++++++++++++++++++------------------------ test/mail/0037.CALLER | 2 + test/mail/0098.CALLER | 5 +++ test/mail/0194.CALLER | 10 +++++ test/mail/0211.CALLER | 1 + test/mail/0224.CALLER | 3 ++ test/mail/0226.CALLER | 1 + test/mail/0237.CALLER | 1 + test/mail/0309.CALLER | 2 + test/mail/0374.CALLER | 1 + 10 files changed, 64 insertions(+), 50 deletions(-) diff --git a/src/src/deliver.c b/src/src/deliver.c index ad871c575..65b4824ab 100644 --- a/src/src/deliver.c +++ b/src/src/deliver.c @@ -912,7 +912,7 @@ if (log_extra_selector & LX_smtp_confirmation && (addr->host_used || Ustrcmp(addr->transport->driver_name, "lmtp") == 0)) { unsigned i; - unsigned lim = MIN(big_buffer_size, 1024); + unsigned lim = big_buffer_size < 1024 ? big_buffer_size : 1024; uschar *p = big_buffer; uschar *ss = addr->message; *p++ = '\"'; @@ -6715,8 +6715,7 @@ if (addr_senddsn != NULL) "create child process to send failure message: %s", getpid(), getppid(), strerror(errno)); - DEBUG(D_deliver) debug_printf("DSN: child_open_exim failed\n"); - + DEBUG(D_deliver) debug_printf("DSN: child_open_exim failed\n"); } else /* Creation of child succeeded */ { @@ -6725,7 +6724,8 @@ if (addr_senddsn != NULL) int topt = topt_add_return_path | topt_no_body; uschar * bound; - DEBUG(D_deliver) debug_printf("sending error message to: %s\n", sender_address); + DEBUG(D_deliver) + debug_printf("sending error message to: %s\n", sender_address); /* build unique id for MIME boundary */ bound = string_sprintf(TIME_T_FMT "-eximdsn-%d", time(NULL), rand()); @@ -6748,9 +6748,8 @@ if (addr_senddsn != NULL) " ----- The following addresses had successful delivery notifications -----\n", qualify_domain_sender, sender_address, bound, bound); - addr_dsntmp = addr_senddsn; - while(addr_dsntmp) - { + for (addr_dsntmp = addr_senddsn; addr_dsntmp; + addr_dsntmp = addr_dsntmp->next) fprintf(f, "<%s> (relayed %s)\n\n", addr_dsntmp->address, (addr_dsntmp->dsn_flags & rf_dsnlasthop) == 1 @@ -6759,15 +6758,14 @@ if (addr_senddsn != NULL) ? "to non-DSN-aware mailer" : "via non \"Remote SMTP\" router" ); - addr_dsntmp = addr_dsntmp->next; - } + fprintf(f, "--%s\n" "Content-type: message/delivery-status\n\n" "Reporting-MTA: dns; %s\n", bound, smtp_active_hostname); - if (dsn_envid != NULL) { - /* must be decoded from xtext: see RFC 3461:6.3a */ + if (dsn_envid) + { /* must be decoded from xtext: see RFC 3461:6.3a */ uschar *xdec_envid; if (auth_xtextdecode(dsn_envid, &xdec_envid) > 0) fprintf(f, "Original-Envelope-ID: %s\n", dsn_envid); @@ -6789,12 +6787,11 @@ if (addr_senddsn != NULL) addr_dsntmp->address); if (addr_dsntmp->host_used && addr_dsntmp->host_used->name) - fprintf(f, "Remote-MTA: dns; %s\nDiagnostic-Code: smtp; 250 Ok\n", + fprintf(f, "Remote-MTA: dns; %s\nDiagnostic-Code: smtp; 250 Ok\n\n", addr_dsntmp->host_used->name); else - fprintf(f,"Diagnostic-Code: X-Exim; relayed via non %s router\n", + fprintf(f, "Diagnostic-Code: X-Exim; relayed via non %s router\n\n", (addr_dsntmp->dsn_flags & rf_dsnlasthop) == 1 ? "DSN" : "SMTP"); - fputc('\n', f); } fprintf(f, "--%s\nContent-type: text/rfc822-headers\n\n", bound); @@ -6876,16 +6873,16 @@ while (addr_failed != NULL) || ( ((addr_failed->dsn_flags & rf_dsnflags) != 0) && ((addr_failed->dsn_flags & rf_notify_failure) != rf_notify_failure)) ) - { + { addr = addr_failed; addr_failed = addr->next; if (addr->return_filename != NULL) Uunlink(addr->return_filename); log_write(0, LOG_MAIN, "%s%s%s%s: error ignored", addr->address, - (addr->parent == NULL)? US"" : US" <", - (addr->parent == NULL)? US"" : addr->parent->address, - (addr->parent == NULL)? US"" : US">"); + !addr->parent ? US"" : US" <", + !addr->parent ? US"" : addr->parent->address, + !addr->parent ? US"" : US">"); address_done(addr, logtod); child_done(addr, logtod); @@ -6901,16 +6898,12 @@ while (addr_failed != NULL) else { - bounce_recipient = (addr_failed->p.errors_address == NULL)? - sender_address : addr_failed->p.errors_address; + bounce_recipient = addr_failed->p.errors_address + ? addr_failed->p.errors_address : sender_address; /* Make a subprocess to send a message */ - pid = child_open_exim(&fd); - - /* Creation of child failed */ - - if (pid < 0) + if ((pid = child_open_exim(&fd)) < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Process %d (parent %d) failed to " "create child process to send failure message: %s", getpid(), getppid(), strerror(errno)); @@ -6941,20 +6934,16 @@ while (addr_failed != NULL) paddr = &addr_failed; for (addr = addr_failed; addr != NULL; addr = *paddr) - { - if (Ustrcmp(bounce_recipient, (addr->p.errors_address == NULL)? - sender_address : addr->p.errors_address) != 0) - { - paddr = &(addr->next); /* Not the same; skip */ - } - else /* The same - dechain */ - { + if (Ustrcmp(bounce_recipient, addr->p.errors_address + ? addr->p.errors_address : sender_address) == 0) + { /* The same - dechain */ *paddr = addr->next; *pmsgchain = addr; addr->next = NULL; pmsgchain = &(addr->next); } - } + else + paddr = &addr->next; /* Not the same; skip */ /* Include X-Failed-Recipients: for automatic interpretation, but do not let any one header line get too long. We do this by starting a @@ -6979,7 +6968,7 @@ while (addr_failed != NULL) /* Output the standard headers */ - if (errors_reply_to != NULL) + if (errors_reply_to) fprintf(f, "Reply-To: %s\n", errors_reply_to); fprintf(f, "Auto-Submitted: auto-replied\n"); moan_write_from(f); @@ -7175,6 +7164,7 @@ wording. */ addr->host_used->name); print_dsn_diagnostic_code(addr, f); } + fputc('\n', f); } /* Now copy the message, trying to give an intelligible comment if @@ -7195,7 +7185,7 @@ wording. */ bounce_return_size_limit is always honored. */ - fprintf(f, "\n--%s\n", bound); + fprintf(f, "--%s\n", bound); dsnlimitmsg = US"X-Exim-DSN-Information: Due to administrative limits only headers are returned"; dsnnotifyhdr = NULL; @@ -7224,10 +7214,9 @@ wording. */ } } - if (topt & topt_no_body) - fprintf(f,"Content-type: text/rfc822-headers\n\n"); - else - fprintf(f,"Content-type: message/rfc822\n\n"); + fputs(topt & topt_no_body ? "Content-type: text/rfc822-headers\n\n" + : "Content-type: message/rfc822\n\n", + f); fflush(f); transport_filter_argv = NULL; /* Just in case */ @@ -7327,11 +7316,9 @@ if (addr_defer == NULL) "msglog.OLD directory", spoolname); } else - { if (Uunlink(spoolname) < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to unlink %s: %s", spoolname, strerror(errno)); - } } /* Remove the two message files. */ @@ -7674,24 +7661,25 @@ else if (addr_defer != (address_item *)(+1)) } fputc('\n', f); - while (addr_dsndefer) + for ( ; addr_dsndefer; addr_dsndefer = addr_dsndefer->next) { if (addr_dsndefer->dsn_orcpt) - fprintf(f,"Original-Recipient: %s\n", addr_dsndefer->dsn_orcpt); + fprintf(f, "Original-Recipient: %s\n", addr_dsndefer->dsn_orcpt); - fprintf(f,"Action: delayed\n"); - fprintf(f,"Final-Recipient: rfc822;%s\n", addr_dsndefer->address); - fprintf(f,"Status: 4.0.0\n"); + fprintf(f, "Action: delayed\n" + "Final-Recipient: rfc822;%s\n" + "Status: 4.0.0\n", + addr_dsndefer->address); if (addr_dsndefer->host_used && addr_dsndefer->host_used->name) { - fprintf(f,"Remote-MTA: dns; %s\n", + fprintf(f, "Remote-MTA: dns; %s\n", addr_dsndefer->host_used->name); print_dsn_diagnostic_code(addr_dsndefer, f); } - addr_dsndefer = addr_dsndefer->next; + fputc('\n', f); } - fprintf(f, "\n--%s\n" + fprintf(f, "--%s\n" "Content-type: text/rfc822-headers\n\n", bound); diff --git a/test/mail/0037.CALLER b/test/mail/0037.CALLER index f3770676a..4ba7eef27 100644 --- a/test/mail/0037.CALLER +++ b/test/mail/0037.CALLER @@ -40,9 +40,11 @@ Reporting-MTA: dns; the.local.host.name Action: failed Final-Recipient: rfc822;userx@test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;abcd@test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;usery@test.ex Status: 5.0.0 diff --git a/test/mail/0098.CALLER b/test/mail/0098.CALLER index ffb739e5e..cead0a571 100644 --- a/test/mail/0098.CALLER +++ b/test/mail/0098.CALLER @@ -44,6 +44,7 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;|/non/existing/file Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 @@ -108,6 +109,7 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@another.test.ex Status: 4.0.0 @@ -172,6 +174,7 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;|/non/existing/file Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 @@ -231,6 +234,7 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;|/non/existing/file Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 @@ -290,6 +294,7 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@another.test.ex Status: 4.0.0 diff --git a/test/mail/0194.CALLER b/test/mail/0194.CALLER index 463575cd2..41420fb84 100644 --- a/test/mail/0194.CALLER +++ b/test/mail/0194.CALLER @@ -42,9 +42,11 @@ Reporting-MTA: dns; myhost.test.ex Action: failed Final-Recipient: rfc822;userz@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;usery@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;userx@myhost.test.ex Status: 5.0.0 @@ -126,21 +128,27 @@ Reporting-MTA: dns; myhost.test.ex Action: failed Final-Recipient: rfc822;three@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;two@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;one@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;six@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;five@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;four@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;seven@myhost.test.ex Status: 5.0.0 @@ -207,9 +215,11 @@ Reporting-MTA: dns; myhost.test.ex Action: failed Final-Recipient: rfc822;userz@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;usery@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;userx@myhost.test.ex Status: 5.0.0 diff --git a/test/mail/0211.CALLER b/test/mail/0211.CALLER index 89eadf58d..c863f58b5 100644 --- a/test/mail/0211.CALLER +++ b/test/mail/0211.CALLER @@ -96,6 +96,7 @@ Final-Recipient: rfc822;userx@domain1 Status: 5.0.0 Remote-MTA: dns; 127.0.0.1 Diagnostic-Code: smtp; 550 Go away + Action: failed Final-Recipient: rfc822;usery@domain2 Status: 5.0.0 diff --git a/test/mail/0224.CALLER b/test/mail/0224.CALLER index 056492573..b05090732 100644 --- a/test/mail/0224.CALLER +++ b/test/mail/0224.CALLER @@ -37,6 +37,7 @@ Reporting-MTA: dns; the.local.host.name Action: failed Final-Recipient: rfc822;hbounce@test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;bounce@test.ex Status: 5.0.0 @@ -106,9 +107,11 @@ Reporting-MTA: dns; the.local.host.name Action: delayed Final-Recipient: rfc822;/no/such/file Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;defer@test.ex Status: 4.0.0 + Action: delayed Final-Recipient: rfc822;hdefer@test.ex Status: 4.0.0 diff --git a/test/mail/0226.CALLER b/test/mail/0226.CALLER index 8d5a694f8..6fdc064f2 100644 --- a/test/mail/0226.CALLER +++ b/test/mail/0226.CALLER @@ -34,6 +34,7 @@ Reporting-MTA: dns; the.local.host.name Action: failed Final-Recipient: rfc822;/a/b/c Status: 5.0.0 + Action: failed Final-Recipient: rfc822;|/p/q/r Status: 5.0.0 diff --git a/test/mail/0237.CALLER b/test/mail/0237.CALLER index b47265d4a..2fa164320 100644 --- a/test/mail/0237.CALLER +++ b/test/mail/0237.CALLER @@ -32,6 +32,7 @@ Reporting-MTA: dns; the.local.host.name Action: failed Final-Recipient: rfc822;/a/b/c Status: 5.0.0 + Action: failed Final-Recipient: rfc822;|/p/q/r Status: 5.0.0 diff --git a/test/mail/0309.CALLER b/test/mail/0309.CALLER index c072d2a4f..b53186d4f 100644 --- a/test/mail/0309.CALLER +++ b/test/mail/0309.CALLER @@ -34,9 +34,11 @@ Reporting-MTA: dns; myhost.test.ex Action: failed Final-Recipient: rfc822;50@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;55@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;1k@myhost.test.ex Status: 5.0.0 diff --git a/test/mail/0374.CALLER b/test/mail/0374.CALLER index 859d93d3b..e92bef1f1 100644 --- a/test/mail/0374.CALLER +++ b/test/mail/0374.CALLER @@ -38,6 +38,7 @@ Reporting-MTA: dns; myhost.test.ex Action: failed Final-Recipient: rfc822;b1@myhost.test.ex Status: 5.0.0 + Action: failed Final-Recipient: rfc822;d3@myhost.test.ex Status: 5.0.0 -- 2.30.2