DSN: fix multiple-recipient notifications
authorJeremy Harris <jgh146exb@wizmail.org>
Sat, 7 Mar 2015 16:05:19 +0000 (16:05 +0000)
committerJeremy Harris <jgh146exb@wizmail.org>
Sat, 7 Mar 2015 22:18:27 +0000 (22:18 +0000)
A newline is needed between each Action group

src/src/deliver.c
test/mail/0037.CALLER
test/mail/0098.CALLER
test/mail/0194.CALLER
test/mail/0211.CALLER
test/mail/0224.CALLER
test/mail/0226.CALLER
test/mail/0237.CALLER
test/mail/0309.CALLER
test/mail/0374.CALLER

index ad871c575910ba8a55b273370c9dc75ec35c91e4..65b4824ab9a0079be0bbfddbbaccba5c7b3929c7 100644 (file)
@@ -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);
 
index f3770676af5fc792404e7b91edd0bc1e87e390ff..4ba7eef27de70b6d696fed31904faaf2b7a58997 100644 (file)
@@ -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
index ffb739e5efa7760e9624d56535e2eae4f4c3f7d6..cead0a57116d0ff95594843e34b0467b7f66baf0 100644 (file)
@@ -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
index 463575cd2ea35530623696e13c8008a2fce6e4a4..41420fb84e0e9be8c5f8a06d5d560425b00b52ea 100644 (file)
@@ -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
index 89eadf58d2601acb9c8839ecbeaf3d466b21da55..c863f58b59f70d57813d9375269b4bafb697b343 100644 (file)
@@ -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
index 056492573d67592f600b5bdf51678af49a70e27c..b050907324e5c21e3af4ca2b5eaa05e0f6dd2550 100644 (file)
@@ -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
index 8d5a694f84ce7dd1053a0c08ff52a375482f888d..6fdc064f2a8048c5007edce252c6855f3a999302 100644 (file)
@@ -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
index b47265d4a8c636ab3521961eb620e97da235dbde..2fa164320f26a7e1966d8ccbdc199d89db5fff44 100644 (file)
@@ -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
index c072d2a4fe1a88a4b65b0b532fe3894a3d958ca0..b53186d4fe12f5b5707cb9dba738b753125c308e 100644 (file)
@@ -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
index 859d93d3bc3c1bb3f7b8ea56d0abc10684995a2f..e92bef1f151f708ab7cb92e77c8e25aaf33cd091 100644 (file)
@@ -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